pallets / pallets/click

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

Open
#2,781 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help output
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.