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

[Feature Request] Allow to to emit colored click.secho() text to a pipeline. #2781

Open
zapta opened this issue Sep 27, 2024 · 0 comments
Open

Comments

@zapta
Copy link

zapta commented Sep 27, 2024

Currently click.secho() strips the color information when the output stream is a pipe and not a terminal. With this feature, it will be possible to force click.secho() to preserve the colors even if writing to a pipe. This can be done at several levels and each one of them should work. For example having the functions below, at a global or per stream level. This will allow the parent process to pass the color policy to the subprocess via command line args.

enum ColorPolicy = ALLWAYS_KEEP | ALLWAYS_STRIP | AUTO

# Used at child process.
click.set_color_policy(color_policy:  ColorPolicy)

# Used at parent process.
click.get_color_policy() -> ColorPolicy                    

We have a python program that runs a scons script as a subprocess, captures it's stdout pipe, and sends it to a terminal. When we use ``click.secho() in the subprocess, the colors are removed. This result with the non desire outcome that some our output is colored and similar output that came from the subprocess is not.

I am not aware of a workaround.

@zapta zapta changed the title Allow to to emit colored click.secho() messages to a pipeline. [Feature Request] Allow to to emit colored click.secho() text to a pipeline. Sep 27, 2024
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

1 participant