Skip to content
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

"Side effect" of demo code #389

Open
aamrun opened this issue Apr 19, 2024 · 1 comment
Open

"Side effect" of demo code #389

aamrun opened this issue Apr 19, 2024 · 1 comment

Comments

@aamrun
Copy link

aamrun commented Apr 19, 2024

I came across your project while browsing the packages installed on my system ( Ubuntu 22.04 running as WSL on Windows 11). I ran the demo code below which is mentioned both on your PyPi and Github homepages :

from colorama import Fore, Back, Style
print(Fore.RED + 'some red text')
print(Back.GREEN + 'and with a green background')
print(Style.DIM + 'and in dim text')
print(Style.RESET_ALL)
print('back to normal now')

Doing so, I got the output below :

image

As can be seen, not only the line with the text containing 'green background' but the two following lines also have a green background. It's interesting that the 'green background' line is green only for the sentence but the two subsequent lines are green for the entire screen width.

I don't know if this is the intended effect but it looked like a bug to me and I came up with this 'fix' :

from colorama import Fore, Back, Style
print(Fore.RED + 'some red text')
print(Back.GREEN + 'and with a green background' + Back.RESET)
print(Style.DIM + 'and in dim text')
print(Style.RESET_ALL)
print('back to normal now')

Now the output looks like this :

image

Also, because a Fore.RESET hasn't been applied on the first line, the 'green background' text is in red and the 'dim text' is really dim, especially on a black background. With this line :

print(Fore.RED + 'some red text' + Fore.RESET)

The output looks more 'proper'

image

Again, not sure if the current code is intended to work "as it is" or if this 'issue' has been reported in the past. I came across it and thought of letting you know.

Thanks !

@ken-morel
Copy link

Actually, when you pring a newline( '\n'), on the console with specific styling set, the stylings or in this case background should apply on the rest of the line. I have already tested and resolved that issue when working using C and win32 system calls. Actually appending the reset resets the styling before the newline is printed.

That should not be a bug with colorama.

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

No branches or pull requests

2 participants