Class: Byebug::LocalInterface
- Defined in:
- lib/byebug/interfaces/local_interface.rb
Overview
Interface class for standard byebug use.
Constant Summary collapse
- EOF_ALIAS =
"continue"
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 Reline.
-
#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.
-
#without_reline_completion ⇒ Object
Disable any Reline completion procs.
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.
10 11 12 13 14 15 |
# File 'lib/byebug/interfaces/local_interface.rb', line 10 def initialize super() @input = $stdin @output = $stdout @error = $stderr end |
Instance Method Details
#readline(prompt) ⇒ Object
Reads a single line of input using Reline. If Ctrl-D is pressed, it returns “continue”, meaning that program’s execution will go on.
23 24 25 |
# File 'lib/byebug/interfaces/local_interface.rb', line 23 def readline(prompt) with_repl_like_sigint { without_reline_completion { Reline.readline(prompt) || EOF_ALIAS } } 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.
34 35 36 37 38 39 40 41 42 |
# File 'lib/byebug/interfaces/local_interface.rb', line 34 def with_repl_like_sigint orig_handler = trap("INT") { raise Interrupt } yield rescue Interrupt puts("^C") retry ensure trap("INT", orig_handler) end |
#without_reline_completion ⇒ Object
Disable any Reline completion procs.
Other gems, for example, IRB could’ve installed completion procs that are dependent on them being loaded. Disable those while byebug is the REPL making use of Reline.
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/byebug/interfaces/local_interface.rb', line 51 def without_reline_completion orig_completion = Reline.completion_proc return yield unless orig_completion begin Reline.completion_proc = ->(_) { nil } yield ensure Reline.completion_proc = orig_completion end end |