class Byebug::LocalInterface

Interface class for standard byebug use.

Constants

EOF_ALIAS

Public Class Methods

new() click to toggle source
Calls superclass method Byebug::Interface::new
# File lib/byebug/interfaces/local_interface.rb, line 10
def initialize
  super()
  @input = $stdin
  @output = $stdout
  @error = $stderr
end

Public Instance Methods

readline(prompt) click to toggle source

Reads a single line of input using Readline. If Ctrl-D is pressed, it returns “continue”, meaning that program’s execution will go on.

@param prompt Prompt to be displayed.

# File lib/byebug/interfaces/local_interface.rb, line 23
def readline(prompt)
  with_repl_like_sigint { without_readline_completion { Readline.readline(prompt) || EOF_ALIAS } }
end
with_repl_like_sigint() { || ... } click to toggle source

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.

@note Any external ‘INT’ traps are overriden during this method.

# 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_readline_completion() { || ... } click to toggle source

Disable any Readline 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 Readline.

# File lib/byebug/interfaces/local_interface.rb, line 51
def without_readline_completion
  orig_completion = Readline.completion_proc
  return yield unless orig_completion

  begin
    Readline.completion_proc = ->(_) { nil }
    yield
  ensure
    Readline.completion_proc = orig_completion
  end
end