cathode icon indicating copy to clipboard operation
cathode copied to clipboard

Implement a control sequence parser

Open alexrp opened this issue 3 years ago • 3 comments

This should basically be a state machine that processes UTF-8 text and invokes handler methods when successfully processing sequences. This will be at the heart of all of our input processing and terminal state tracking.

Can draw inspiration from Windows Terminal: https://github.com/microsoft/terminal/tree/main/src/terminal/parser

alexrp avatar Dec 28 '21 04:12 alexrp

https://vt100.net/emu/dec_ansi_parser

alexrp avatar Dec 28 '21 15:12 alexrp

I'm not sure how to handle the classic ESC ambiguity in input parsing. You can only use brittle heuristics (e.g. input buffer size or timing) to attempt to distinguish an Escape key press from a longer input sequence that happens to start with the ESC character. This is necessarily going to have a sweeping effect on the parser API shape...

alexrp avatar Jul 24 '22 16:07 alexrp

When I implemented ambiguous ESC key detection in my own tooling, I did a small survey of established tools and libraries to see how others handled it, and the timeout method was the most common.

The tcell term library (which I use as a gold standard) implemented it that way here:

https://github.com/gdamore/tcell/blob/master/tscreen.go#L1624

scottbilas avatar Jul 24 '22 20:07 scottbilas