Class: Tomo::Console::KeyReader
- Inherits:
-
Object
- Object
- Tomo::Console::KeyReader
- Extended by:
- Forwardable
- Defined in:
- lib/tomo/console/key_reader.rb
Instance Method Summary collapse
-
#initialize(input = $stdin) ⇒ KeyReader
constructor
A new instance of KeyReader.
- #next ⇒ Object
Constructor Details
#initialize(input = $stdin) ⇒ KeyReader
Returns a new instance of KeyReader.
12 13 14 15 |
# File 'lib/tomo/console/key_reader.rb', line 12 def initialize(input=$stdin) @buffer = +"" @input = input end |
Instance Method Details
#next ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/tomo/console/key_reader.rb', line 17 def next pressed = raw { getc } pressed << read_chars_nonblock if pressed == "\e" raise Interrupt if pressed == ?\C-c clear if !pressed.match?(/\A\w+\z/) || seconds_since_last_press > 0.75 buffer << pressed end |