module Remedy::Keyboard

Public Instance Methods

dont_raise_on_control_c!() click to toggle source
# File lib/remedy/keyboard.rb, line 59
def dont_raise_on_control_c!
  @raise_on_control_c = false
end
dont_raise_on_unrecognized_key!() click to toggle source
# File lib/remedy/keyboard.rb, line 47
def dont_raise_on_unrecognized_key!
  @raise_on_unrecognized_key = false
end
get() click to toggle source
# File lib/remedy/keyboard.rb, line 8
def get
  parse raw_get
end
parse(sequence) click to toggle source
# File lib/remedy/keyboard.rb, line 25
def parse sequence
  key = Key.new sequence

  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
raise_on_control_c!() click to toggle source
# File lib/remedy/keyboard.rb, line 55
def raise_on_control_c!
  @raise_on_control_c = true
end
raise_on_control_c?() click to toggle source
# File lib/remedy/keyboard.rb, line 51
def raise_on_control_c?
  @raise_on_control_c
end
raise_on_unrecognized_key!() click to toggle source
# File lib/remedy/keyboard.rb, line 43
def raise_on_unrecognized_key!
  @raise_on_unrecognized_key = true
end
raise_on_unrecognized_key?() click to toggle source
# File lib/remedy/keyboard.rb, line 39
def raise_on_unrecognized_key?
  @raise_on_unrecognized_key
end
raw_get() click to toggle source
# File lib/remedy/keyboard.rb, line 12
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

    input
  end
end