From 9643f45c8934be1f319d499be9ee87df7e833edf Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Wed, 4 Jun 2025 16:45:51 +0900 Subject: [PATCH] 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. --- lib/debug/console.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/debug/console.rb b/lib/debug/console.rb index 2c89f035f..48cc7b71f 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,16 @@ def history end end + def clear_stdin + # consume all STDIN input just before prompt + loop do + case $stdin.read_nonblock(1024, exception: false) + when nil, :wait_readable + break + end + end + end + def history_file path = if !CONFIG[:history_file].empty? && File.exist?(File.expand_path(CONFIG[:history_file]))