aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorStan Lo <stan001212@gmail.com>2023-11-23 07:29:08 +0000
committergit <svn-admin@ruby-lang.org>2023-11-23 07:29:12 +0000
commite8b905896482f2952ccbb4d5bf0a1910edd07bf9 (patch)
treec1c3c38ce4cdf09f89d8e17cabaeb74c3987539f /lib
parente2078ccd5a54e54e16bec8db96c45d467307e6c3 (diff)
downloadruby-e8b905896482f2952ccbb4d5bf0a1910edd07bf9.tar.gz
[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
Diffstat (limited to 'lib')
-rw-r--r--lib/irb/debug.rb18
1 files changed, 18 insertions, 0 deletions
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