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
Colors STOPPED showing in Windows 10, latest update. #265
Comments
on windows10 with python35, As colorama has never worled for me, I installed color. |
ah! so it works fine on the windows console. I was naively expecting it to also work on print() output. |
It works, but not quite fine. The "Hello, Red" colour for example should be produced by 41, not 31. 31 should give the colour in the second set of output. Also reverse and underline don't render. |
"but I'm sure I would have noticed reverse not working" Reverse and underline don't render in either of those operating systems. The correct colours are being used though - 31 for Red produces the normal intensity red. Windows 8.1 gave the same results. The documentation doesn't list underscore and reverse video as supported escape sequences, but the normal colour sequences (eg ESC [ 31 m for red) shouldn't produce high intensity. It looks like that happened because the Windows 10 console was using a bright colour for the foreground. |
I've been playing around with colorama, and have got behaviour that I believe is more consistent with Linux. This code: import colorama
# import platform
#
# if platform.system() == "Windows":
# import ctypes
# kernel32 = ctypes.windll.kernel32
# kernel32.SetConsoleMode(kernel32.GetStdHandle(-11), 7)
# Some ANSI escape sequences for colours and effects
BLACK = '\u001b[30m'
RED = '\u001b[31m'
GREEN = '\u001b[32m'
YELLOW = '\u001b[33m'
BLUE = '\u001b[34m'
MAGENTA = '\u001b[35m'
CYAN = '\u001b[36m'
WHITE = '\u001b[37m'
RESET = '\u001b[0m'
LIGHT_GREEN = '\u001b[92m'
BOLD = '\u001b[1m'
BOLD_OFF = '\u001b[21m'
NORMAL = '\u001b[22m'
UNDERLINE = '\u001b[4m'
UNDERLINE_OFF = '\u001b[24m'
REVERSE = '\u001b[7m'
REVERSE_OFF = '\u001b[27m'
def colour_print(text: str, *effects: str) -> None:
"""
Print `text` using the ANSI sequences to change colour, etc.
:param text: The text to print.
:param effects: The effects we want. Zero or more of the constants
defined at the start of this module.
"""
effect_string = "".join(effects)
output_string = "{0}{1}{2}".format(effect_string, text, RESET)
print(output_string)
colorama.init(strip=False)
colour_print("Hello, Red", RED)
colour_print("Hello, Red in bold", RED, BOLD)
# test that the colour was reset
print("This should be in the default terminal colour")
colour_print("Hello, Green", GREEN)
colour_print("Hello, Green reversed", GREEN, REVERSE)
print()
colour_print("Hello, Green bold and underlined", BOLD, UNDERLINE, GREEN)
print()
colour_print("Hello, Yellow", YELLOW)
colour_print("Hello, Yellow bold", YELLOW, BOLD)
colour_print("Hello, green", GREEN)
colour_print("Hello, light green", LIGHT_GREEN)
colour_print("Hello, bold green", GREEN, BOLD)
colour_print("Hello, bold green reversed", GREEN, BOLD, REVERSE)
colour_print("Hello, green reversed", GREEN, REVERSE)
colour_print("Hello, Bold", BOLD)
colour_print("Hello, Underline", UNDERLINE)
colour_print("Hello, Reverse", REVERSE)
colour_print("Hello, Reverse and Underline", REVERSE, UNDERLINE)
colour_print("Hello, Reverse", REVERSE)
colour_print("Hello, Black", BLACK)
print("{}Reversed{}NotReversed".format(REVERSE, REVERSE_OFF))
print("{}bold{}Reversed{}Not Reversed{}underlined{}not bold{}not underlined".format(BOLD, REVERSE, REVERSE_OFF, UNDERLINE, BOLD_OFF, UNDERLINE_OFF))
colorama.deinit() Produces this output, on a console with a bright foreground and background. It also works fine with normal fore/background. I also added support for reverse video and underlining (not under Windows 8 though). Edited to remove silly question. This is my first time contributing to an open-source project. |
Even without Colorama, I get the handle but kernel32.GetConsoleMode() returns 0. Latest Windows 10 and all the packages. Similar code in C/C++ renders as it should (https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences) |
What Python code are you running? |
this works in Python Interactive window in Visual Studio 2019 but not in Python Console:
|
Now something like this, works just fine in Windows 10. This is C++ and no Colorama:
|
I may have figured it out (Maybe). I have Python 2.7, 3.4, 3.6 on my Windows10 machine. |
Just in case it's causing confusion, in my comment that "I've been playing around with colorama" from 9 days ago, I meant that I'd been modifying the colorama source code. The current version of colorama doesn't produce reverse video and underlining on Windows. |
The solution only needs one line of code: |
Hi, Xyndra |
Yeah, but I think that´s the most you can get in cmd.😔 |
If my PR makes it into the next release, you'll be able to get the effects in the screenshot above (my last post on 5th July). |
Colors STOPPED showing in Windows 10, latest update. Still work in Ubuntu. Same code.
This is my latest windows update https://support.microsoft.com/en-us/help/4549951/windows-10-update-kb4549951
Thank you!
The text was updated successfully, but these errors were encountered: