console 1.9.0 → 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79f9ed13eedb54202ce2111a451e6e7d744f97db971a6b619ba3decb5aa6c963
4
- data.tar.gz: 8c77221c0e50be91b7c1857fde7b596ec7e48eebd67a43287bd01aa3f95e70b4
3
+ metadata.gz: ebadd29a9248f8a155c3bc22550a6433e53af806acae2112fe96a3924c92fb8d
4
+ data.tar.gz: fd23c8cb36efc9a36f688c2caa0383feb85fe7fdab2992d269239650faa8f92a
5
5
  SHA512:
6
- metadata.gz: 021e0bd5c98d7019af39186b6fa06e49aed619cb5228051a85725bd43f3f05d8015b6d9bc84baf3a49f51a9b13ac62ed65cb20051f9561939d0fb72c791b8475
7
- data.tar.gz: '029abdaded5a4d383e7e4b666c99e2b06c0aaabed87c1da9740c6925ca5e9308eb41b52d61835e0b6a3223efff9b25a98aac555fe43c2ca441ef48f5f27e6f3f'
6
+ metadata.gz: 02b4cecf9844a7d6bb733da31953805d89590b5a43b68e7d6cc379bde7e2660e3064438385d40b147cde4c89b50b7f7f9f4cf3f58aa69e1498e0085f56015a86
7
+ data.tar.gz: 3bba83e7c801994f6fdb6a1a248fbac746a8a9987f786d30df73c91ba7d79032226d4f78d3eed9fb1a5d0eb9c339f89864c15fcceb823a2f877e81fe90c977f7
@@ -21,15 +21,20 @@
21
21
  require_relative 'filter'
22
22
 
23
23
  module Console
24
+ # A general sink which captures all events into a buffer.
24
25
  class Capture
25
26
  def initialize
26
- @events = []
27
+ @buffer = []
27
28
  end
28
29
 
29
- attr :events
30
+ attr :buffer
30
31
 
31
32
  def last
32
- @events.last
33
+ @buffer.last
34
+ end
35
+
36
+ def clear
37
+ @buffer.clear
33
38
  end
34
39
 
35
40
  def verbose!(value = true)
@@ -37,7 +42,7 @@ module Console
37
42
 
38
43
  def call(subject = nil, *arguments, severity: UNKNOWN, **options, &block)
39
44
  message = {
40
- time: Time.now.iso8601,
45
+ time: ::Time.now.iso8601,
41
46
  severity: severity,
42
47
  **options,
43
48
  }
@@ -60,7 +65,7 @@ module Console
60
65
  end
61
66
  end
62
67
 
63
- @events << message
68
+ @buffer << message
64
69
  end
65
70
  end
66
71
  end
@@ -20,4 +20,5 @@
20
20
 
21
21
  require_relative 'event/spawn'
22
22
  require_relative 'event/failure'
23
+ require_relative 'event/metric'
23
24
  require_relative 'event/progress'
@@ -49,6 +49,10 @@ module Console
49
49
  terminal[:exception_backtrace] ||= terminal.style(:red)
50
50
  end
51
51
 
52
+ def to_h
53
+ {exception: @exception, root: @root}
54
+ end
55
+
52
56
  def format(output, terminal, verbose)
53
57
  format_exception(@exception, nil, output, terminal, verbose)
54
58
  end
@@ -24,6 +24,13 @@ module Console
24
24
  def self.register(terminal)
25
25
  end
26
26
 
27
+ def to_h
28
+ end
29
+
30
+ def as_json
31
+ to_h
32
+ end
33
+
27
34
  def format(buffer, terminal)
28
35
  end
29
36
  end
@@ -0,0 +1,49 @@
1
+ # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require_relative 'generic'
22
+
23
+ module Console
24
+ module Event
25
+ class Metric < Generic
26
+ def self.[](**parameters)
27
+ parameters.map(&self.method(:new))
28
+ end
29
+
30
+ def initialize(name, value, **tags)
31
+ @name = name
32
+ @value = value
33
+ @tags = tags
34
+ end
35
+
36
+ attr :name
37
+ attr :value
38
+ attr :tags
39
+
40
+ def to_h
41
+ {name: @name, value: @value, tags: @tags}
42
+ end
43
+
44
+ def format(output, terminal, verbose)
45
+ output.puts "#{@name}=#{@value} #{@tags.inspect}"
46
+ end
47
+ end
48
+ end
49
+ end
@@ -63,7 +63,7 @@ module Console
63
63
  terminal[:progress_bar] ||= terminal.style(:blue, :white)
64
64
  end
65
65
 
66
- def as_json
66
+ def to_h
67
67
  {current: @current, total: @total}
68
68
  end
69
69
 
@@ -24,6 +24,7 @@ module Console
24
24
  module Event
25
25
  class Spawn < Generic
26
26
  def self.for(*arguments, **options)
27
+ # Extract out the command environment:
27
28
  if arguments.first.is_a?(Hash)
28
29
  self.new(*arguments, **options)
29
30
  else
@@ -51,6 +52,10 @@ module Console
51
52
  terminal[:shell_command] ||= terminal.style(:blue, nil, :bold)
52
53
  end
53
54
 
55
+ def to_h
56
+ {environment: @environment, arguments: @arguments, options: @options}
57
+ end
58
+
54
59
  def format(output, terminal, verbose)
55
60
  arguments = @arguments.flatten.collect(&:to_s)
56
61
 
@@ -46,7 +46,7 @@ module Console
46
46
  end
47
47
 
48
48
  define_method("#{name}?") do
49
- @level >= level
49
+ @level <= level
50
50
  end
51
51
  end
52
52
  end
@@ -19,7 +19,7 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  require_relative 'filter'
22
- require_relative 'measure'
22
+ require_relative 'progress'
23
23
 
24
24
  module Console
25
25
  class Logger < Filter[debug: 0, info: 1, warn: 2, error: 3, fatal: 4]
@@ -29,8 +29,15 @@ module Console
29
29
  super(output, **options)
30
30
  end
31
31
 
32
- def measure(subject, total)
33
- Measure.new(self, subject, total)
32
+ def progress(subject, total, **options)
33
+ Progress.new(self, subject, total, **options)
34
+ end
35
+
36
+ # @deprecated Please use {progress}.
37
+ alias measure progress
38
+
39
+ def failure(subject, exception, *arguments, &block)
40
+ fatal(subject, *arguments, Event::Failure.new(exception), &block)
34
41
  end
35
42
  end
36
43
  end
@@ -18,26 +18,33 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
+ require_relative 'event/progress'
22
+
21
23
  module Console
22
- class Measure
23
- def initialize(output, subject, total = 0)
24
+ class Progress
25
+ def self.now
26
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
27
+ end
28
+
29
+ def initialize(output, subject, total = 0, minimum_output_duration: 1.0)
24
30
  @output = output
25
31
  @subject = subject
26
32
 
27
- @start_time = Time.now
33
+ @start_time = Progress.now
34
+
35
+ @last_output_time = nil
36
+ @minimum_output_duration = 0.1
28
37
 
29
38
  @current = 0
30
39
  @total = total
31
40
  end
32
41
 
33
42
  attr :subject
34
-
35
43
  attr :current
36
-
37
44
  attr :total
38
45
 
39
46
  def duration
40
- Time.now - @start_time
47
+ Progress.now - @start_time
41
48
  end
42
49
 
43
50
  def progress
@@ -63,7 +70,10 @@ module Console
63
70
  def increment(amount = 1)
64
71
  @current += amount
65
72
 
66
- @output.info(@subject, self) {Event::Progress.new(@current, @total)}
73
+ if output?
74
+ @output.info(@subject, self) {Event::Progress.new(@current, @total)}
75
+ @last_output_time = Progress.now
76
+ end
67
77
 
68
78
  return self
69
79
  end
@@ -72,6 +82,7 @@ module Console
72
82
  @total = total
73
83
 
74
84
  @output.info(@subject, self) {Event::Progress.new(@current, @total)}
85
+ @last_output_time = Progress.now
75
86
 
76
87
  return self
77
88
  end
@@ -90,6 +101,20 @@ module Console
90
101
 
91
102
  private
92
103
 
104
+ def duration_since_last_output
105
+ if @last_output_time
106
+ Progress.now - @last_output_time
107
+ end
108
+ end
109
+
110
+ def output?
111
+ if duration = duration_since_last_output
112
+ return duration > @minimum_output_duration
113
+ else
114
+ return true
115
+ end
116
+ end
117
+
93
118
  def formatted_duration(duration)
94
119
  if duration < 60.0
95
120
  return "#{duration.round(2)}s"
@@ -24,6 +24,8 @@ require_relative '../event'
24
24
  require_relative 'text'
25
25
  require_relative 'xterm'
26
26
 
27
+ require 'json'
28
+
27
29
  module Console
28
30
  module Terminal
29
31
  # This, and all related methods, is considered private.
@@ -77,7 +79,9 @@ module Console
77
79
  end
78
80
 
79
81
  attr :io
82
+
80
83
  attr_accessor :verbose
84
+
81
85
  attr :start
82
86
  attr :terminal
83
87
 
@@ -94,7 +98,7 @@ module Console
94
98
 
95
99
  UNKNOWN = 'unknown'
96
100
 
97
- def call(subject = nil, *arguments, name: nil, severity: UNKNOWN, &block)
101
+ def call(subject = nil, *arguments, name: nil, severity: UNKNOWN, **options, &block)
98
102
  prefix = build_prefix(name || severity.to_s)
99
103
  indent = " " * prefix.size
100
104
 
@@ -104,6 +108,10 @@ module Console
104
108
  format_subject(severity, prefix, subject, buffer)
105
109
  end
106
110
 
111
+ if options&.any?
112
+ format_options(options, buffer)
113
+ end
114
+
107
115
  arguments.each do |argument|
108
116
  format_argument(argument, buffer)
109
117
  end
@@ -121,6 +129,10 @@ module Console
121
129
 
122
130
  protected
123
131
 
132
+ def format_options(options, output)
133
+ format_value(options.to_json, output)
134
+ end
135
+
124
136
  def format_argument(argument, output)
125
137
  case argument
126
138
  when Exception
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Console
22
- VERSION = "1.9.0"
22
+ VERSION = "1.9.1"
23
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: console
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-27 00:00:00.000000000 Z
11
+ date: 2020-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bake
@@ -93,11 +93,12 @@ files:
93
93
  - lib/console/event.rb
94
94
  - lib/console/event/failure.rb
95
95
  - lib/console/event/generic.rb
96
+ - lib/console/event/metric.rb
96
97
  - lib/console/event/progress.rb
97
98
  - lib/console/event/spawn.rb
98
99
  - lib/console/filter.rb
99
100
  - lib/console/logger.rb
100
- - lib/console/measure.rb
101
+ - lib/console/progress.rb
101
102
  - lib/console/resolver.rb
102
103
  - lib/console/serialized/logger.rb
103
104
  - lib/console/split.rb