Repository navigation
Fix VT sequences leaking as text when Esc is held - #1012
Conversation
|
@microsoft-github-policy-service agree |
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { |
There was a problem hiding this comment.
Can you back out these tests from the PR? Otherwise: LGTM!
There was a problem hiding this comment.
Sure thing, just dropped the tests! Thanks for taking a look.
Dustin L. Howett (DHowett)
left a comment
There was a problem hiding this comment.
I'd be interested in seeing more precedent for this. Line editors seem to treat the following ESC as cancelling the first (expected); visual editors like nano seem to treat it in the new way you are proposing. Midnight Commander seems to defer behavior to the shell (see "line editors" above).
| '\x1b' => { | ||
| // ESC ESC: the first one was a lone Escape key press (e.g. while | ||
| // holding Esc). Stay in the Esc state so that whatever follows | ||
| // (e.g. `[A`) is still parsed as a sequence and not as text. | ||
| return Some(Token::Esc('\0')); | ||
| } |
There was a problem hiding this comment.
I do not believe this is correct.
VT100:
This state is entered whenever the C0 control ESC is received. This will immediately cancel any escape sequence, control sequence or control string in progress. If an escape sequence or control sequence was in progress, “cancel” means that the sequence will have no effect
xterm's altSendsEscape and metaSendsEscape do not countermand this.
There was a problem hiding this comment.
Makes total sense, thanks for catching that! Updated it to just cancel the previous ESC and stay in State::Esc per VT100 instead of emitting Esc('\0'), so whatever follows still gets parsed as a sequence instead of leaking as text. Really appreciate the review!
Leonard Hecker (lhecker)
left a comment
There was a problem hiding this comment.
Thanks! (And thanks Dustin! Didn't know about that!)
Closes #641
When Esc is held and another key sends a sequence, the input looks like
ESC ESC [ A. Previously, the parser treated the second ESC as the final char of anESC xsequence,input.rsdropped thatEsc('\x1b')token, and[Athen came through as plain text.Now, per the VT100 state machine, receiving
ESCwhile inState::Esccancels the previous escape sequence and stays inState::Esc, so whatever follows (e.g.[A) is still parsed as a sequence instead of leaking as text.