infobar 0.13.2 → 0.14.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 +4 -4
- data/CHANGES.md +44 -0
- data/Rakefile +1 -1
- data/infobar.gemspec +2 -2
- data/lib/infobar/display.rb +29 -5
- data/lib/infobar/input_output.rb +2 -0
- data/lib/infobar/version.rb +1 -1
- data/lib/infobar.rb +24 -0
- data/spec/infobar/config_spec.rb +1 -1
- data/spec/infobar/display_spec.rb +22 -6
- data/spec/infobar/input_output_spec.rb +2 -0
- data/spec/infobar_spec.rb +5 -3
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: beec20adb697be698aa12ed3f834604867867e6fe75c8dcc4ad078ec74846f2e
|
|
4
|
+
data.tar.gz: 06a4590b0743fd05b408dee31f336c137f8386b3f6bd0d68996749f449ad6ff7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1a162cbf417cda56c28fa60aecc64868142bf538045b7383192ec8cc78c2eb98f766ec8da3a9d216eca8da82e81dd2fe8d5a3efd054b5947ddc6f19f32268797
|
|
7
|
+
data.tar.gz: 73babe25cdd25aa3c84ba53441a8948a2da82b2c1abc209d2644d338eb41c90197a0b1916822aa7e18afbf41e24844d137055a3176e67088d8cff89eacab79b6
|
data/CHANGES.md
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-11-15 v0.14.0
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- Added `Infobar::Display#save_position!` to explicitly save the cursor
|
|
8
|
+
position and update the `@position_saved` flag.
|
|
9
|
+
- Exposed a writer for `Infobar::Display#position_saved` to allow forcing a
|
|
10
|
+
re-save of the cursor position on the next update.
|
|
11
|
+
|
|
12
|
+
### Fixes
|
|
13
|
+
|
|
14
|
+
- Replaced carriage return (`\r`) with ANSI save (`\e[s`) and restore (`\e[u`)
|
|
15
|
+
position sequences in `Infobar::Display#update` and `Infobar::Display#clear`
|
|
16
|
+
to prevent bar drift when the user presses Enter mid-render.
|
|
17
|
+
- Updated the `SIGWINCH` handler in `Infobar#install_winch_trap` to reset
|
|
18
|
+
`position_saved` instead of calling `display.clear`, preventing stale cursor
|
|
19
|
+
restores when the saved row is out of bounds after a terminal resize.
|
|
20
|
+
- Modified `Infobar::Display#update` to restore the cursor position after
|
|
21
|
+
`layout_bar` to cancel delayed-wrap on the last visible row.
|
|
22
|
+
- Ensured `Infobar::InputOutput` methods (`print`, `printf`, `putc`, `puts`,
|
|
23
|
+
`gets`, `readline`, `readlines`) call `display.save_position!` after writing
|
|
24
|
+
to keep the bar aligned with the cursor.
|
|
25
|
+
|
|
26
|
+
### Improvements
|
|
27
|
+
|
|
28
|
+
- Added `cscope.out` to the `skip_files` regex in `.utilsrc` to prevent code
|
|
29
|
+
search tools from indexing cscope database files.
|
|
30
|
+
|
|
31
|
+
### Build & CI
|
|
32
|
+
|
|
33
|
+
- Added `cscope.out` to `.gitignore` and the `ignore` list in the `Rakefile`.
|
|
34
|
+
|
|
35
|
+
### Testing
|
|
36
|
+
|
|
37
|
+
- Added a test in `spec/infobar/display_spec.rb` covering the save, clear,
|
|
38
|
+
write, and re-save lifecycle.
|
|
39
|
+
- Updated `spec/infobar/input_output_spec.rb` to expect `save_position!` calls
|
|
40
|
+
for `puts` and `gets`.
|
|
41
|
+
- Updated `spec/infobar/display_spec.rb` and `spec/infobar/config_spec.rb`
|
|
42
|
+
expectations to reflect the new ANSI position sequences.
|
|
43
|
+
- Switched `.busy` specs in `spec/infobar_spec.rb` from `and_call_original` to
|
|
44
|
+
plain stubs for hermetic output and added `finish`/`newline` expectations to
|
|
45
|
+
the `ArgumentError` test.
|
|
46
|
+
|
|
3
47
|
## 2026-11-13 v0.13.2
|
|
4
48
|
|
|
5
49
|
### 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.
|
|
2
|
+
# stub: infobar 0.14.0 ruby lib
|
|
3
3
|
|
|
4
4
|
Gem::Specification.new do |s|
|
|
5
5
|
s.name = "infobar".freeze
|
|
6
|
-
s.version = "0.
|
|
6
|
+
s.version = "0.14.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]
|
data/lib/infobar/display.rb
CHANGED
|
@@ -37,9 +37,15 @@ class Infobar::Display
|
|
|
37
37
|
self.input = $stdin
|
|
38
38
|
self.frequency = 0.05
|
|
39
39
|
@show = true
|
|
40
|
-
@style
|
|
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
|
-
|
|
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
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
data/lib/infobar/input_output.rb
CHANGED
|
@@ -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
|
data/lib/infobar/version.rb
CHANGED
|
@@ -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.
|
|
8
|
+
VERSION = '0.14.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).
|
data/spec/infobar/config_spec.rb
CHANGED
|
@@ -19,7 +19,7 @@ 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(
|
|
22
|
+
expect(infobar.display.output).to receive(:<<).with("\e[s")
|
|
23
23
|
expect(infobar.display.output).to receive(:<<).with(
|
|
24
24
|
"\e[38;5;22m\e[48;5;40m\e[0m\e[0m"
|
|
25
25
|
)
|
|
@@ -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
|
-
"\
|
|
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"
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
it 'update
|
|
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
|
|
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
|
-
"\
|
|
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"
|
|
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
|
-
"\
|
|
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"
|
|
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)
|
|
22
|
-
expect(infobar).to receive(:finish).at_least(1)
|
|
23
|
-
expect(infobar).to receive(:newline).at_least(1)
|
|
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
|