Class: RubyTUI::Input::Parser
- Inherits:
-
Object
- Object
- RubyTUI::Input::Parser
- Defined in:
- lib/rubytui/input/parser.rb
Overview
Decodes raw terminal input into KeyEvent and MouseEvent objects.
Recognised input: printable ASCII, Enter, Tab, Backspace, Ctrl+letter, multi-byte UTF-8 characters given as raw bytes (as read by Reader), ESC, Alt+character (ESC followed by one character), CSI and SS3 key sequences (arrows, Home/End, Insert/Delete, Page Up/Down, Back-tab, F1-F12, xterm modified arrows such as ESC [ 1 ; 5 A), and SGR and legacy mouse reports.
Instance Method Summary collapse
-
#parse(bytes) ⇒ KeyEvent, ...
Parse raw bytes into an Event.
Instance Method Details
#parse(bytes) ⇒ KeyEvent, ...
Parse raw bytes into an Event.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rubytui/input/parser.rb', line 22 def parse(bytes) return nil if bytes.nil? || bytes.empty? # ESC sequence if bytes.start_with?("\e") parse_escape(bytes) elsif bytes.length == 1 parse_single(bytes) else # Multi-byte UTF-8 character KeyEvent.new(code: Key::CHAR, char: bytes) end end |