-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Corrupted output on Windows 10 and Windows 11 #160
Comments
I no longer have access to a Windows 10 machine. (This is not a problem with Command Prompt on Windows 11.) Is this also a problem in Windows Terminal (Microsoft's replacement for Command Prompt, including for Windows 10 22H2 - https://apps.microsoft.com/detail/9N0DX20HK701?rtc=1&hl=en-gb&gl=GB)? I suspect the problem may be that, on Windows 10 22H2, Microsoft does not enable Console Virtual Terminal Sequences in Command Prompt 'by default'; I need to do some research. ChatGPT suggests there is a registry setting that can be changed so that it is 'turned on'; again, I need to reseach if that suggestion is reliable. |
Thanks @mpilgrem! Asking a tester to test an |
There is a long discussion here about the Command Prompt problem and the 'registry setting' fix is in the comment that I have linked: microsoft/WSL#1173 (comment). In short, the history is:
As I understand it, changing the registry setting makes it ANSI-capable AND ANSI-enabled by default. You probably have a good reason for using Command Prompt but, in case you are not wedded to it, I strongly recommend switching to Windows Terminal. |
The changed behaviour with |
Was Win 10 with the default terminal intentionally dropped as legacy in 1.0? I feel it is a tricky situation. It is Microsoft's fault as the behaviour is not backwards compatible and is changed on Windows 11, but there is also a registry key that you can set to get the old behaviour back. So even on Windows 11, you may need to support the older terminal type. I am not a Windows users, but fiddling with the registry seems a global system modification. I don't think I can ask in good conscience the player — this is a game — to make global modifications just to try my game. This is an even more pressing matter for the less frivolous applications that rely on |
An alternative to enabling the functionality through the registry is to do it in code: module Main where
import System.Console.ANSI
import Data.Bits ( (.|.) )
import System.IO ( stdout )
-- From Win32 package:
import System.Win32.Console
( eNABLE_VIRTUAL_TERMINAL_PROCESSING, getConsoleMode, setConsoleMode )
import System.Win32.Types ( withHandleToHANDLE )
main :: IO ()
main = do
-- Using Command Prompt on Windows where VT processing may not be enabled by default
enableVTProcessing
setSGR [SetColor Foreground Vivid Red]
putStrLn "This text is in Red."
setSGR [Reset]
putStrLn "This text is in default colour."
enableVTProcessing :: IO ()
enableVTProcessing = do
withHandleToHANDLE stdout $ \h -> do
currentMode <- getConsoleMode h
let newMode = currentMode .|. eNABLE_VIRTUAL_TERMINAL_PROCESSING
setConsoleMode h newMode |
Command Prompt on Windows 11 is, I think, ANSI-enabled by default. You are correct that Command Prompt is, formally, the 'default' terminal on Windows 10 but, de facto, Microsoft has, essentially, dropped Command Prompt for Windows Terminal and moved on from its non-ANSI history. The shift to If there is demand, I will continue to try to 'patch' the |
Matt, you — and @UnkindPartition, and Max — have done a tremendous job on What I see here with So yes, my feeling is: yes, this is a regression. Microsoft pulled a fast one on the maintainers. Do you happen to know whether |
Unfortunately that's is not the case, at least in build 22621.2428:
|
@torgeirsh, may I clarify: are you using Command Prompt on Windows 11 outside of a Windows Terminal tab? |
It's the older one (Conhost?), not Windows Terminal. |
Also, in Windows Terminal and ConHost terminals, `hSupportsANSI` will yield `False` if the the processing of \'ANSI\' control characters in output is not enabled. Also makes deprecated `hSupportsANSIWithoutEmulation` consistent with `hNowSupportsANSI`.
Also, in Windows Terminal and ConHost terminals, `hSupportsANSI` will yield `False` if the the processing of \'ANSI\' control characters in output is not enabled. Also makes deprecated `hSupportsANSIWithoutEmulation` consistent with `hNowSupportsANSI`.
@ffaf1, @torgeirsh, #164 makes some additions to allow support of Windows users who use ConHost directly, rather than use Windows Terminal. Specifically, it adds module Main where
import System.IO (stdout)
import System.Console.ANSI
main :: IO ()
main = do
stdoutSupportsANSI <- hNowSupportsANSI stdout
if stdoutSupportsANSI
then -- do certain ANSI-related things
else -- do something else I think this can be released as a minor version bump, given the nature of the changes. |
Hello @mpilgrem, sorry to have taken this long to review this. I would like to test this with my Windows tester, can I assure him the exe I send does not make any permanent changes (registry, etc.)? |
@ffaf1, in fact, a Stack issue caused me to issue this as |
That's great! Stack was how I ran into it myself, I'm not a user of the library. |
From my trusted Win tester:
To reproduce
Output
System
ansi-terminal >= 1.0 && < 1.1
Additional informations
ansi-terminal >=0.11 && <0.12
, so this is a regression.The text was updated successfully, but these errors were encountered: