class IRB::Debug::UI

Public Class Methods

new(thread, irb) click to toggle source
# File irb/debug/ui.rb, line 7
def initialize(thread, irb)
  @thread = thread
  @irb = irb
end

Public Instance Methods

activate(session, on_fork: false) click to toggle source
# File irb/debug/ui.rb, line 16
def activate session, on_fork: false
end
after_fork_parent() click to toggle source
# File irb/debug/ui.rb, line 85
def after_fork_parent
  parent_pid = Process.pid

  at_exit{
    DEBUGGER__::SESSION.intercept_trap_sigint_end
    trap(:SIGINT, :IGNORE)

    if Process.pid == parent_pid
      # only check child process from its parent
      begin
        # wait for all child processes to keep terminal
        Process.waitpid
      rescue Errno::ESRCH, Errno::ECHILD
      end
    end
  }
end
ask(prompt) click to toggle source
# File irb/debug/ui.rb, line 35
def ask prompt
  setup_interrupt do
    print prompt
    ($stdin.gets || '').strip
  end
end
deactivate() click to toggle source
# File irb/debug/ui.rb, line 19
def deactivate
end
puts(str = nil) click to toggle source
# File irb/debug/ui.rb, line 42
def puts str = nil
  case str
  when Array
    str.each{|line|
      $stdout.puts line.chomp
    }
  when String
    str.each_line{|line|
      $stdout.puts line.chomp
    }
  when nil
    $stdout.puts
  end
end
quit(n) { || ... } click to toggle source
# File irb/debug/ui.rb, line 30
def quit n
  yield
  exit n
end
readline(_) click to toggle source
# File irb/debug/ui.rb, line 57
def readline _
  setup_interrupt do
    tc = DEBUGGER__::SESSION.get_thread_client(@thread)
    cmd = @irb.debug_readline(tc.current_frame.binding || TOPLEVEL_BINDING)

    case cmd
    when nil # when user types C-d
      "continue"
    else
      cmd
    end
  end
end
remote?() click to toggle source
# File irb/debug/ui.rb, line 12
def remote?
  false
end
setup_interrupt() { || ... } click to toggle source
# File irb/debug/ui.rb, line 71
def setup_interrupt
  DEBUGGER__::SESSION.intercept_trap_sigint false do
    current_thread = Thread.current # should be session_server thread

    prev_handler = trap(:INT){
      current_thread.raise Interrupt
    }

    yield
  ensure
    trap(:INT, prev_handler)
  end
end
width() click to toggle source
# File irb/debug/ui.rb, line 22
def width
  if (w = IO.console_size[1]) == 0 # for tests PTY
    80
  else
    w
  end
end