Skip to content

Commit 9643f45

Browse files
committed
Clear $stdin before showing prompt
Any input into `$stdin` before showing prompt will be appear on the next prompt, and entering new empty line will dispatch previous command. This patch consumes all input to `$stdin` just before showing the prompt.
1 parent f0579e4 commit 9643f45

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/debug/console.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def readline_setup prompt
9797
end
9898

9999
def readline prompt
100+
clear_stdin
100101
readline_setup prompt do
101102
Reline.readmultiline(prompt, true){ true }
102103
end
@@ -132,6 +133,7 @@ def readline_setup
132133
end
133134

134135
def readline prompt
136+
clear_stdin
135137
readline_setup
136138
Readline.readline(prompt, true)
137139
end
@@ -142,6 +144,7 @@ def history
142144

143145
rescue LoadError
144146
def readline prompt
147+
clear_stdin
145148
print prompt
146149
$stdin.gets
147150
end
@@ -152,6 +155,16 @@ def history
152155
end
153156
end
154157

158+
def clear_stdin
159+
# consume all STDIN input just before prompt
160+
loop do
161+
case $stdin.read_nonblock(1024, exception: false)
162+
when nil, :wait_readable
163+
break
164+
end
165+
end
166+
end
167+
155168
def history_file
156169
path =
157170
if !CONFIG[:history_file].empty? && File.exist?(File.expand_path(CONFIG[:history_file]))

0 commit comments

Comments
 (0)