infobar 0.13.2 → 0.15.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: d40d5b452af90e9dc3a001fbed6b3a99592c9957f961ff5e80023bad450470fd
4
- data.tar.gz: e09df34cc5ec2d154ad72e9b93430086b33f11c8fce42990fcc205d3923244c8
3
+ metadata.gz: 78cbcd08f0a2d2ddd1094df459bf3ca54bf3daab8ce3414263f51df214292d16
4
+ data.tar.gz: 477e29d5f2e1fe56a422083c6efceb770eee9b570594c9ad6ba33f54104240ee
5
5
  SHA512:
6
- metadata.gz: 61dccf5182cc602737ca95da8f583adbea6cabc7b33e5ae7a0f205ca3eb7535f51e08139293be6d30b2289042017ee4dd38f5f027c95952e422f1724bb3efcea
7
- data.tar.gz: c7aca2ac7d23e230b56cdd464154187795ae83e53babdcadf762fe9560bfbe950ddaec4e4917bf728006269c5b6470ab4e47ab1d2209ada2e79ca1ff390cc6fb
6
+ metadata.gz: 6d3f41bbf6ae87c63fc4183d229f12ce505f58bcd72eb7f6ba568a521d23ef48561929c19ded01d4154c5b38c5e11d9c3cb4052b609893c61eb746839b5824dd
7
+ data.tar.gz: af5a5669ff6057a85a76f9ecf07be72cc384359de19ea4b034d398c0bd2175e49d79d8c9b95ebd364c3c0a0202721ae8a6e098159f677f07a7451f62fe20ee16
data/CHANGES.md CHANGED
@@ -1,5 +1,64 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-11-16 v0.15.0
4
+
5
+ ### Fixes
6
+
7
+ - `Display#newline` now resets `@position_saved` to `false`, preventing the
8
+ next `Display#update` from restoring to a stale bar-line position after a
9
+ newline commit.
10
+
11
+ ### Testing
12
+
13
+ - Updated spec expectations in `display_spec.rb` to include the trailing
14
+ `restore_position` escape sequence.
15
+ - Added singleton state isolation (`display.reset`) and the missing
16
+ `restore_position` expectation in `config_spec.rb`.
17
+
18
+ ## 2026-11-15 v0.14.0
19
+
20
+ ### Features
21
+
22
+ - Added `Infobar::Display#save_position!` to explicitly save the cursor
23
+ position and update the `@position_saved` flag.
24
+ - Exposed a writer for `Infobar::Display#position_saved` to allow forcing a
25
+ re-save of the cursor position on the next update.
26
+
27
+ ### Fixes
28
+
29
+ - Replaced carriage return (`\r`) with ANSI save (`\e[s`) and restore (`\e[u`)
30
+ position sequences in `Infobar::Display#update` and `Infobar::Display#clear`
31
+ to prevent bar drift when the user presses Enter mid-render.
32
+ - Updated the `SIGWINCH` handler in `Infobar#install_winch_trap` to reset
33
+ `position_saved` instead of calling `display.clear`, preventing stale cursor
34
+ restores when the saved row is out of bounds after a terminal resize.
35
+ - Modified `Infobar::Display#update` to restore the cursor position after
36
+ `layout_bar` to cancel delayed-wrap on the last visible row.
37
+ - Ensured `Infobar::InputOutput` methods (`print`, `printf`, `putc`, `puts`,
38
+ `gets`, `readline`, `readlines`) call `display.save_position!` after writing
39
+ to keep the bar aligned with the cursor.
40
+
41
+ ### Improvements
42
+
43
+ - Added `cscope.out` to the `skip_files` regex in `.utilsrc` to prevent code
44
+ search tools from indexing cscope database files.
45
+
46
+ ### Build & CI
47
+
48
+ - Added `cscope.out` to `.gitignore` and the `ignore` list in the `Rakefile`.
49
+
50
+ ### Testing
51
+
52
+ - Added a test in `spec/infobar/display_spec.rb` covering the save, clear,
53
+ write, and re-save lifecycle.
54
+ - Updated `spec/infobar/input_output_spec.rb` to expect `save_position!` calls
55
+ for `puts` and `gets`.
56
+ - Updated `spec/infobar/display_spec.rb` and `spec/infobar/config_spec.rb`
57
+ expectations to reflect the new ANSI position sequences.
58
+ - Switched `.busy` specs in `spec/infobar_spec.rb` from `and_call_original` to
59
+ plain stubs for hermetic output and added `finish`/`newline` expectations to
60
+ the `ArgumentError` test.
61
+
3
62
  ## 2026-11-13 v0.13.2
4
63
 
5
64
  ### Improvements
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ GemHadar do
13
13
  test_dir 'spec'
14
14
  ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', 'coverage', '.rvmrc',
15
15
  '.AppleDouble', 'tags', '.DS_Store', 'errors.lst', '.tool-versions',
16
- '.bundle', '.yardoc', 'doc'
16
+ '.bundle', '.yardoc', 'doc', 'cscope.out'
17
17
  package_ignore '.utilsrc', '.all_images.yml', 'VERSION', '.rspec',
18
18
  '.gitignore', 'TODO.md', 'doc'
19
19
 
data/infobar.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: infobar 0.13.2 ruby lib
2
+ # stub: infobar 0.15.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "infobar".freeze
6
- s.version = "0.13.2".freeze
6
+ s.version = "0.15.0".freeze
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
@@ -37,9 +37,15 @@ class Infobar::Display
37
37
  self.input = $stdin
38
38
  self.frequency = 0.05
39
39
  @show = true
40
- @style = self.class.default_style.dup
40
+ @style = self.class.default_style.dup
41
+ @position_saved = false
41
42
  end
42
43
 
44
+ # @!attribute [w] position_saved
45
+ # Forces the next +update+ to re-save the cursor
46
+ # position.
47
+ attr_writer :position_saved
48
+
43
49
  # Sets the update frequency threshold.
44
50
  #
45
51
  # @param duration [Numeric] minimum seconds between updates
@@ -134,10 +140,11 @@ class Infobar::Display
134
140
  def update(message: nil, counter: nil, force: false, **options)
135
141
  force and @frequency.reset
136
142
  @frequency.call do
137
- carriage_return
143
+ @position_saved ? (output << restore_position) : save_position!
138
144
  self.style = options
139
145
  message = infobar.convert_to_message(message)
140
146
  layout_bar(message, counter)
147
+ output << restore_position
141
148
  end
142
149
  end
143
150
 
@@ -183,6 +190,7 @@ class Infobar::Display
183
190
  # @param clear [Boolean] whether to blank the current line
184
191
  # @return [Infobar::Display] self
185
192
  def reset(clear: true)
193
+ @position_saved = false
186
194
  clear && self.clear
187
195
  self.style = self.class.default_style
188
196
  self
@@ -192,13 +200,29 @@ class Infobar::Display
192
200
  #
193
201
  # @return [Infobar::Display] self
194
202
  def clear
195
- carriage_return
196
- output << ' ' * columns
197
- carriage_return
203
+ if @position_saved
204
+ output << restore_position
205
+ output << ' ' * columns
206
+ output << restore_position
207
+ else
208
+ carriage_return
209
+ output << ' ' * columns
210
+ carriage_return
211
+ end
212
+ @position_saved = false
198
213
  @frequency.reset
199
214
  self
200
215
  end
201
216
 
217
+ # Saves the current cursor position for subsequent restores.
218
+ #
219
+ # @return [Infobar::Display] self
220
+ def save_position!
221
+ output << save_position
222
+ @position_saved = true
223
+ self
224
+ end
225
+
202
226
  # Emits a carriage return to the output.
203
227
  #
204
228
  # @return [Infobar::Display] self
@@ -212,6 +236,7 @@ class Infobar::Display
212
236
  # @return [Infobar::Display] self
213
237
  def newline
214
238
  output << $/
239
+ @position_saved = false
215
240
  self
216
241
  end
217
242
 
@@ -24,6 +24,7 @@ module Infobar::InputOutput
24
24
  display.clear
25
25
  if display.output.respond_to?(method)
26
26
  display.output.public_send(method, *a, &b)
27
+ display.save_position!
27
28
  end
28
29
  end
29
30
  end
@@ -33,6 +34,7 @@ module Infobar::InputOutput
33
34
  display.clear
34
35
  if display.input.respond_to?(method)
35
36
  display.input.public_send(method, *a, &b)
37
+ display.save_position!
36
38
  end
37
39
  end
38
40
  end
@@ -5,7 +5,7 @@
5
5
  # by hand; it is rewritten on every `rake version` invocation.
6
6
  class Infobar
7
7
  # The current version of the Infobar gem as a String.
8
- VERSION = '0.13.2'
8
+ VERSION = '0.15.0'
9
9
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
10
10
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
11
11
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
data/lib/infobar.rb CHANGED
@@ -151,6 +151,7 @@ class Infobar
151
151
  self.input = input
152
152
  self.output = output
153
153
  update and update(message: @message, force: true)
154
+ install_winch_trap
154
155
  self
155
156
  end
156
157
 
@@ -255,6 +256,7 @@ class Infobar
255
256
  counter.finish
256
257
  @message = convert_to_message(message)
257
258
  display.update(message: @message, force: true, counter: counter)
259
+ restore_winch_trap
258
260
  self
259
261
  end
260
262
 
@@ -286,6 +288,28 @@ class Infobar
286
288
  @message
287
289
  end
288
290
  end
291
+
292
+ private
293
+
294
+ # Installs a `SIGWINCH` handler that clears the display so the
295
+ # bar re-saves its position after a terminal resize.
296
+ #
297
+ # @api private
298
+ def install_winch_trap
299
+ @winch_handler ||= Signal.trap('WINCH', 'DEFAULT')
300
+ Signal.trap('WINCH') do
301
+ display.position_saved = false if display.show?
302
+ end
303
+ end
304
+
305
+ # Restores the original `SIGWINCH` handler saved by
306
+ # #install_winch_trap.
307
+ #
308
+ # @api private
309
+ def restore_winch_trap
310
+ Signal.trap('WINCH', @winch_handler) if @winch_handler
311
+ @winch_handler = nil
312
+ end
289
313
  end
290
314
 
291
315
  # Creates and configures a new infobar (top-level convenience method).
@@ -19,11 +19,13 @@ describe 'Infobar config' do
19
19
 
20
20
  it 'configures default infobar' do
21
21
  Infobar(total: 23)
22
- expect(infobar.display.output).to receive(:<<).with(?\r)
22
+ infobar.display.reset
23
+ expect(infobar.display.output).to receive(:<<).with("\e[s")
23
24
  expect(infobar.display.output).to receive(:<<).with(
24
25
  "\e[38;5;22m\e[48;5;40m\e[0m\e[0m"
25
26
  )
26
27
  expect(infobar.display.output).to receive(:<<).with(%r(Progress 0/23.*⣽))
28
+ expect(infobar.display.output).to receive(:<<).with("\e[u")
27
29
  infobar.update
28
30
  expect(infobar).to be_show
29
31
  end
@@ -21,13 +21,29 @@ describe Infobar::Display do
21
21
  it 'can be updated' do
22
22
  display.update message: 'test', counter: counter
23
23
  expect(output.tap(&:rewind).read).to eq\
24
- "\r\e[38;5;22m\e[48;5;40m░░░░░░░░░░░░░░░░░░te\e[0m\e[0m\e[38;5;40m\e[48;5;22mst \e[0m\e[0m"
24
+ "\e[s\e[38;5;22m\e[48;5;40m░░░░░░░░░░░░░░░░░░te\e[0m\e[0m\e[38;5;40m\e[48;5;22mst \e[0m\e[0m\e[u"
25
25
  end
26
26
 
27
- it 'update returns carriage first' do
28
- expect(display).to receive(:carriage_return).and_call_original
27
+ it 'update saves position first' do
29
28
  display.update message: 'test', counter: counter
30
- expect(output.tap(&:rewind).read).to start_with ?\r
29
+ expect(output.tap(&:rewind).read).to start_with "\e[s"
30
+ display.update message: 'test', counter: counter, force: true
31
+ output.rewind
32
+ expect(output.read).to include "\e[u"
33
+ end
34
+
35
+ it 're-saves position after clear and write' do
36
+ display.update message: 'test', counter: counter
37
+ output.rewind
38
+
39
+ display.clear
40
+ output << "hello\n"
41
+ display.save_position!
42
+
43
+ display.update message: 'test', counter: counter, force: true
44
+ content = output.tap(&:rewind).read
45
+ expect(content).to include "\e[u"
46
+ expect(content).not_to include "\e[s" + "\e[s"
31
47
  end
32
48
 
33
49
  it 'reset clears and sets to default style' do
@@ -53,7 +69,7 @@ describe Infobar::Display do
53
69
  display.style = test_style
54
70
  display.update message: 'test', counter: counter
55
71
  expect(output.tap(&:rewind).read).to eq\
56
- "\r\e[38;5;1m\e[48;5;9mXXXXXXXXXXXXXXXXXXte\e[0m\e[0m\e[38;5;0m\e[48;5;8mstOOOOOOOOOOOOOOOOOO\e[0m\e[0m"
72
+ "\e[s\e[38;5;1m\e[48;5;9mXXXXXXXXXXXXXXXXXXte\e[0m\e[0m\e[38;5;0m\e[48;5;8mstOOOOOOOOOOOOOOOOOO\e[0m\e[0m\e[u"
57
73
  expect(display.style).to eq(test_style)
58
74
  end
59
75
 
@@ -79,7 +95,7 @@ describe Infobar::Display do
79
95
  ).at_least(:once)
80
96
  display.update message: 'test', counter: counter
81
97
  expect(output.tap(&:rewind).read).to eq\
82
- "\r\e[38;5;1m\e[48;5;9mXXXXXXXXXXXXXXXXX\e[0m\e[0m\e[38;5;0m\e[48;5;10m*test******\e[0m\e[0m\e[38;5;40m\e[48;5;22m \e[0m\e[0m"
98
+ "\e[s\e[38;5;1m\e[48;5;9mXXXXXXXXXXXXXXXXX\e[0m\e[0m\e[38;5;0m\e[48;5;10m*test******\e[0m\e[0m\e[38;5;40m\e[48;5;22m \e[0m\e[0m\e[u"
83
99
  end
84
100
 
85
101
  it 'can output newline' do
@@ -21,12 +21,14 @@ describe Infobar::InputOutput do
21
21
  it 'can puts after clearing' do
22
22
  expect(infobar.display).to receive(:clear)
23
23
  expect(infobar.display.output).to receive(:puts)
24
+ expect(infobar.display).to receive(:save_position!)
24
25
  infobar.puts 'hello'
25
26
  end
26
27
 
27
28
  it 'can gets after clearing' do
28
29
  expect(infobar.display).to receive(:clear)
29
30
  expect(infobar.display.input).to receive(:gets)
31
+ expect(infobar.display).to receive(:save_position!)
30
32
  infobar.gets
31
33
  end
32
34
 
data/spec/infobar_spec.rb CHANGED
@@ -18,13 +18,15 @@ describe Infobar do
18
18
 
19
19
  describe '.busy' do
20
20
  it 'can be used to signal being busy with a block' do
21
- expect(infobar.display).to receive(:update).at_least(1).and_call_original
22
- expect(infobar).to receive(:finish).at_least(1).and_call_original
23
- expect(infobar).to receive(:newline).at_least(1).and_call_original
21
+ expect(infobar.display).to receive(:update).at_least(1)
22
+ expect(infobar).to receive(:finish).at_least(1)
23
+ expect(infobar).to receive(:newline).at_least(1)
24
24
  Infobar.busy { sleep 0.2 }
25
25
  end
26
26
 
27
27
  it 'needs a block for busy display' do
28
+ expect(infobar).to receive(:newline).at_least(1)
29
+ expect(infobar).to receive(:finish).at_least(1)
28
30
  expect { Infobar.busy }.to raise_error ArgumentError
29
31
  end
30
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infobar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.2
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank