summaryrefslogtreecommitdiffstats
path: root/terminal-scanner.cabal
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-16 02:16:59 +0000
committertv <tv@krebsco.de>2026-11-16 04:13:17 +0100
commit03046ee6c7279da313e2e156ced4c350488be5ee (patch)
treedbfa991df05c1093842c990e2fb8b5be2e41cafd /terminal-scanner.cabal
parent37a5a4be992d8893ca2a81fbc1ca250b4895e5df (diff)
scan: return what was read instead of throwing
scan threw on input it did not expect: an escape sequence that stopped early (Alt-O sends ESC O and nothing else, a slow link splits sequences) or that contained a character outside its syntax. In a program that scans in a thread of its own, that thread died and the program stopped reading the keyboard. Likewise, an X10 mouse report that stopped early blocked until three more characters came, swallowing the keys typed meanwhile. Now every character of a sequence is read with the timeout, and when a sequence stops early or the next character does not fit, what was read so far is returned as a ScanKey. The character that did not fit stays in the handle for the next scan. For example ESC O alone is ScanKey "\ESCO", which is what Alt-O sends anyway, and ESC [ 1 followed by a newline is ScanKey "\ESC[1" followed by ScanKey "\n". SGR mouse reports are CSI sequences whose parameters start with <, so they are read like any other CSI sequence and decoded afterwards. A malformed one is returned as a ScanKey. This drops expectChar and scanNumber. Errors of the handle itself still propagate, such as end of file, or a byte that the handle's encoding cannot decode.
Diffstat (limited to 'terminal-scanner.cabal')
0 files changed, 0 insertions, 0 deletions