-
-
Notifications
You must be signed in to change notification settings - Fork 255
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
Support for Windows 10 built-in ANSI cmd #104
Comments
Helo @Slayther. Is colorama broken on Windows 10 cmd, or do both coloring methods (ANSI codes and API calls) work? The decision about whether to strip and/or convert ANSI codes is in ansitowin32.py (currently lines 74 and 79). It would be great if you could submit a pull request. Otherwise please specify how to check for Windows 10 ANSI code support here. Thanks! |
Well, both ANSI codes and API calls work on new Windows 10 cmd. I thought I saw the dim option working on the new cmd, but I was mistaken once I commented out both ANSI stripping and API calls. Everything else works as expected on Windows. Nevertheless, if Windows updates support for ANSI sequences, it would be good to support those right away. I will submit the pull request shortly, once I test some stuff out. |
Fixed with #105. |
While simple test runs of colorama works well on the new Windows 10 cmd, more complex usage of colorama breaks. E.g. calling py.test works well, calling py.test with a specific file gives broken colors, sometimes even with black text on black background (also, Ctrl+C leaves console in whatever color state it was in when exception occurred). Other applications which use colorama also act strange. I unfortunately don't know enough about how colorama works to create a minimal working example. But yeah, +1 from me on getting a fix in :) |
As colorama is broken in many cases for me on Windows 10, and the submitted PR is still open, I would propose to reopen this issue. |
I did not check the PR as this was a temporary fix before I started using the key codes themselves. @wiggin15 As the build is passing and the feature is proven to work, could you pull the request? |
@vidartf it would be very helpful if you can produce minimal test cases anyway so we can find exactly what is broken. The behavior on Windows 10 should not be different than the behavior on other Windows versions if using the API for color conversion. I think if we can leave things the way they are without adding detection for Windows 10 it would be better. |
Hi @vidartf thank you for providing this example.
import colorama
colorama.init()
print("Some test output here")
print(colorama.Style.BRIGHT + "Some test output here" + colorama.Style.RESET_ALL)
print("Some test output here")
|
Answer point by point:
Adding
Moving the import fixes this (gives colors as expected). As such, I think you might be right that this is not a Win10 issue, but rather that the consequences on win 10 are different from other windows versions. As extra information:
|
@vidartf thanks for the explanation. I understand. Further testing is needed to determine exactly what is wrong with the conversion on Windows 10. |
Note: If importing colorama when stdout is captured by FDs, and In other words, the following code will set terminal colors to black on black: import sys
import os
from tempfile import TemporaryFile
# Capture stdout using file descriptors
stdoutfd = 1
saved_fd = os.dup(stdoutfd)
f = TemporaryFile()
os.dup2(f.fileno(), stdoutfd)
# Import colorama with captured stdout
import colorama
colorama.init()
# Restore stdout
os.dup2(saved_fd, stdoutfd)
os.close(saved_fd)
f.close() |
The issue lies in self._default = win32.GetConsoleScreenBufferInfo(win32.STDOUT).wAttributes This default value gets set to 0 when stdoutfd is set to the TemporaryFile's fd. This later causes the RESET_ALL in the example, and at the end of the program (init installs an atexit hook to call reset all) to set the console's properties "back" to 0 (black on black). |
Not sure if this only happens on Windows 10 (that's the only one I got available). Py.test only uses this type of redirection at limited points during import (or when explicitly asked by the test code). Do you see a reasonable workaround for this? |
I was going to add an issue, but maybe should just add my thoughts on this issue. We need init() to have an option to not use the class wrapper, but behave the same as if it was on Linux. GIven the modern terminal setup on windows supports this by default, this is a better way to go forward and will allow certain combinations to work as strip=True on the init function to work so I can control if I want to suppress color output ( which is current broken on windows) when using colorama |
This issue has hopefully been addressed in a way that keeps everyone happy by the recent merging of a new alternative to 'init', called 'just_fix_windows_console', which is now described in the README as the preferred way to use Colorama for most users. This retains the existing complex idiocyncratic behavior of 'init' for those who rely on it being the way it is. |
Windows 10 has built-in support for ANSI cmd. The ANSI codes should not be stripped.
The module should check for this. I know how to, but I don't know where to put this check..
The text was updated successfully, but these errors were encountered: