From e8b905896482f2952ccbb4d5bf0a1910edd07bf9 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Thu, 23 Nov 2023 07:29:08 +0000 Subject: [ruby/irb] Hint debugger command in irb:rdbg session (https://github.com/ruby/irb/pull/768) When user enters irb:rdbg session, they don't get the same hint that the `debug` gem provides, like ``` (rdbg) n # next command ``` This means that users may accidentally execute commands when they want to retrieve the value of a variable. So this commit adds a Reline output modifier to add a simiar hint: ``` irb:rdbg(main):002> n # debug command ``` It is not exactly the same as `debug`'s because in this case the importance is to help users distinguish between value evaluation and debugger command execution. https://github.com/ruby/irb/commit/fdf24de851 --- lib/irb/debug.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib') diff --git a/lib/irb/debug.rb b/lib/irb/debug.rb index e522d39300..514395605f 100644 --- a/lib/irb/debug.rb +++ b/lib/irb/debug.rb @@ -57,6 +57,24 @@ module IRB DEBUGGER__::ThreadClient.prepend(SkipPathHelperForIRB) end + if !@output_modifier_defined && !DEBUGGER__::CONFIG[:no_hint] + irb_output_modifier_proc = Reline.output_modifier_proc + + Reline.output_modifier_proc = proc do |output, complete:| + unless output.strip.empty? + cmd = output.split(/\s/, 2).first + + if DEBUGGER__.commands.key?(cmd) + output = output.sub(/\n$/, " # debug command\n") + end + end + + irb_output_modifier_proc.call(output, complete: complete) + end + + @output_modifier_defined = true + end + true end -- cgit v1.2.3