Class: Byebug::LocalInterface
- Defined in:
- lib/byebug/interfaces/local_interface.rb
Overview
Interface class for standard byebug use.
Constant Summary collapse
- EOF_ALIAS =
'continue'.freeze
Instance Attribute Summary
Attributes inherited from Interface
#command_queue, #error, #history, #input, #output
Instance Method Summary collapse
-
#initialize ⇒ LocalInterface
constructor
A new instance of LocalInterface.
-
#readline(prompt) ⇒ Object
Reads a single line of input using Readline.
-
#with_repl_like_sigint ⇒ Object
Yields the block handling Ctrl-C the following way: if pressed while waiting for input, the line is reset to only the prompt and we ask for input again.
Methods inherited from Interface
#autorestore, #autosave, #close, #confirm, #errmsg, #last_if_empty, #prepare_input, #print, #puts, #read_command, #read_file, #read_input
Methods included from Helpers::FileHelper
#get_line, #get_lines, #n_lines, #normalize, #shortpath, #virtual_file?
Constructor Details
#initialize ⇒ LocalInterface
Returns a new instance of LocalInterface.
9 10 11 12 13 14 |
# File 'lib/byebug/interfaces/local_interface.rb', line 9 def initialize super() @input = STDIN @output = STDOUT @error = STDERR end |
Instance Method Details
#readline(prompt) ⇒ Object
Reads a single line of input using Readline. If Ctrl-D is pressed, it returns “continue”, meaning that program’s execution will go on.
22 23 24 25 26 |
# File 'lib/byebug/interfaces/local_interface.rb', line 22 def readline(prompt) with_repl_like_sigint do Readline.readline(prompt, false) || EOF_ALIAS end end |
#with_repl_like_sigint ⇒ Object
Any external ‘INT’ traps are overriden during this method.
Yields the block handling Ctrl-C the following way: if pressed while waiting for input, the line is reset to only the prompt and we ask for input again.
35 36 37 38 39 40 41 42 43 |
# File 'lib/byebug/interfaces/local_interface.rb', line 35 def with_repl_like_sigint orig_handler = trap('INT') { raise Interrupt } yield rescue Interrupt puts('^C') retry ensure trap('INT', orig_handler) end |