EM handler to handle keyboard input while a test is running.
# File lib/ssl_test/input_handler.rb, line 7 def initialize(stdin=$stdin) @stdin = stdin @actions = {} # Set the term to accept keystrokes immediately. @stdin.enable_raw_chars end
# File lib/ssl_test/input_handler.rb, line 28 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
Receives one character at a time.
# File lib/ssl_test/input_handler.rb, line 21 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
# File lib/ssl_test/input_handler.rb, line 15 def unbind # Clean up by resotring the old termios @stdin.disable_raw_chars end