[PR #12277] [MERGED] Simplify the IStateMachineEngine interface #28945

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/12277
Author: @j4james
Created: 1/28/2022
Status: Merged
Merged: 1/28/2022
Merged by: @undefined

Base: mainHead: simplify-statemachine-engines


📝 Commits (2)

  • b56c938 Use bool field to control input-specific behaviour in the state machine.
  • 02dd383 Removed unused methods in the state machine engines.

📊 Changes

8 files changed (+22 additions, -130 deletions)

View changed files

📝 src/terminal/parser/IStateMachineEngine.hpp (+0 -5)
📝 src/terminal/parser/InputStateMachineEngine.cpp (+0 -52)
📝 src/terminal/parser/InputStateMachineEngine.hpp (+0 -5)
📝 src/terminal/parser/OutputStateMachineEngine.cpp (+0 -51)
📝 src/terminal/parser/OutputStateMachineEngine.hpp (+0 -5)
📝 src/terminal/parser/stateMachine.cpp (+15 -6)
📝 src/terminal/parser/stateMachine.hpp (+7 -1)
📝 src/terminal/parser/ut_parser/StateMachineTest.cpp (+0 -5)

📄 Description

There were a number of methods in the IStateMachineEngine interface
which controlled how the StateMachine interpreted escape sequences.
But essentially what it came down to was a bunch of a properties that
were always true for the InputStateMachineEngine, and always false for
the OutputStateMachine engine. To simplify the implementation, and
make things a little more efficient, I've now replaced all of those
virtual calls with a single boolean field in the StateMachine that is
initialised in the constructor.

I started by adding an isEngineForInput parameter to the constructor
to indicate the the type of engine being passed in. But to keep things
simple for callers, and I also then added a constructor without that
parameter, which could derive the value automatically based on the type
of the engine pointer.

Then in the StateMachine implementation, anywhere we were previously
calling ParseControlSequenceAfterSs3, FlushAtEndOfString,
DispatchControlCharsFromEscape, or DispatchIntermediatesFromEscape,
we now just reference _isEngineForInput. But I've also copied across
some of the original comments from those methods, to make it clear at
the point of usage why we have a difference in behavior for input and
output.

To make sure the unit tests would catch any problems, I hardcoded the
_isEngineForInput field to false, and confirmed that it broke a
bunch of input engine tests. Then I hardcoded it to true, and
confirmed that it broke a bunch of state machine and output engine
tests. With the _isEngineForInput set correctly, everything passed.

I also manually tested the various output edge cases that would be
effected by this code - C0 controls within an escape sequence, time
delays in the middle of an escape sequence, SCS character set
selection which requires intermediates following an escape, and a G3
single shift select which depends on SS3.

Closes #12254


🔄 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/12277 **Author:** [@j4james](https://github.com/j4james) **Created:** 1/28/2022 **Status:** ✅ Merged **Merged:** 1/28/2022 **Merged by:** [@undefined](undefined) **Base:** `main` ← **Head:** `simplify-statemachine-engines` --- ### 📝 Commits (2) - [`b56c938`](https://github.com/microsoft/terminal/commit/b56c938fa89664f777aa4b5455af7ea33766e3ca) Use bool field to control input-specific behaviour in the state machine. - [`02dd383`](https://github.com/microsoft/terminal/commit/02dd383c51dc86090dd031c4e1aeb88d4e9d207b) Removed unused methods in the state machine engines. ### 📊 Changes **8 files changed** (+22 additions, -130 deletions) <details> <summary>View changed files</summary> 📝 `src/terminal/parser/IStateMachineEngine.hpp` (+0 -5) 📝 `src/terminal/parser/InputStateMachineEngine.cpp` (+0 -52) 📝 `src/terminal/parser/InputStateMachineEngine.hpp` (+0 -5) 📝 `src/terminal/parser/OutputStateMachineEngine.cpp` (+0 -51) 📝 `src/terminal/parser/OutputStateMachineEngine.hpp` (+0 -5) 📝 `src/terminal/parser/stateMachine.cpp` (+15 -6) 📝 `src/terminal/parser/stateMachine.hpp` (+7 -1) 📝 `src/terminal/parser/ut_parser/StateMachineTest.cpp` (+0 -5) </details> ### 📄 Description There were a number of methods in the `IStateMachineEngine` interface which controlled how the `StateMachine` interpreted escape sequences. But essentially what it came down to was a bunch of a properties that were always true for the `InputStateMachineEngine`, and always false for the `OutputStateMachine` engine. To simplify the implementation, and make things a little more efficient, I've now replaced all of those virtual calls with a single boolean field in the `StateMachine` that is initialised in the constructor. I started by adding an `isEngineForInput` parameter to the constructor to indicate the the type of engine being passed in. But to keep things simple for callers, and I also then added a constructor without that parameter, which could derive the value automatically based on the type of the engine pointer. Then in the `StateMachine` implementation, anywhere we were previously calling `ParseControlSequenceAfterSs3`, `FlushAtEndOfString`, `DispatchControlCharsFromEscape`, or `DispatchIntermediatesFromEscape`, we now just reference `_isEngineForInput`. But I've also copied across some of the original comments from those methods, to make it clear at the point of usage why we have a difference in behavior for input and output. To make sure the unit tests would catch any problems, I hardcoded the `_isEngineForInput` field to `false`, and confirmed that it broke a bunch of input engine tests. Then I hardcoded it to `true`, and confirmed that it broke a bunch of state machine and output engine tests. With the `_isEngineForInput` set correctly, everything passed. I also manually tested the various output edge cases that would be effected by this code - C0 controls within an escape sequence, time delays in the middle of an escape sequence, `SCS` character set selection which requires intermediates following an escape, and a G3 single shift select which depends on `SS3`. Closes #12254 --- <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:31:48 +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#28945