Module: Amun::Helpers::Keyboard

Defined in:
lib/amun/helpers/keyboard.rb

Overview

a module to deal with the keyboard a complementary module to curses doesn’t intend to replace it it was created to overcome the shorcoming of getting a character + meta from the keyboard in the first place.

Constant Summary collapse

TIMEOUT =
100

Class Method Summary collapse

Class Method Details

.charObject

get a character from the keyboard and make sure you detect the meta combination



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/amun/helpers/keyboard.rb', line 18

def char
  ch = Curses.stdscr.get_char
  modified_character = modified_char if ch == "\e"

  return ch.to_s if modified_character.nil?
  return "#{ch} #{modified_character}" if modified_character.is_a? Numeric
  return "#{ch} #{modified_character}" if modified_character.length > 1

  begin
    eval "?\\M-#{modified_character}"
  rescue SyntaxError
    return "#{ch} #{modified_character}"
  end
end