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

Option to force color output #8132

Closed
cjolowicz opened this issue Apr 25, 2020 · 5 comments
Closed

Option to force color output #8132

cjolowicz opened this issue Apr 25, 2020 · 5 comments

Comments

@cjolowicz
Copy link
Contributor

cjolowicz commented Apr 25, 2020

What's the problem this feature will solve?
Sometimes you want color output when the output stream is not a tty. For example, GitHub Actions does not currently provide a tty to jobs, see actions/runner#241.

Describe the solution you'd like
Add a new option --color=WHEN. WHEN can be always, auto, or never:

  • always: Force color output
  • auto: Enable color output if output is a tty (default behavior)
  • never: Do not color output.

With this change, the existing option --no-color becomes a shorthand for --color=never.

For example, on a CI system which does not provide a tty, you can invoke pip --color=always to enable color output explicitly.

Alternative Solutions
I am not aware of an alternative solution. You can work around this by allocating a pseudoterminal explicitly, for example using pyinvoke with pty=True.

Update: pip already enables color output when TERM=ANSI is passed in the environment. AFAICS this behavior is undocumented.

Additional context
The proposed design comes from the ls(1) command of GNU coreutils. Additionally, the ls option allows passing --color without an argument, in which case WHEN defaults to always.

Happy to provide a PR, if there is interest in this. 🐾

@triage-new-issues triage-new-issues bot added the S: needs triage Issues/PRs that need to be triaged label Apr 25, 2020
@cjolowicz
Copy link
Contributor Author

cjolowicz commented Apr 25, 2020

I decided to go ahead with the PR (see #8135), because it's a nice way to get my feet wet with the pip code base. Hope that's ok. Feel free to close if you don't want this feature.

@Alex-S42
Copy link

Using pip in the Windows 10 PowerShell activates the color output. But error messages are printed in dark-red on dark-blue, making them nearly illegible to me. So this option would at least circumvent this problem.

@cjolowicz
Copy link
Contributor Author

@CloudbusterOhio Disabling color output is already available using pip's --no-color option. This issue is about forcing color output when it would be switched off by default.

@webknjaz
Copy link
Member

webknjaz commented Oct 5, 2022

Looks like the FORCE_COLOR env var will start taking effect once the vendored copy of rich is updated in pip.
Ref: #10909.

@uranusjr
Copy link
Member

uranusjr commented Oct 6, 2022

Merging this into the other issue.

@uranusjr uranusjr closed this as not planned Won't fix, can't repro, duplicate, stale Oct 6, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 5, 2022
@pradyunsg pradyunsg removed the S: needs triage Issues/PRs that need to be triaged label Mar 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants