lib/remedy/keyboard.rb in remedy-0.0.3 vs lib/remedy/keyboard.rb in remedy-0.0.4.pre

- old
+ new

@@ -1,66 +1,67 @@ require 'remedy/console' require 'remedy/key' -module Keyboard - module_function +module Remedy + module Keyboard + module_function - def get - parse raw_get - end + def get + parse raw_get + end - def raw_get - Console.raw do - input = STDIN.getc.chr + def raw_get + Console.raw do + input = STDIN.getc.chr - if input == "\e" then - input << STDIN.read_nonblock(3) rescue nil - input << STDIN.read_nonblock(2) rescue nil - end + if input == "\e" then + input << STDIN.read_nonblock(3) rescue nil + input << STDIN.read_nonblock(2) rescue nil + end - input + input + end end - end - def parse sequence - key = Key.new sequence - $log.debug "Key read", key + def parse sequence + key = Key.new sequence + $log.debug "Key read", key - if raise_on_control_c? && key.control_c? then - raise ControlC, "User pressed Control-C" - elsif key.recognized? then - key - elsif raise_on_unrecognized_key? then - raise UnrecognizedInput, %Q{Unknown key or byte sequence: "#{sequence}" : #{key.inspect}} - else - key + if raise_on_control_c? && key.control_c? then + raise ControlC, "User pressed Control-C" + elsif key.recognized? then + key + elsif raise_on_unrecognized_key? then + raise UnrecognizedInput, %Q{Unknown key or byte sequence: "#{sequence}" : #{key.inspect}} + else + key + end end - end - def raise_on_unrecognized_key? - @raise_on_unrecognized_key - end + def raise_on_unrecognized_key? + @raise_on_unrecognized_key + end - def raise_on_unrecognized_key! - @raise_on_unrecognized_key = true - end + def raise_on_unrecognized_key! + @raise_on_unrecognized_key = true + end - def dont_raise_on_unrecognized_key! - @raise_on_unrecognized_key = false - end + def dont_raise_on_unrecognized_key! + @raise_on_unrecognized_key = false + end - def raise_on_control_c? - @raise_on_control_c - end + def raise_on_control_c? + @raise_on_control_c + end - def raise_on_control_c! - @raise_on_control_c = true - end + def raise_on_control_c! + @raise_on_control_c = true + end - def dont_raise_on_control_c! - @raise_on_control_c = false - end + def dont_raise_on_control_c! + @raise_on_control_c = false + end - class ControlC < Interrupt; end - class UnrecognizedInput < IOError; end + class ControlC < Interrupt; end + class UnrecognizedInput < IOError; end + end end -