Class: Byebug::LocalInterface

Inherits:
Interface show all
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

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

#initializeLocalInterface

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 Readline. If Ctrl-D is pressed, it returns “continue”, meaning that program’s execution will go on.

Parameters:

  • prompt

    Prompt to be displayed.



23
24
25
# File 'lib/byebug/interfaces/local_interface.rb', line 23

def readline(prompt)
  with_repl_like_sigint { Readline.readline(prompt) || EOF_ALIAS }
end

#with_repl_like_sigintObject

Note:

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