Module: OpenHAB::Console::IRB::Irb

Defined in:
lib/openhab/console/irb.rb

Instance Method Summary collapse

Instance Method Details

#exitObject

Define #exit instead of using Kernel#exit, to raise an error if we’re not on the main thread (i.e. in the signal handler)

Raises:



18
19
20
21
22
# File 'lib/openhab/console/irb.rb', line 18

def exit
  raise Exit unless Thread.current == context.thread

  super
end

#trap(signal, handler = nil) ⇒ Object

Define #trap instead of using Kernel#trap, so that we register a signal handler against JLine. It can also never be as effective, since it’s an SSH session, not a true signal, and thus it comes in as part of the input stream, and if we’re not actively reading the input stream (cause we’re executing a blocking Ruby method), we won’t see it to be able to interrupt the Ruby code.



28
29
30
31
32
33
34
35
36
37
# File 'lib/openhab/console/irb.rb', line 28

def trap(signal, handler = nil)
  jline_signal = org.jline.terminal.Terminal::Signal.const_get(signal.sub(/^SIG/, ""), false)
  return $terminal.handle(jline_signal, handler) if handler

  $terminal.handle(jline_signal) do
    yield
  rescue StandardError, Exit => e
    context.thread.raise e
  end
end