Linux - clock doesn't show colors via ssh
I have a simple python script that prints text with color using colorama .
test.py
#!/usr/bin/env python
from colorama import Fore
text = "Test"
print(Fore.RED + text)
The problem is when I try to put it in a command watch
when connecting via SSH , it doesn't display colors.
when connecting via SSH I run
watch -c test.py
And it doesn't display colors.
I searched a lot about this issue, but watch
through SSH
for some reason won't display colors. (also when using a flag -c
).
What is the problem?
EDIT:
Another question asked that reproduces the issue - linux - view command not displaying colors via ssh
source to share
Update: Following the comment by William Russell. I looked a little at the repama colorama github and found the init () parameterwrap
Speaking colorama to act like stdout is not wrapped in a call init(wrap=False)
:
test.py
# !/usr/bin/env python
import colorama
from colorama import Fore
colorama.init(wrap=False)
text = "Test"
print(Fore.RED + text)
you also get the correct colors inside the watch command.
Update 2: For colors over ssh in general, see How do I get a colored terminal over ssh?
Original answer:
Ok, I don't know why, but when I remove colorama.init()
it works:
test.py
#!/usr/bin/env python
from colorama import Fore
text = "Test"
print(Fore.RED + text)
Called with watch -c test.py
leads to red "Test" ...
I copied their sample from the python package index and forgot init()
and surprised that I got a colored oO output
source to share