infobar 0.15.0 → 0.17.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: 78cbcd08f0a2d2ddd1094df459bf3ca54bf3daab8ce3414263f51df214292d16
4
- data.tar.gz: 477e29d5f2e1fe56a422083c6efceb770eee9b570594c9ad6ba33f54104240ee
3
+ metadata.gz: fbac07b2903afac38fab91239a60457fcc4f6b34a40a0b9c6b99eb4075c171a3
4
+ data.tar.gz: 4de63ffbc567bfce47dce19228d49740e69baafc39d1cd4e953d3c8a0e5e0d1d
5
5
  SHA512:
6
- metadata.gz: 6d3f41bbf6ae87c63fc4183d229f12ce505f58bcd72eb7f6ba568a521d23ef48561929c19ded01d4154c5b38c5e11d9c3cb4052b609893c61eb746839b5824dd
7
- data.tar.gz: af5a5669ff6057a85a76f9ecf07be72cc384359de19ea4b034d398c0bd2175e49d79d8c9b95ebd364c3c0a0202721ae8a6e098159f677f07a7451f62fe20ee16
6
+ metadata.gz: e1a77c76049492567509528698d206741e2ef37f2db3f8584b6ca42b2d2b5a10aafa07a99f49eba16119af044286b1fa12707d3e6eb3dfc3e7defa5b2bd0d366
7
+ data.tar.gz: 75ff8183c7089b0f6e339f41decd4a3f4078023f2a1df206c3a0cd611b2652311cd4ae1b50e1c63115686c1a18d8162d99dbd2f73961d12057c4d42b0ae1067d
data/CHANGES.md CHANGED
@@ -1,5 +1,40 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-11-19 v0.17.0
4
+
5
+ ### Build & CI
6
+
7
+ - Bumped the minimum required version of the `gem_hadar` development dependency
8
+ to **2.24.1**.
9
+ - Removed Vim modelines from `Gemfile` and `Rakefile`.
10
+
11
+ ## 2026-11-17 v0.16.0
12
+
13
+ ### Features
14
+
15
+ - Added intelligent bar abandonment detection using `Reline::IOGate.cursor_pos`
16
+ to track the bar's home row.
17
+ - Implemented logic to detect when the cursor has moved away from the saved bar
18
+ position, preventing visual artifacts when the bar is cleared or updated
19
+ after terminal output.
20
+
21
+ ### Improvements
22
+
23
+ - Modified `save_position!` to emit a carriage return (`\r`) before saving the
24
+ cursor position, ensuring the bar always anchors at column 1.
25
+ - Updated `clear` to check if the current cursor row matches the saved
26
+ `@home_row`; if they differ, it falls back to carriage-return-based clearing
27
+ instead of restoring the saved position.
28
+ - Added `cursor_row` method to query the current cursor row via `Reline`.
29
+ - Reset `@home_row` to `nil` in `reset`, `clear`, and `newline` methods to
30
+ maintain state consistency.
31
+
32
+ ### Testing
33
+
34
+ - Updated `spec/infobar/config_spec.rb` and `spec/infobar/display_spec.rb` to
35
+ mock `cursor_row` and verify the new carriage return behavior in output
36
+ sequences.
37
+
3
38
  ## 2026-11-16 v0.15.0
4
39
 
5
40
  ### Fixes
data/Gemfile CHANGED
@@ -1,5 +1,3 @@
1
- # vim: set filetype=ruby et sw=2 ts=2:
2
-
3
1
  source 'https://rubygems.org'
4
2
 
5
3
  gemspec
data/Rakefile CHANGED
@@ -1,5 +1,3 @@
1
- # vim: set filetype=ruby et sw=2 ts=2:
2
-
3
1
  require 'gem_hadar'
4
2
 
5
3
  GemHadar do
data/infobar.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: infobar 0.15.0 ruby lib
2
+ # stub: infobar 0.17.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "infobar".freeze
6
- s.version = "0.15.0".freeze
6
+ s.version = "0.17.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]
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.specification_version = 4
24
24
 
25
- s.add_development_dependency(%q<gem_hadar>.freeze, [">= 2.21.0".freeze])
25
+ s.add_development_dependency(%q<gem_hadar>.freeze, [">= 2.24.1".freeze])
26
26
  s.add_development_dependency(%q<simplecov>.freeze, [">= 0".freeze])
27
27
  s.add_development_dependency(%q<rspec>.freeze, [">= 0".freeze])
28
28
  s.add_development_dependency(%q<debug>.freeze, [">= 0".freeze])
@@ -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 = true
40
- @style = self.class.default_style.dup
41
- @position_saved = false
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 = infobar.convert_to_message(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
@@ -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.15.0'
8
+ VERSION = '0.17.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:
@@ -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
- expect(infobar.display.output).to receive(:<<).with("\e[s")
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
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.15.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 2.21.0
18
+ version: 2.24.1
19
19
  type: :development
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: 2.21.0
25
+ version: 2.24.1
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: simplecov
28
28
  requirement: !ruby/object:Gem::Requirement