Hi! Windows Console Subsystem maintainer here :)
is_windows_10 is documented implying that you cannot use ENABLE_VIRTUAL_TERMINAL_PROCESSING without first checking that you're on Windows 10, and goes to great lengths to explain how versioning is handled.
None of that is strictly necessary! If you call SetConsoleMode(..., ENABLE_VIRTUAL_TERMINAL_PROCESSING) and the console host does not support it, regardless of the version of Windows, it will give you a status code and ignore you.
I know we haven't made this very easily discoverable. Sorry :/.
That means you can collapse all your version checking logic into "does the console host support VT processing?" In so doing, you get is_microsoft_terminal for free (since it does support VT processing) and the handful of custom console hosts that exist for Windows 8 which also support VT processing. You can collapse every micosoft_terminal and Windows case to "get mode, check VT_PROCESSING, try to set it, bail out1 if it's rejected."
To put a finer point on it... here's a console on Windows 8.1 displaying Sixels, a nominally "Windows 11+" feature which requires VIRTUAL_TERMINAL_PROCESSING (side by side with one that doesn't support that mode!)

Hi! Windows Console Subsystem maintainer here :)
is_windows_10is documented implying that you cannot useENABLE_VIRTUAL_TERMINAL_PROCESSINGwithout first checking that you're on Windows 10, and goes to great lengths to explain how versioning is handled.None of that is strictly necessary! If you call
SetConsoleMode(..., ENABLE_VIRTUAL_TERMINAL_PROCESSING)and the console host does not support it, regardless of the version of Windows, it will give you a status code and ignore you.I know we haven't made this very easily discoverable. Sorry :/.
That means you can collapse all your version checking logic into "does the console host support VT processing?" In so doing, you get
is_microsoft_terminalfor free (since it does support VT processing) and the handful of custom console hosts that exist for Windows 8 which also support VT processing. You can collapse everymicosoft_terminalandWindowscase to "get mode, checkVT_PROCESSING, try to set it, bail out1 if it's rejected."To put a finer point on it... here's a console on Windows 8.1 displaying Sixels, a nominally "Windows 11+" feature which requires
VIRTUAL_TERMINAL_PROCESSING(side by side with one that doesn't support that mode!)Footnotes
bail out and do it the legacy way, FWIW. ↩