Add ANSI support for legacy (pre-win10) Windows environments. - #446
Open
scobei wants to merge 8 commits into
Open
Add ANSI support for legacy (pre-win10) Windows environments.#446scobei wants to merge 8 commits into
scobei wants to merge 8 commits into
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Contributor
Author
|
I've tried to fix the various failing checks, but have hit a wall. cpp-linter says all jobs have failed and I can't figure out what I can do to fix it. I'm kinda new to the PR game. Not sure where to go from here. |
scobei
marked this pull request as ready for review
August 4, 2026 20:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #173.
This PR provides ANSI support for legacy Windows consoles, which don't offer it natively.
It works by extracting ANSI sequences from data written to output streams and making calls
to Win32 console API methods to execute the intent of those sequences.
Implementation Overview
Output Streams
The
Term:cxxfamily of output streams automatically provide ANSI support if a legacy Windowsconsole is detected and the terminal option
Term::Option::NoLegacyWindowsSupporthasnot been set.
The
std::cxxstreams are not affected by default. If ANSI support for those streams is desired,a
WinConsoleAdapterobject can be constructed for each of the streams ANSI support is tobe provided.
WinConsoleAdapterdoes nothing if it's constructed in a non-Windows legacyenvironment.
Parsing
Parsing is done with a state machine that's design is based on Paul Flo Williams's excellent
VT500-Series parser state diagram (https://vt100.net/emu/dec_ansi_parser). As sequences are
identified, they are either returned via a callback or added to a collection to be returned
when all the available characters have been parsed.
Processing
The sequences are passed to a
VtEmulator, where text and simple C0 and C1 sequences arewritten to the console. Command sequences are converted into
VtCommandobjects whichare then passed to command-specific handlers for further processing. Finally, the appropriate
API calls are made.
Error Reporting
Any errors that occur are silently ignored unless error reporting has been enabled. Errors
include sequences that are malformed or otherwise invalid, Win32 API failures and any
other unexpected runtime errors. If error reporting has been enabled an error message is
printed to the console.
To enable error reporting, issue the custom sequence
CSI ? 3210hto the stream that itis to be enabled on. To disable, issue the sequence
CSI ? 3210l.Testing
Testability was a big consideration in the design. Tests have been written for every element,
except for, of course, the Win32 functions.
Screenshots
Below are a number of screenshots of example programs running on a Windows 7 (version 6.1.7601)






virtual machine.