123456789_123456789_123456789_123456789_123456789_

Class: DEBUGGER__::UI_LocalConsole

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, UI_Base
Instance Chain:
self, UI_Base
Inherits: DEBUGGER__::UI_Base
Defined in: lib/debug/local.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.newUI_LocalConsole

[ GitHub ]

  
# File 'lib/debug/local.rb', line 8

def initialize
  @console = Console.new
end

Instance Attribute Details

#remote?Boolean (readonly)

[ GitHub ]

  
# File 'lib/debug/local.rb', line 12

def remote?
  false
end

Instance Method Details

#activate(session, on_fork: false)

[ GitHub ]

  
# File 'lib/debug/local.rb', line 16

def activate session, on_fork: false
  unless CONFIG[:no_sigint_hook]
    prev_handler = trap(:SIGINT){
      if session.active?
        ThreadClient.current.on_trap :SIGINT
      end
    }
    session.intercept_trap_sigint_start prev_handler
  end
end

#after_fork_parent

[ GitHub ]

  
# File 'lib/debug/local.rb', line 90

def after_fork_parent
  parent_pid = Process.pid

  at_exit{
    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)

[ GitHub ]

  
# File 'lib/debug/local.rb', line 48

def ask prompt
  setup_interrupt do
    print prompt
    ($stdin.gets || '').strip
  end
end

#deactivate

[ GitHub ]

  
# File 'lib/debug/local.rb', line 27

def deactivate
  if SESSION.intercept_trap_sigint?
    prev = SESSION.intercept_trap_sigint_end
    trap(:SIGINT, prev)
  end

  @console.deactivate
end

#puts(str = nil)

[ GitHub ]

  
# File 'lib/debug/local.rb', line 55

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)

[ GitHub ]

  
# File 'lib/debug/local.rb', line 44

def quit n
  exit n
end

#readline(prompt = '(rdbg)')

[ GitHub ]

  
# File 'lib/debug/local.rb', line 70

def readline prompt = '(rdbg)'
  setup_interrupt do
    (@console.readline(prompt) || 'quit').strip
  end
end

#setup_interrupt

[ GitHub ]

  
# File 'lib/debug/local.rb', line 76

def setup_interrupt
  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

[ GitHub ]

  
# File 'lib/debug/local.rb', line 36

def width
  if (w = IO.console_size[1]) == 0 # for tests PTY
    80
  else
    w
  end
end