infobar 0.15.0 → 0.16.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 +27 -0
- data/infobar.gemspec +2 -2
- data/lib/infobar/display.rb +19 -6
- data/lib/infobar/version.rb +1 -1
- data/spec/infobar/config_spec.rb +2 -1
- data/spec/infobar/display_spec.rb +5 -4
- 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: 0035c3af284ee36b175e1454f0245b21dbc3a1124afcf2aa89f7ffe8a0a1f13b
|
|
4
|
+
data.tar.gz: 29e8ec9699dfb2b475593b107be5063348bbd05ef59027fade6c4ab86d1c034b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 238f95edc457b87ff2cfbba65e58246a2db374cac3ccf444ce3e38a9a529d37a2c56cb3b73827be37ab181ae69700baea2ba8a634452dc2165281c65861dab9f
|
|
7
|
+
data.tar.gz: 2ed0b0d7516d650614555c5dd9c2cc1e26fe10ba39fe284ee4519e5cfec3f8d815f9dc3fb1fc1926ac523241ae768701108352a5eb93c8627a0c58cfcfe13ae0
|
data/CHANGES.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-11-17 v0.16.0
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- Added intelligent bar abandonment detection using `Reline::IOGate.cursor_pos`
|
|
8
|
+
to track the bar's home row.
|
|
9
|
+
- Implemented logic to detect when the cursor has moved away from the saved bar
|
|
10
|
+
position, preventing visual artifacts when the bar is cleared or updated
|
|
11
|
+
after terminal output.
|
|
12
|
+
|
|
13
|
+
### Improvements
|
|
14
|
+
|
|
15
|
+
- Modified `save_position!` to emit a carriage return (`\r`) before saving the
|
|
16
|
+
cursor position, ensuring the bar always anchors at column 1.
|
|
17
|
+
- Updated `clear` to check if the current cursor row matches the saved
|
|
18
|
+
`@home_row`; if they differ, it falls back to carriage-return-based clearing
|
|
19
|
+
instead of restoring the saved position.
|
|
20
|
+
- Added `cursor_row` method to query the current cursor row via `Reline`.
|
|
21
|
+
- Reset `@home_row` to `nil` in `reset`, `clear`, and `newline` methods to
|
|
22
|
+
maintain state consistency.
|
|
23
|
+
|
|
24
|
+
### Testing
|
|
25
|
+
|
|
26
|
+
- Updated `spec/infobar/config_spec.rb` and `spec/infobar/display_spec.rb` to
|
|
27
|
+
mock `cursor_row` and verify the new carriage return behavior in output
|
|
28
|
+
sequences.
|
|
29
|
+
|
|
3
30
|
## 2026-11-16 v0.15.0
|
|
4
31
|
|
|
5
32
|
### Fixes
|
data/infobar.gemspec
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
-
# stub: infobar 0.
|
|
2
|
+
# stub: infobar 0.16.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.16.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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require 'term/ansicolor'
|
|
2
2
|
require 'stringio'
|
|
3
3
|
require 'infobar/frequency'
|
|
4
|
+
require 'reline'
|
|
4
5
|
|
|
5
6
|
# Terminal renderer for the progress bar.
|
|
6
7
|
#
|
|
@@ -36,9 +37,10 @@ class Infobar::Display
|
|
|
36
37
|
self.output = $stdout
|
|
37
38
|
self.input = $stdin
|
|
38
39
|
self.frequency = 0.05
|
|
39
|
-
@show
|
|
40
|
-
@style
|
|
41
|
-
@position_saved
|
|
40
|
+
@show = true
|
|
41
|
+
@style = self.class.default_style.dup
|
|
42
|
+
@position_saved = false
|
|
43
|
+
@home_row = nil
|
|
42
44
|
end
|
|
43
45
|
|
|
44
46
|
# @!attribute [w] position_saved
|
|
@@ -142,7 +144,7 @@ class Infobar::Display
|
|
|
142
144
|
@frequency.call do
|
|
143
145
|
@position_saved ? (output << restore_position) : save_position!
|
|
144
146
|
self.style = options
|
|
145
|
-
message
|
|
147
|
+
message = infobar.convert_to_message(message)
|
|
146
148
|
layout_bar(message, counter)
|
|
147
149
|
output << restore_position
|
|
148
150
|
end
|
|
@@ -191,6 +193,7 @@ class Infobar::Display
|
|
|
191
193
|
# @return [Infobar::Display] self
|
|
192
194
|
def reset(clear: true)
|
|
193
195
|
@position_saved = false
|
|
196
|
+
@home_row = nil
|
|
194
197
|
clear && self.clear
|
|
195
198
|
self.style = self.class.default_style
|
|
196
199
|
self
|
|
@@ -200,7 +203,7 @@ class Infobar::Display
|
|
|
200
203
|
#
|
|
201
204
|
# @return [Infobar::Display] self
|
|
202
205
|
def clear
|
|
203
|
-
if @position_saved
|
|
206
|
+
if @position_saved && @home_row && cursor_row == @home_row
|
|
204
207
|
output << restore_position
|
|
205
208
|
output << ' ' * columns
|
|
206
209
|
output << restore_position
|
|
@@ -210,6 +213,7 @@ class Infobar::Display
|
|
|
210
213
|
carriage_return
|
|
211
214
|
end
|
|
212
215
|
@position_saved = false
|
|
216
|
+
@home_row = nil
|
|
213
217
|
@frequency.reset
|
|
214
218
|
self
|
|
215
219
|
end
|
|
@@ -218,8 +222,9 @@ class Infobar::Display
|
|
|
218
222
|
#
|
|
219
223
|
# @return [Infobar::Display] self
|
|
220
224
|
def save_position!
|
|
221
|
-
output << save_position
|
|
225
|
+
output << ?\r + save_position
|
|
222
226
|
@position_saved = true
|
|
227
|
+
@home_row = cursor_row
|
|
223
228
|
self
|
|
224
229
|
end
|
|
225
230
|
|
|
@@ -237,6 +242,7 @@ class Infobar::Display
|
|
|
237
242
|
def newline
|
|
238
243
|
output << $/
|
|
239
244
|
@position_saved = false
|
|
245
|
+
@home_row = nil
|
|
240
246
|
self
|
|
241
247
|
end
|
|
242
248
|
|
|
@@ -256,4 +262,11 @@ class Infobar::Display
|
|
|
256
262
|
def columns
|
|
257
263
|
Tins::Terminal.columns
|
|
258
264
|
end
|
|
265
|
+
|
|
266
|
+
# Queries the current cursor row via Reline.
|
|
267
|
+
#
|
|
268
|
+
# @return [Integer] the current row position
|
|
269
|
+
def cursor_row
|
|
270
|
+
Reline::IOGate.cursor_pos.y
|
|
271
|
+
end
|
|
259
272
|
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.16.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/spec/infobar/config_spec.rb
CHANGED
|
@@ -20,7 +20,8 @@ describe 'Infobar config' do
|
|
|
20
20
|
it 'configures default infobar' do
|
|
21
21
|
Infobar(total: 23)
|
|
22
22
|
infobar.display.reset
|
|
23
|
-
|
|
23
|
+
allow(infobar.display).to receive(:cursor_row).and_return 0
|
|
24
|
+
expect(infobar.display.output).to receive(:<<).with("\r\e[s")
|
|
24
25
|
expect(infobar.display.output).to receive(:<<).with(
|
|
25
26
|
"\e[38;5;22m\e[48;5;40m\e[0m\e[0m"
|
|
26
27
|
)
|
|
@@ -16,17 +16,18 @@ describe Infobar::Display do
|
|
|
16
16
|
before do
|
|
17
17
|
display.output = output
|
|
18
18
|
allow(display).to receive(:columns).and_return 40
|
|
19
|
+
allow(display).to receive(:cursor_row).and_return 0
|
|
19
20
|
end
|
|
20
21
|
|
|
21
22
|
it 'can be updated' do
|
|
22
23
|
display.update message: 'test', counter: counter
|
|
23
24
|
expect(output.tap(&:rewind).read).to eq\
|
|
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
|
+
"\r\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
26
|
end
|
|
26
27
|
|
|
27
28
|
it 'update saves position first' do
|
|
28
29
|
display.update message: 'test', counter: counter
|
|
29
|
-
expect(output.tap(&:rewind).read).to start_with "\e[s"
|
|
30
|
+
expect(output.tap(&:rewind).read).to start_with "\r\e[s"
|
|
30
31
|
display.update message: 'test', counter: counter, force: true
|
|
31
32
|
output.rewind
|
|
32
33
|
expect(output.read).to include "\e[u"
|
|
@@ -69,7 +70,7 @@ describe Infobar::Display do
|
|
|
69
70
|
display.style = test_style
|
|
70
71
|
display.update message: 'test', counter: counter
|
|
71
72
|
expect(output.tap(&:rewind).read).to eq\
|
|
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"
|
|
73
|
+
"\r\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"
|
|
73
74
|
expect(display.style).to eq(test_style)
|
|
74
75
|
end
|
|
75
76
|
|
|
@@ -95,7 +96,7 @@ describe Infobar::Display do
|
|
|
95
96
|
).at_least(:once)
|
|
96
97
|
display.update message: 'test', counter: counter
|
|
97
98
|
expect(output.tap(&:rewind).read).to eq\
|
|
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"
|
|
99
|
+
"\r\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"
|
|
99
100
|
end
|
|
100
101
|
|
|
101
102
|
it 'can output newline' do
|