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 +4 -4
- data/Gemfile.lock +3 -2
- data/Gemfile_2_7.lock +2 -2
- data/README.md +2 -1
- data/lib/irb/autosuggestions/line_editor_patch.rb +49 -39
- data/lib/irb/autosuggestions/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b9d8279c02d62499ce7d58d2b8c4c47c7f8289fa4e601b140106219ea4d0d472
|
|
4
|
+
data.tar.gz: f35c372e76961a2b91fc65bdf1fe94e6ec6daa7fec810461b49eb8dd11c34379
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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.
|
|
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.
|
|
94
|
+
4.0.11
|
data/Gemfile_2_7.lock
CHANGED
data/README.md
CHANGED
|
@@ -113,7 +113,8 @@ Or from command line:
|
|
|
113
113
|
irb --nocolorize
|
|
114
114
|
```
|
|
115
115
|
|
|
116
|
-
> [!NOTE]
|
|
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
|
-
#
|
|
43
|
-
#
|
|
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
|
|
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.
|
|
113
|
-
# so
|
|
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[
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
output.write("\e[
|
|
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
|
-
#
|
|
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
|
|
192
|
-
case ENV.fetch(
|
|
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[
|
|
197
|
-
val.nil?
|
|
196
|
+
val = IRB.conf[CONFIG_NAV_KEY]
|
|
197
|
+
val.nil? ? enabled? : val
|
|
198
198
|
end
|
|
199
199
|
end
|
|
200
200
|
|
|
201
|
-
#
|
|
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
|
|
207
|
-
case ENV.fetch(
|
|
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[
|
|
212
|
-
val.nil?
|
|
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
|
-
|
|
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
|
-
#
|
|
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
|
-
# @
|
|
463
|
-
|
|
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
|
-
|
|
468
|
-
|
|
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
|
-
|
|
471
|
-
|
|
472
|
-
|
|
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
|
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.
|
|
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-
|
|
11
|
+
date: 2026-05-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: reline
|