-
Notifications
You must be signed in to change notification settings - Fork 184
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
bug: Importing colors
from plumbum
adds a trailing line to the output
#659
Comments
Testing all values, and printing with for value in -1 0 1 2 3 4 5 "" yes no; do
FORCE_COLOR="${value}" python colors_with_plumbum.py > fc$value.txt
done % for fc in fc*; do echo $fc:; cat -v $fc; echo; done
fc0.txt:
^[[1;32mHello^[[0m
fc-1.txt:
^[[1;32mHello^[[0m
fc1.txt:
^[[1;32mHello^[[0m
^[[0m
fc2.txt:
^[[1;32mHello^[[0m
^[[0m
fc3.txt:
^[[1;32mHello^[[0m
^[[0m
fc4.txt:
^[[1;32mHello^[[0m
^[[0m
fc5.txt:
^[[1;32mHello^[[0m
fcno.txt:
^[[1;32mHello^[[0m
fc.txt:
^[[1;32mHello^[[0m
fcyes.txt:
^[[1;32mHello^[[0m |
Hmmm, this is caused by |
I was really worried about breaking prompts, but I think that's not as bad these days. In 3.13 Python will even fix the REPL for you if color leaks. Maybe we can remove it and have an opt-in function that adds the protection instead. |
That would be great @henryiii, thanks 🙂 |
It seems like merely importing
colors
fromplumbum
while settingFORCE_COLOR
to supported values 1, 2, 3 and 4 adds a new line to a Python script output. Any other value (0, 5, 6, -1, "", "hello") do not trigger this behavior.The
%
comes from my Zsh prompt. If we redirect the output to a file and open it, here are the contents:Without the Plumbum import, contents are:
So actually, rather than a newline, it seems to append a reset sequence. Now that the line is not empty, cat displays it. It has no newline character at the end so my prompt is directly printed after it.
The text was updated successfully, but these errors were encountered: