diff --git a/lib/debug/console.rb b/lib/debug/console.rb index ec860b423..10a08f1ce 100644 --- a/lib/debug/console.rb +++ b/lib/debug/console.rb @@ -97,6 +97,7 @@ def readline_setup prompt end def readline prompt + clear_stdin readline_setup prompt do Reline.readmultiline(prompt, true){ true } end @@ -132,6 +133,7 @@ def readline_setup end def readline prompt + clear_stdin readline_setup Readline.readline(prompt, true) end @@ -142,6 +144,7 @@ def history rescue LoadError def readline prompt + clear_stdin print prompt $stdin.gets end @@ -152,6 +155,22 @@ def history end end + def clear_stdin + # consume all STDIN input just before prompt + loop do + case r = $stdin.read_nonblock(1, exception: false) + when "\n" + # drop \n + next + when nil, :wait_readable + break + else + $stdin.ungetc r + break + end + end + end + def history_file case when (path = CONFIG[:history_file]) && !path.empty?