module TLSPretense::TestHarness::InputHandler
EM handler to handle keyboard input while a test is running.
Public Class Methods
new(stdin=$stdin)
click to toggle source
# File lib/tlspretense/test_harness/input_handler.rb, line 6 def initialize(stdin=$stdin) @stdin = stdin @actions = {} # Set the term to accept keystrokes immediately. if @stdin.tty? @stdin.enable_raw_chars end end
Public Instance Methods
on(char, blk=nil, &block)
click to toggle source
# File lib/tlspretense/test_harness/input_handler.rb, line 31 def on(char, blk=nil, &block) puts "Warning: setting a keyboard handler for a keystroke that is longer than one char: #{char.inspect}" if char.length != 1 raise ArgumentError, "No block passed in" if blk == nil and block == nil @actions[char] = ( blk ? blk : block) end
receive_data(data)
click to toggle source
Receives one character at a time.
# File lib/tlspretense/test_harness/input_handler.rb, line 24 def receive_data(data) raise "data was longer than 1 char: #{data.inspect}" if data.length != 1 if @actions.has_key? data @actions[data].call end end
unbind()
click to toggle source
# File lib/tlspretense/test_harness/input_handler.rb, line 16 def unbind # Clean up by resotring the old termios if @stdin.tty? @stdin.disable_raw_chars end end