[PR #4171] [MERGED] Dispatch more C0 control characters from the VT state machine #25672

Open
opened 2026-01-31 09:11:01 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/4171
Author: @j4james
Created: 1/9/2020
Status: Merged
Merged: 1/17/2020
Merged by: @DHowett-MSFT

Base: masterHead: move-vt-control-chars


📝 Commits (6)

  • a10cef7 Add a CarriageReturn method to the ITermDispatch interface to handle the CR control character.
  • eee8e5e Add a private ConGetSet API and a corresponding ITermDispatch method to handle the BEL control character.
  • b78c62c Handle the BEL, BS, TAB, and CR control characters in the OutputStateMachine.
  • 07e2cd5 Add a state machine test to confirm the control characters are dispatched correctly.
  • db89428 Merge branch 'master' into move-vt-control-chars
  • a47b0f1 Update CarriageReturn implementation to use the new _CursorMovePosition method.

📊 Changes

12 files changed (+141 additions, -10 deletions)

View changed files

📝 src/cascadia/TerminalCore/TerminalDispatch.cpp (+8 -0)
📝 src/cascadia/TerminalCore/TerminalDispatch.hpp (+1 -0)
📝 src/host/outputStream.cpp (+9 -0)
📝 src/host/outputStream.hpp (+2 -0)
📝 src/terminal/adapter/ITermDispatch.hpp (+2 -0)
📝 src/terminal/adapter/adaptDispatch.cpp (+24 -0)
📝 src/terminal/adapter/adaptDispatch.hpp (+2 -0)
📝 src/terminal/adapter/conGetSet.hpp (+1 -0)
📝 src/terminal/adapter/termDispatch.hpp (+2 -0)
📝 src/terminal/adapter/ut_adapter/adapterTest.cpp (+7 -0)
📝 src/terminal/parser/OutputStateMachineEngine.cpp (+18 -10)
📝 src/terminal/parser/ut_parser/OutputEngineTest.cpp (+65 -0)

📄 Description

Summary of the Pull Request

This PR moves the handling of the BEL, BS, TAB, and CR controls characters into the state machine (when in VT mode), instead of forwarding them on to the default string writer, which would otherwise have to parse them out all over again.

This doesn't cover all the control characters, but ESC, SUB, and CAN are already an integral part of the StateMachine itself; NUL is filtered out by the OutputStateMachineEngine; and LF, FF, and VT are due to be implemented as part of PR #3271.

Once all of these controls are handled at the state machine level, we can strip out all the VT-specific code from the WriteCharsLegacy function, which should simplify it considerably. This would also let us simplify the Terminal::_WriteBuffer implementation, and the planned replacement stream writer for issue #780.

References

#3271, #780, #3628, #4046

PR Checklist

  • Closes #xxx
  • CLA signed. If not, go over here and sign the CLA
  • Tests added/passed
  • Requires documentation to be updated
  • I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: https://github.com/microsoft/terminal/issues/780#issuecomment-570287435

Detailed Description of the Pull Request / Additional comments

On the conhost side, the implementation is handled as follows:

  • The BS control is dispatched to the existing CursorBackward method, with a distance of 1.
  • The TAB control is dispatched to the existing ForwardTab method, with a tab count of 1.
  • The CR control required a new dispatch method, but the implementation was a simple call to the new _CursorMovePosition method from PR #3628.
  • The BEL control also required a new dispatch method, as well as an additional private API in the ConGetSet interface. But that's mostly boilerplate code - ultimately it just calls the SendNotifyBeep method.

On the Windows Terminal side, not all dispatch methods are implemented.

  • There is an existing CursorBackward implementation, so BS works OK.
  • There isn't a ForwardTab implementation, but TAB isn't currently required by the conpty protocol.
  • I had to implement the CarriageReturn dispatch method, but that was a simple call to Terminal::SetCursorPosition.
  • The WarningBell method I've left unimplemented, because that functionality wasn't previously supported anyway, and there's an existing issue for that (#4046).

Validation Steps Performed

I've added a state machine test to confirm that the updated control characters are now forwarded to the appropriate dispatch handlers. But since the actual implementation is mostly relying on existing functionality, I'm assuming that code is already adequately tested elsewhere. That said, I have also run various manual tests of my own, and confirmed that everything still worked as well as before.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/4171 **Author:** [@j4james](https://github.com/j4james) **Created:** 1/9/2020 **Status:** ✅ Merged **Merged:** 1/17/2020 **Merged by:** [@DHowett-MSFT](https://github.com/DHowett-MSFT) **Base:** `master` ← **Head:** `move-vt-control-chars` --- ### 📝 Commits (6) - [`a10cef7`](https://github.com/microsoft/terminal/commit/a10cef7d47cce2eef0409c6e969c92582f3d7367) Add a CarriageReturn method to the ITermDispatch interface to handle the CR control character. - [`eee8e5e`](https://github.com/microsoft/terminal/commit/eee8e5eecd4f7f03bb3f354da5b74ad5121a073d) Add a private ConGetSet API and a corresponding ITermDispatch method to handle the BEL control character. - [`b78c62c`](https://github.com/microsoft/terminal/commit/b78c62c3429943092a1aa300b9a13b29179b289d) Handle the BEL, BS, TAB, and CR control characters in the OutputStateMachine. - [`07e2cd5`](https://github.com/microsoft/terminal/commit/07e2cd56b500520172a8e3db0c27c3c895ace42e) Add a state machine test to confirm the control characters are dispatched correctly. - [`db89428`](https://github.com/microsoft/terminal/commit/db894283e119b51f469118246638c962e0a5d9e9) Merge branch 'master' into move-vt-control-chars - [`a47b0f1`](https://github.com/microsoft/terminal/commit/a47b0f123ab03c34ccf845fcfe5525ebfebcaf9e) Update CarriageReturn implementation to use the new _CursorMovePosition method. ### 📊 Changes **12 files changed** (+141 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/TerminalCore/TerminalDispatch.cpp` (+8 -0) 📝 `src/cascadia/TerminalCore/TerminalDispatch.hpp` (+1 -0) 📝 `src/host/outputStream.cpp` (+9 -0) 📝 `src/host/outputStream.hpp` (+2 -0) 📝 `src/terminal/adapter/ITermDispatch.hpp` (+2 -0) 📝 `src/terminal/adapter/adaptDispatch.cpp` (+24 -0) 📝 `src/terminal/adapter/adaptDispatch.hpp` (+2 -0) 📝 `src/terminal/adapter/conGetSet.hpp` (+1 -0) 📝 `src/terminal/adapter/termDispatch.hpp` (+2 -0) 📝 `src/terminal/adapter/ut_adapter/adapterTest.cpp` (+7 -0) 📝 `src/terminal/parser/OutputStateMachineEngine.cpp` (+18 -10) 📝 `src/terminal/parser/ut_parser/OutputEngineTest.cpp` (+65 -0) </details> ### 📄 Description ## Summary of the Pull Request This PR moves the handling of the `BEL`, `BS`, `TAB`, and `CR` controls characters into the state machine (when in VT mode), instead of forwarding them on to the default string writer, which would otherwise have to parse them out all over again. This doesn't cover all the control characters, but `ESC`, `SUB`, and `CAN` are already an integral part of the `StateMachine` itself; `NUL` is filtered out by the `OutputStateMachineEngine`; and `LF`, `FF`, and `VT` are due to be implemented as part of PR #3271. Once all of these controls are handled at the state machine level, we can strip out all the VT-specific code from the `WriteCharsLegacy` function, which should simplify it considerably. This would also let us simplify the `Terminal::_WriteBuffer` implementation, and the planned replacement stream writer for issue #780. ## References #3271, #780, #3628, #4046 ## PR Checklist * [ ] Closes #xxx * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [x] Tests added/passed * [ ] Requires documentation to be updated * [x] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: https://github.com/microsoft/terminal/issues/780#issuecomment-570287435 ## Detailed Description of the Pull Request / Additional comments On the conhost side, the implementation is handled as follows: * The `BS` control is dispatched to the existing `CursorBackward` method, with a distance of 1. * The `TAB` control is dispatched to the existing `ForwardTab` method, with a tab count of 1. * The `CR` control required a new dispatch method, but the implementation was a simple call to the new `_CursorMovePosition` method from PR #3628. * The `BEL` control also required a new dispatch method, as well as an additional private API in the `ConGetSet` interface. But that's mostly boilerplate code - ultimately it just calls the `SendNotifyBeep` method. On the Windows Terminal side, not all dispatch methods are implemented. * There is an existing `CursorBackward` implementation, so `BS` works OK. * There isn't a `ForwardTab` implementation, but `TAB` isn't currently required by the conpty protocol. * I had to implement the `CarriageReturn` dispatch method, but that was a simple call to `Terminal::SetCursorPosition`. * The `WarningBell` method I've left unimplemented, because that functionality wasn't previously supported anyway, and there's an existing issue for that (#4046). ## Validation Steps Performed I've added a state machine test to confirm that the updated control characters are now forwarded to the appropriate dispatch handlers. But since the actual implementation is mostly relying on existing functionality, I'm assuming that code is already adequately tested elsewhere. That said, I have also run various manual tests of my own, and confirmed that everything still worked as well as before. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:11:01 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#25672