console 1.37.0 → 1.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 885a16aa891f4867dc3ef9811178e121750a5f8395e88beb9f9a96b02d009ba9
4
- data.tar.gz: 919cce15d67d7922a444f4d764864de5d1d4bb1ef04b59e723062040cbb7f5d6
3
+ metadata.gz: 00b1eca4193288f97e7b4e1a5dd1cd5e074447bf26f92e994eab48a3daf2728a
4
+ data.tar.gz: efa0889c58183210e91d37efbfc0ee5952020fd43f0524717a1cce09cc626139
5
5
  SHA512:
6
- metadata.gz: 922158e79dccdfa2db29f3dd46d1763542449a6ec8c96cfde6b28459e6b6f17e380108e3260b7ff74142eca57158e4191321ebe569a267010629ba408606a78e
7
- data.tar.gz: 82feebd861439923efa6fd4b772a0767f83cd150925f876a620ac745a3e1da45ade27dd850f40751c3118abbffd6102f04dfccfe76418e7b194a36204da5df80
6
+ metadata.gz: 8c1bd30af3388dccfba16b043f54643a6daf23fbe859117897608e93cc6a451d89367d7518ca42710c2c6daa52a9b981215f4cc999b4c7a0fdfc15844861f2c2
7
+ data.tar.gz: 57e0f70484777fbfa5c8a03d8604ae4f915dad90f5154bd47553c303ab28d700f4671eb9293be4ca11a827243887a91f334a20058998ce636e5ab7fd75030987
checksums.yaml.gz.sig CHANGED
Binary file
@@ -60,7 +60,7 @@ module Console
60
60
  def progress(subject, total, **options)
61
61
  options[:severity] ||= :info
62
62
 
63
- Progress.new(subject, total, **options)
63
+ Progress.new(subject, total, logger: self, **options)
64
64
  end
65
65
  end
66
66
  end
@@ -18,10 +18,12 @@ module Console
18
18
  #
19
19
  # @parameter subject [Object] The subject of the progress indicator.
20
20
  # @parameter total [Integer] The total number of steps.
21
+ # @parameter logger [Console::Logger] The logger to use for output.
21
22
  # @parameter minimum_output_duration [Numeric] The minimum duration between outputs.
22
23
  # @parameter options [Hash] Additional options to customize the output.
23
- def initialize(subject, total = 0, minimum_output_duration: 0.1, **options)
24
+ def initialize(subject, total = 0, logger: Console, minimum_output_duration: 0.1, **options)
24
25
  @subject = subject
26
+ @logger = logger
25
27
  @options = options
26
28
 
27
29
  @start_time = Clock.now
@@ -55,6 +57,8 @@ module Console
55
57
 
56
58
  # @returns [Rational] The ratio of steps completed to total steps.
57
59
  def ratio
60
+ return Rational(0, 1) if @total.zero?
61
+
58
62
  Rational(@current.to_f, @total.to_f)
59
63
  end
60
64
 
@@ -99,7 +103,7 @@ module Console
99
103
  @current += amount
100
104
 
101
105
  if output?
102
- Console.call(@subject, self.to_s, event: self.to_hash, **@options)
106
+ @logger.call(@subject, self.to_s, event: self.to_hash, **@options)
103
107
  @last_output_time = Clock.now
104
108
  end
105
109
 
@@ -113,7 +117,7 @@ module Console
113
117
  def resize(total)
114
118
  @total = total
115
119
 
116
- Console.call(@subject, self.to_s, event: self.to_hash, **@options)
120
+ @logger.call(@subject, self.to_s, event: self.to_hash, **@options)
117
121
  @last_output_time = Clock.now
118
122
 
119
123
  return self
@@ -125,7 +129,7 @@ module Console
125
129
  # @parameter **options [Hash] Additional options to log.
126
130
  # @parameter &block [Proc] An optional block used to generate the log message.
127
131
  def mark(*arguments, **options, &block)
128
- Console.call(@subject, *arguments, **options, **@options, &block)
132
+ @logger.call(@subject, *arguments, **options, **@options, &block)
129
133
  end
130
134
 
131
135
  # @returns [String] A human-readable representation of the progress indicator.
@@ -41,12 +41,10 @@ module Console
41
41
  def format(event, stream, verbose: false, width: 80)
42
42
  current = event[:current].to_f
43
43
  total = event[:total].to_f
44
- value = current / total
44
+ value = total.zero? ? 0.0 : current / total
45
45
 
46
- # Clamp value to 1.0 to avoid rendering issues:
47
- if value > 1.0
48
- value = 1.0
49
- end
46
+ # Clamp value to avoid rendering issues:
47
+ value = value.clamp(0.0, 1.0)
50
48
 
51
49
  stream.puts "#{@terminal[:progress_bar]}#{self.bar(value, width-10)}#{@terminal.reset} #{sprintf('%6.2f', value * 100)}%"
52
50
  end
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2019-2026, by Samuel Williams.
5
5
 
6
6
  module Console
7
- VERSION = "1.37.0"
7
+ VERSION = "1.38.0"
8
8
  end
data/readme.md CHANGED
@@ -34,6 +34,10 @@ Please see the [project documentation](https://socketry.github.io/console/) for
34
34
 
35
35
  Please see the [project releases](https://socketry.github.io/console/releases/index) for all releases.
36
36
 
37
+ ### v1.38.0
38
+
39
+ - Fix `Console::Progress` to emit through the logger that created it and safely handle zero totals.
40
+
37
41
  ### v1.37.0
38
42
 
39
43
  - Show compound units in elapsed time display.
@@ -76,10 +80,6 @@ Please see the [project releases](https://socketry.github.io/console/releases/in
76
80
 
77
81
  - Serialized output now uses `IO#write` with a single string to reduce the chance of interleaved output.
78
82
 
79
- ### v1.29.2
80
-
81
- - Always return `nil` from `Console::Filter` logging methods.
82
-
83
83
  ## Contributing
84
84
 
85
85
  We welcome contributions to this project.
data/releases.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Releases
2
2
 
3
+ ## v1.38.0
4
+
5
+ - Fix `Console::Progress` to emit through the logger that created it and safely handle zero totals.
6
+
3
7
  ## v1.37.0
4
8
 
5
9
  - Show compound units in elapsed time display.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: console
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.37.0
4
+ version: 1.38.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
metadata.gz.sig CHANGED
Binary file