You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
click.secho(, color=True) is supposed to preserve text coloring despite writing to a pipe. This works correctly on Mac (colors are preserved) but not on Windows the colors are stripped.
To reproduce:
Save the two files below in a directory and run python parent.py. The parent job will launch the child job which will output to the stdout pipe colored text. The parent jobs echoes that text and it should be colored (green).
File child.py
import click
import sys
# A message with color info.
msg = click.style("GREEN", fg="green")
# Dump message to stderr. This bypasses the parent job.
msg_hex = " ".join("{:02x}".format(ord(c)) for c in msg)
print(f"[CHILD ] Sending (as hex): [{msg_hex}]", file=sys.stderr)
# Write to stdout. Should be send to the parent via pipe while
# preserving the coloring.
# * reset=False prevents appending color off sequence.
# * nl="" prevents append EOL char.
click.secho(msg, color=True, reset=False, nl="")
File parent.py
import subprocess, time, os, sys
# Run the child process.
child = subprocess.Popen(["python", "child.py"],
stdout=subprocess.PIPE,
stderr=None)
# Dump the captured stdout.
for line in iter(child.stdout.readline, b''):
# Dump line as hex.
hex_dump = " ".join("{:02x}".format(c) for c in line)
print(f"[PARENT] recieved (as hex): [{hex_dump}]")
# Dump line as text. Should print colored text.
str = line.decode("utf-8")
print(f"[PARENT] recieved (as str): {str}")
Expected abehavior:
On Mac the behavior is correct and the text that the parent echoes from the pipe is colored.
Actual behavior:
On windows, however, the ansi colors are stripped (see the shorter hex string) and the output text is not colored.
Environment:
Python version: 3.12.0
Click version: 8.1.7
The text was updated successfully, but these errors were encountered:
Summary:
click.secho(, color=True)
is supposed to preserve text coloring despite writing to a pipe. This works correctly on Mac (colors are preserved) but not on Windows the colors are stripped.To reproduce:
Save the two files below in a directory and run
python parent.py
. The parent job will launch the child job which will output to the stdout pipe colored text. The parent jobs echoes that text and it should be colored (green).File child.py
File parent.py
Expected abehavior:
On Mac the behavior is correct and the text that the parent echoes from the pipe is colored.
Actual behavior:
On windows, however, the ansi colors are stripped (see the shorter hex string) and the output text is not colored.
Environment:
The text was updated successfully, but these errors were encountered: