vezel-dev / cathode

A terminal-centric replacement for the .NET console APIs.
https://docs.vezel.dev/cathode
BSD Zero Clause License
91 stars 7 forks source link

Implement a control sequence parser #59

Open alexrp opened 2 years ago

alexrp commented 2 years ago

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 commented 2 years ago

https://vt100.net/emu/dec_ansi_parser

alexrp commented 2 years ago

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...

scottbilas commented 2 years ago

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