Class: RubyTUI::Input::Reader
- Inherits:
-
Object
- Object
- RubyTUI::Input::Reader
- Defined in:
- lib/rubytui/input/reader.rb
Overview
Reads terminal input without blocking and decodes it with a Parser.
A lone ESC byte is told apart from the start of an escape sequence by waiting up to ESC_TIMEOUT_MS for more bytes.
Constant Summary collapse
- ESC_TIMEOUT_MS =
Timeout for disambiguating standalone ESC from escape sequences (ms)
50
Instance Method Summary collapse
-
#initialize(input: $stdin) ⇒ Reader
constructor
A new instance of Reader.
-
#poll(timeout_ms: 100) ⇒ KeyEvent, ...
Poll for an event with the given timeout.
-
#read ⇒ KeyEvent, MouseEvent
Blocking read - waits indefinitely for an event.
Constructor Details
Instance Method Details
#poll(timeout_ms: 100) ⇒ KeyEvent, ...
Poll for an event with the given timeout.
32 33 34 35 36 37 38 |
# File 'lib/rubytui/input/reader.rb', line 32 def poll(timeout_ms: 100) timeout_sec = timeout_ms / 1000.0 ready = IO.select([@input], nil, nil, timeout_sec) return nil unless ready read_event end |
#read ⇒ KeyEvent, MouseEvent
Blocking read - waits indefinitely for an event.
Calls #poll in a loop until it returns an event.
45 46 47 48 49 50 |
# File 'lib/rubytui/input/reader.rb', line 45 def read loop do event = poll(timeout_ms: 1000) return event if event end end |