Class: DEBUGGER__::UI_LocalConsole

Inherits:
UI_Base show all
Defined in:
lib/debug/local.rb

Instance Method Summary collapse

Methods inherited from UI_Base

#event, #flush, #ignore_output_on_suspend?

Constructor Details

#initializeUI_LocalConsole

Returns a new instance of UI_LocalConsole.



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

def initialize
  @console = Console.new
end

Instance Method Details

#activate(session, on_fork: false) ⇒ Object



32
33
34
# File 'lib/debug/local.rb', line 32

def activate session, on_fork: false
  activate_sigint unless CONFIG[:no_sigint_hook]
end

#activate_sigintObject



16
17
18
19
20
21
22
23
# File 'lib/debug/local.rb', line 16

def activate_sigint
  prev_handler = trap(:SIGINT){
    if SESSION.active?
      ThreadClient.current.on_trap :SIGINT
    end
  }
  SESSION.intercept_trap_sigint_start prev_handler
end

#after_fork_parentObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/debug/local.rb', line 96

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) ⇒ Object



54
55
56
57
58
59
# File 'lib/debug/local.rb', line 54

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

#deactivateObject



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

def deactivate
  deactivate_sigint
  @console.deactivate
end

#deactivate_sigintObject



25
26
27
28
29
30
# File 'lib/debug/local.rb', line 25

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

#puts(str = nil) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/debug/local.rb', line 61

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) ⇒ Object



49
50
51
52
# File 'lib/debug/local.rb', line 49

def quit n
  yield
  exit n
end

#readline(prompt = '(rdbg)') ⇒ Object



76
77
78
79
80
# File 'lib/debug/local.rb', line 76

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

#remote?Boolean

Returns:

  • (Boolean)


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

def remote?
  false
end

#setup_interruptObject



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/debug/local.rb', line 82

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

#widthObject



41
42
43
44
45
46
47
# File 'lib/debug/local.rb', line 41

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