module BBS::Telnet::Keys
Key input of a telnet line: control bytes and UTF-8 characters decoded into Strings and Symbols (readkey; Telnet::Escapes decodes the escape sequences of the special keys), and raw bytes for binary protocols (read_raw_byte).
Constants
- CONTROL_KEYS
-
The control bytes that are keys of their own; the other Ctrl-letters are
:ctrl_<letter>. - CTRL_LETTERS
-
The control bytes Ctrl-A … Ctrl-Z.
- CTRL_TO_LETTER
-
Added to a Ctrl-letter byte, gives its lowercase letter.
- ESC_WAIT
-
Seconds to wait for the rest of an escape sequence (or UTF-8 character) before a lone ESC counts as the Escape key.
- UTF8_LEAD
-
The bytes that start a multibyte UTF-8 character.
- UTF8_LEAD_3
-
The lowest lead byte of a three-byte UTF-8 character.
- UTF8_LEAD_4
-
The lowest lead byte of a four-byte UTF-8 character.
- UTF8_TAIL
-
The value of those bits in a continuation byte.
- UTF8_TAIL_MASK
-
The bits that tell a UTF-8 continuation byte.
Public Instance Methods
Source
# File lib/bbs/telnet/keys.rb, line 61 def read_raw_byte(timeout) loop do raw = read_byte(timeout) return raw unless raw.is_a?(String) byte = telnet_data(raw.ord) return byte if byte end end
Reads one byte of the line as an Integer, for binary protocols (ZMODEM): telnet commands are taken out and a doubled IAC comes back as 255. Returns :timeout when nothing came within timeout seconds and nil on hangup.
Source
# File lib/bbs/telnet/keys.rb, line 46 def readkey(timeout: nil) loop do raw = read_byte(timeout) return :idle if raw == :timeout return nil if raw.nil? key = key_of(raw) return key if key end end
Reads one key press, skipping telnet commands (a NAWS report among them updates the window size). Returns:
-
a one-character String for a printable character (UTF-8 included),
-
a Symbol for a special key:
:enter,:tab,:backspace,:escape,:interrupt(Ctrl-C),:ctrl_a…:ctrl_z, arrows,:home,:end,:page_up,:f1…:f12and the like, with analt_,shift_,ctrl_orctrl_shift_prefix for modified keys, -
a MouseEvent for a mouse report,
-
:idlewhen nothing came withintimeoutseconds, -
nilwhen the client hung up.
On a PETSCII line the keys come from BBS::Petscii.key. CR LF and CR NUL count as one :enter. timeout nil waits forever.