Skip to content

Add ANSI support for legacy (pre-win10) Windows environments. - #446

Open
scobei wants to merge 8 commits into
jupyter-xeus:masterfrom
scobei:feature/support-pre-win10
Open

Add ANSI support for legacy (pre-win10) Windows environments.#446
scobei wants to merge 8 commits into
jupyter-xeus:masterfrom
scobei:feature/support-pre-win10

Conversation

@scobei

@scobei scobei commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

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:cxx family of output streams automatically provide ANSI support if a legacy Windows
console is detected and the terminal option Term::Option::NoLegacyWindowsSupport has
not been set.

The std::cxx streams are not affected by default. If ANSI support for those streams is desired,
a WinConsoleAdapter object can be constructed for each of the streams ANSI support is to
be provided. WinConsoleAdapter does nothing if it's constructed in a non-Windows legacy
environment.

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 are
written to the console. Command sequences are converted into VtCommand objects which
are 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 ? 3210h to the stream that it
is 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.
win7_colors
win7_keys
win7_kilo
win7_legacy_support
win7_menu
win7_styles

@scobei

scobei commented Aug 4, 2026

Copy link
Copy Markdown
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
scobei marked this pull request as ready for review August 4, 2026 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support older Windows versions anyway :-P

1 participant