irb-autosuggestions 0.2.0 → 0.2.1

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: 48eb1b9edb63b8d65e26cb9917c5631ec58ccac72e05ab0c47efa7c2521e84c0
4
- data.tar.gz: 7369bbf6293a3ff1c99f733b5026d3d0d6a68305af4330af8ebe5feff8944041
3
+ metadata.gz: b9d8279c02d62499ce7d58d2b8c4c47c7f8289fa4e601b140106219ea4d0d472
4
+ data.tar.gz: f35c372e76961a2b91fc65bdf1fe94e6ec6daa7fec810461b49eb8dd11c34379
5
5
  SHA512:
6
- metadata.gz: d362044adf712df1f2f36a7305554c837263001d557fe6d999614f51cfd43901b336402326c3008d20c2191c89c60fb54618e79dd785626ceb0abd11eb7d43f4
7
- data.tar.gz: d7aee55ff2cd6ec1c49c0b4adeeb890010cda94ffe0b354acb7d63c50081bb6c74c79f8553f820564b592c2ca47cdf8239a492ac1f1a97754be60190ab641635
6
+ metadata.gz: 838a7272d857247def598a2989cd8c43eb35b8272183ce3623c25c53faa8e3bb2c375ed3b0006ec9942c2a34537e8fdc644961ab61477dfd86118fbc9f4ccf33
7
+ data.tar.gz: 85643f9c47045b2accbceb5a0f84b4eb13ae988b39550a541a21e320fec2f81d75e56128a73a59a9ab5061f0ccce1a2c8e984fcebb8b5a083b2927fcd0c6171f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- irb-autosuggestions (0.2.0)
4
+ irb-autosuggestions (0.2.1)
5
5
  reline
6
6
 
7
7
  GEM
@@ -75,6 +75,7 @@ GEM
75
75
  PLATFORMS
76
76
  arm64-darwin-24
77
77
  arm64-darwin-25
78
+ ruby
78
79
  x86_64-linux
79
80
 
80
81
  DEPENDENCIES
@@ -90,4 +91,4 @@ DEPENDENCIES
90
91
  yard (>= 0.9.38)
91
92
 
92
93
  BUNDLED WITH
93
- 4.0.12
94
+ 4.0.11
data/Gemfile_2_7.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- irb-autosuggestions (0.2.0)
4
+ irb-autosuggestions (0.2.1)
5
5
  reline
6
6
 
7
7
  GEM
@@ -70,8 +70,8 @@ GEM
70
70
  yard (0.9.44)
71
71
 
72
72
  PLATFORMS
73
- x86_64-linux
74
73
  arm64-darwin-25
74
+ x86_64-linux
75
75
 
76
76
  DEPENDENCIES
77
77
  docscribe
data/README.md CHANGED
@@ -113,7 +113,8 @@ Or from command line:
113
113
  irb --nocolorize
114
114
  ```
115
115
 
116
- > [!NOTE] Colorized ghost rendering may behave differently across terminal emulators, Ruby versions, and IRB color
116
+ > [!NOTE]
117
+ > Colorized ghost rendering may behave differently across terminal emulators, Ruby versions, and IRB color
117
118
  > schemes. If you notice visual artifacts (e.g., wrong colors, underlines, or unusual brightness), try disabling the
118
119
  > feature or switch to the gray fallback or create new issue.
119
120
 
@@ -36,15 +36,13 @@ module Irb
36
36
  super
37
37
  end
38
38
 
39
- private
40
-
41
39
  # Injects ghost text into terminal output after Reline finishes rendering.
42
- # Clears any previous ghost text (inline and multi-line) first,
43
- # then renders the new ghost suggestion.
40
+ # Must be public because Reline::Core calls +rerender+ externally.
41
+ # Works on both Reline 0.3.x (rerender is the main rendering entry) and
42
+ # Reline 0.4+ (rerender calls render internally).
44
43
  #
45
- # @private
46
44
  # @return [Object] The result of +super+.
47
- def render(...)
45
+ def rerender
48
46
  result = super
49
47
  if enabled?
50
48
  clear_previous_ghost
@@ -53,6 +51,8 @@ module Irb
53
51
  result
54
52
  end
55
53
 
54
+ private
55
+
56
56
  # Prefix-filtered up-arrow history navigation.
57
57
  #
58
58
  # @private
@@ -109,8 +109,8 @@ module Irb
109
109
  end
110
110
 
111
111
  # Clears ghost from the previous frame: inline text from buffer end
112
- # to end of line, and each extra line below. Uses cursor save/restore
113
- # so it does not interfere with Reline's cursor tracking.
112
+ # to end of line, and each extra line below. Restores cursor column
113
+ # afterwards so Reline's cursor tracking is not disturbed.
114
114
  #
115
115
  # @private
116
116
  # @return [void]
@@ -118,10 +118,11 @@ module Irb
118
118
  clear_inline_ghost
119
119
  return unless @ghost_line_count&.positive?
120
120
 
121
+ origin_column = cursor_column_at_byte_pointer
121
122
  output = Reline.core.instance_variable_get(:@output)
122
- output.write("\e[s")
123
123
  @ghost_line_count.times { output.write("\e[1B\e[2K") }
124
- output.write("\e[u")
124
+ output.write("\e[#{@ghost_line_count}A")
125
+ output.write("\e[0G\e[#{origin_column}C")
125
126
  end
126
127
 
127
128
  # Clears inline ghost text from the buffer end to end of line.
@@ -132,12 +133,10 @@ module Irb
132
133
  return unless @has_inline_ghost
133
134
 
134
135
  output = Reline.core.instance_variable_get(:@output)
135
- prompt_width = @prompt ? Reline::Unicode.calculate_width(@prompt) : 0
136
- current_line = @buffer_of_lines[@line_index] || ''
137
- buf_end = prompt_width + Reline::Unicode.calculate_width(current_line)
138
- output.write("\e[s")
139
- output.write("\e[0G\e[#{buf_end}C\e[K")
140
- output.write("\e[u")
136
+ buf_end = move_to_buffer_end
137
+ origin_column = cursor_column_at_byte_pointer
138
+ output.write("#{buf_end}\e[K")
139
+ output.write("\e[0G\e[#{origin_column}C")
141
140
  @has_inline_ghost = false
142
141
  end
143
142
 
@@ -184,32 +183,32 @@ module Irb
184
183
  remove_instance_variable(:@prefix_buffer)
185
184
  end
186
185
 
187
- # Checks whether autosuggestions are enabled via IRB.conf or env var.
186
+ # Whether prefix-filtered history navigation is enabled.
187
+ # Falls back to the value of +enabled?+ when not explicitly set.
188
188
  #
189
189
  # @private
190
190
  # @return [Boolean]
191
- def enabled?
192
- case ENV.fetch(ENV_KEY, nil)
191
+ def navigation_enabled?
192
+ case ENV.fetch(ENV_NAV_KEY, nil)
193
193
  when '0' then false
194
194
  when '1' then true
195
195
  else
196
- val = IRB.conf[CONFIG_KEY]
197
- val.nil? || val
196
+ val = IRB.conf[CONFIG_NAV_KEY]
197
+ val.nil? ? enabled? : val
198
198
  end
199
199
  end
200
200
 
201
- # Whether prefix-filtered history navigation is enabled.
202
- # Falls back to the value of +enabled?+ when not explicitly set.
201
+ # Checks whether autosuggestions are enabled via IRB.conf or env var.
203
202
  #
204
203
  # @private
205
204
  # @return [Boolean]
206
- def navigation_enabled?
207
- case ENV.fetch(ENV_NAV_KEY, nil)
205
+ def enabled?
206
+ case ENV.fetch(ENV_KEY, nil)
208
207
  when '0' then false
209
208
  when '1' then true
210
209
  else
211
- val = IRB.conf[CONFIG_NAV_KEY]
212
- val.nil? ? enabled? : val
210
+ val = IRB.conf[CONFIG_KEY]
211
+ val.nil? || val
213
212
  end
214
213
  end
215
214
 
@@ -325,6 +324,8 @@ module Irb
325
324
  end
326
325
 
327
326
  # Writes the ghost text (inline + extra lines) to terminal output.
327
+ # Saves and restores cursor column so Reline's cursor tracking
328
+ # (used for left/right arrow positioning) is not disturbed.
328
329
  #
329
330
  # If +suggestion+ is provided and colorization is enabled, the ghost
330
331
  # is rendered with syntax highlighting via IRB::Color.
@@ -333,16 +334,19 @@ module Irb
333
334
  # @param [String] ghost The ghost text (suffix of the suggestion).
334
335
  # @param [String, nil] suggestion The full matching history entry.
335
336
  # @return [void]
336
- def render_ghost(ghost, suggestion = nil)
337
+ def render_ghost(ghost, suggestion = nil) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
337
338
  output = Reline.core.instance_variable_get(:@output)
338
339
  display_lines = ghost_display_lines(ghost, suggestion)
339
340
  @ghost_line_count = display_lines.size - 1
340
341
  @has_inline_ghost = true
341
342
 
343
+ output.write(move_to_buffer_end)
342
344
  first_line = display_lines.first
343
345
  output.write(first_line) if first_line && !first_line.empty?
344
346
  write_extra_ghost_lines(display_lines.drop(1))
345
- restore_cursor_after(display_lines)
347
+ origin_column = cursor_column_at_byte_pointer
348
+ output.write("\e[#{@ghost_line_count}A") if @ghost_line_count.positive?
349
+ output.write("\e[0G\e[#{origin_column}C")
346
350
  output.flush
347
351
  end
348
352
 
@@ -456,20 +460,26 @@ module Irb
456
460
  end
457
461
  end
458
462
 
459
- # Restores the cursor to the end of the buffer after ghost rendering.
463
+ # Returns the terminal column where the cursor should sit (after the
464
+ # prompt and currently typed text at +@byte_pointer+).
460
465
  #
461
466
  # @private
462
- # @param [Array<String>] lines The ghost split into lines.
463
- # @return [void]
464
- def restore_cursor_after(lines)
465
- extra_count = lines.size - 1
467
+ # @return [Integer]
468
+ def cursor_column_at_byte_pointer
466
469
  prompt_width = @prompt ? Reline::Unicode.calculate_width(@prompt) : 0
467
- pos = prompt_width + (@buffer_of_lines[@line_index] || '').length
468
- output = Reline.core.instance_variable_get(:@output)
470
+ current_line = @buffer_of_lines[@line_index] || ''
471
+ prompt_width + Reline::Unicode.calculate_width(current_line[0...@byte_pointer])
472
+ end
469
473
 
470
- output.write("\e[#{extra_count}A") if extra_count.positive?
471
- output.write("\e[0G")
472
- output.write("\e[#{pos}C")
474
+ # Moves cursor to the end of the buffer line (for writing inline ghost).
475
+ #
476
+ # @private
477
+ # @return [String]
478
+ def move_to_buffer_end
479
+ prompt_width = @prompt ? Reline::Unicode.calculate_width(@prompt) : 0
480
+ current_line = @buffer_of_lines[@line_index] || ''
481
+ buf_end = prompt_width + Reline::Unicode.calculate_width(current_line)
482
+ "\e[0G\e[#{buf_end}C"
473
483
  end
474
484
  end
475
485
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Irb
4
4
  module Autosuggestions
5
- VERSION = '0.2.0'
5
+ VERSION = '0.2.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irb-autosuggestions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - unurgunite
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-05-27 00:00:00.000000000 Z
11
+ date: 2026-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reline