Class: IRB::Debug::UI
- Defined in:
- lib/irb/debug/ui.rb
Instance Method Summary collapse
- #activate(session, on_fork: false) ⇒ Object
- #after_fork_parent ⇒ Object
- #ask(prompt) ⇒ Object
- #deactivate ⇒ Object
-
#initialize(irb) ⇒ UI
constructor
A new instance of UI.
- #puts(str = nil) ⇒ Object
- #quit(n) ⇒ Object
- #readline(_) ⇒ Object
- #remote? ⇒ Boolean
- #setup_interrupt ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(irb) ⇒ UI
Returns a new instance of UI.
7 8 9 |
# File 'lib/irb/debug/ui.rb', line 7 def initialize(irb) @irb = irb end |
Instance Method Details
#activate(session, on_fork: false) ⇒ Object
15 16 |
# File 'lib/irb/debug/ui.rb', line 15 def activate session, on_fork: false end |
#after_fork_parent ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/irb/debug/ui.rb', line 84 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) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/irb/debug/ui.rb', line 34 def ask prompt setup_interrupt do print prompt ($stdin.gets || '').strip end end |
#deactivate ⇒ Object
18 19 |
# File 'lib/irb/debug/ui.rb', line 18 def deactivate end |
#puts(str = nil) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/irb/debug/ui.rb', line 41 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
29 30 31 32 |
# File 'lib/irb/debug/ui.rb', line 29 def quit n yield exit n end |
#readline(_) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/irb/debug/ui.rb', line 56 def readline _ setup_interrupt do tc = DEBUGGER__::SESSION.instance_variable_get(:@tc) 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? ⇒ Boolean
11 12 13 |
# File 'lib/irb/debug/ui.rb', line 11 def remote? false end |
#setup_interrupt ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/irb/debug/ui.rb', line 70 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 ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/irb/debug/ui.rb', line 21 def width if (w = IO.console_size[1]) == 0 # for tests PTY 80 else w end end |