File tree Expand file tree Collapse file tree 3 files changed +28
-3
lines changed Expand file tree Collapse file tree 3 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,20 @@ def reset_tab_completion(tab_complete_proc = nil)
40
40
::Readline . completion_proc = tab_complete_proc || @rl_saved_proc
41
41
end
42
42
43
+
44
+ #
45
+ # Retrieve the line buffer
46
+ #
47
+ def line_buffer
48
+ if defined? RbReadline
49
+ RbReadline . rl_line_buffer
50
+ else
51
+ ::Readline . line_buffer
52
+ end
53
+ end
54
+
55
+ attr_accessor :prompt
56
+
43
57
#
44
58
# Whether or not the input medium supports readline.
45
59
#
@@ -124,12 +138,13 @@ def readline_with_output(prompt, add_history=false)
124
138
# to reimplement []`Readline.readline`](https://github.com/luislavena/rb-readline/blob/ce4908dae45dbcae90a6e42e3710b8c3a1f2cd64/lib/readline.rb#L36-L58)
125
139
# for rb-readline to support setting input and output. Output needs to be set so that colorization works for the
126
140
# prompt on Windows.
141
+ self . prompt = prompt
127
142
if defined? RbReadline
128
143
RbReadline . rl_instream = fd
129
144
RbReadline . rl_outstream = output
130
145
131
146
begin
132
- line = RbReadline . readline ( prompt )
147
+ line = RbReadline . readline ( " \001 \r \033 [K \002 " + prompt )
133
148
rescue ::Exception => exception
134
149
RbReadline . rl_cleanup_after_signal ( )
135
150
RbReadline . rl_deprep_terminal ( )
@@ -143,7 +158,7 @@ def readline_with_output(prompt, add_history=false)
143
158
144
159
line . try ( :dup )
145
160
else
146
- ::Readline . readline ( prompt , true )
161
+ ::Readline . readline ( " \001 \r \033 [K \002 " + prompt , true )
147
162
end
148
163
end
149
164
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ def initialize
29
29
super
30
30
end
31
31
attr_reader :config
32
+ attr_accessor :input
32
33
33
34
def disable_color
34
35
@config [ :color ] = false
@@ -60,7 +61,14 @@ def print_status(msg = '')
60
61
end
61
62
62
63
def print_line ( msg = '' )
63
- print ( msg + "\n " )
64
+ print ( "\033 [s" ) # Save cursor position
65
+ print ( "\r \033 [K" + msg + "\n " )
66
+ if input and input . prompt
67
+ print ( "\r \033 [K" )
68
+ print ( input . prompt )
69
+ print ( input . line_buffer )
70
+ print ( "\033 [u\033 [B" ) # Restore cursor, move down one line
71
+ end
64
72
end
65
73
66
74
def print_warning ( msg = '' )
Original file line number Diff line number Diff line change @@ -184,7 +184,9 @@ def run(&block)
184
184
self . init_prompt = input . prompt
185
185
end
186
186
187
+ output . input = input
187
188
line = input . pgets ( )
189
+ output . input = nil
188
190
log_output ( input . prompt )
189
191
190
192
# If a block was passed in, pass the line to it. If it returns true,
You can’t perform that action at this time.
0 commit comments