A ScriptInterface is used when we are reading debugger commands from a command-file rather than an interactive user. Command files appear in a users initialization script (e.g. .rdebugrc) and appear when running the debugger command source (Debugger::SourceCommand).
# File cli/ruby-debug/interface.rb, line 217 def initialize(file, out, verbose=false) super() @command_queue = [] @file = file.respond_to?(:gets) ? file : open(file) @out = out @verbose = verbose @history_save = false @history_length = 256 # take gdb default @histfile = '' end
# File cli/ruby-debug/interface.rb, line 256 def close @file.close end
confirm is called before performing a dangerous action. In running a debugger script, we don’t want to prompt, so we’ll pretend the user has unconditionally said “yes” and return String “y”.
# File cli/ruby-debug/interface.rb, line 248 def confirm(prompt) 'y' end
# File cli/ruby-debug/interface.rb, line 252 def print(*args) @out.printf(*args) end
# File cli/ruby-debug/interface.rb, line 228 def read_command(prompt) while result = @file.gets puts "# #{result}" if @verbose next if result =~ %r^\s*#/ next if result.strip.empty? break end raise IOError unless result result.chomp! end
Do we have ReadLine support? When running an debugger command script, we are not interactive so we just return false.
# File cli/ruby-debug/interface.rb, line 241 def readline_support? false end