[Feature Request] Allow to to emit colored click.secho() text to a pipeline.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 17.7k
- Forks
- 2.3k
- Avg merge
- 1d 30m
- Merged PRs (30d)
- 18
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how click.secho() decides whether to emit color when stdout is a pipe rather than a terminal. Compare the requested global and per-stream color policies with the subprocess use case, and clarify how AUTO, ALWAYS_KEEP, and ALWAYS_STRIP should behave. Done means a documented, tested policy API can preserve or strip colors for piped output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100