microsoft / microsoft/terminal
terminal/parser: determine what to do when split escape sequence writes show up
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 105k
- Forks
- 9.6k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 29
Description
Environment
Windows build number: Version 10.0.18363.535
(reproducible with OpenConsole from master)
Windows Terminal version (if applicable): n/a
Any other software?
- Simple ConPTY test code
Steps to reproduce
- Create pseudo console as seen in examples
- Copy I/O to and from serial / COM port; alternatively manually write CSI or escape sequence in multiple write operations.
Example for arrow-up key (as seen during development with serial ports):
Write 1: 0x1b
Write 2: 0x5b 0x41
Expected behavior
- Working escape sequences over multiple write operations to PTY input pipe
Example for arrow-up key:
$ showkey -a
Press any keys - Ctrl-D will terminate this program
^[[A 27 0033 0x1b
91 0133 0x5b
65 0101 0x41
Actual behavior
Due to FlushAtEndOfString being true, the escape sequence is split up and rendered wrong. E.g. arrow-up becomes:
^[ 27 0033 0x1b
[A 91 0133 0x5b
65 0101 0x41
which only renders "[A" to the PTY without the desired effect.
This is 100% reproducible, i.e. the arrow keys never work because they are always received as two reads from the (virtual) serial port.
Note: A custom build of conhost.exe (OpenConsole.exe) with FlushAtEndOfString changed to return false does correctly process split escape sequence writes.
Comments
The comment in the caller in stateMachine.cpp says the following:
// <kbd>alt+[</kbd>, <kbd>A</kbd> would be processed like `\x1b[A`,
// which is _wrong_).
//
// Fortunately, for VT input, each keystroke comes in as an individual
// write operation.
I think both statements here are wrong, or at least not universally true. Typing Alt+[ and A on a VTE based Linux terminal emulator (e.g. gnome-terminal or xfce4-terminal) will result in the same reaction as pressing the arrow-up key.
Is there any standard that guarantees VT input sequences to happen in single writes? I tested Linux support of split escape sequence writes - it worked fine on Linux 5.4 framebuffer getty TTY and on all tested PTY terminal emulators (xterm, VTE, etc.).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with FlushAtEndOfString in src/terminal/parser/InputStateMachineEngine.cpp and the caller comment in src/terminal/parser/stateMachine.cpp. Reproduce the two-write escape sequence through the ConPTY path, then review related pull request #2823 and the parser behavior around split input. Done means split CSI sequences work without incorrectly combining separate Alt+[ and A input.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- cli, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100