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

Support CLICOLOR #9835

Closed
Mythra opened this issue Aug 23, 2021 · 3 comments
Closed

Support CLICOLOR #9835

Mythra opened this issue Aug 23, 2021 · 3 comments
Labels
A-console-output Area: Terminal output, colors, progress bar, etc. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@Mythra
Copy link

Mythra commented Aug 23, 2021

Describe the problem you are trying to solve

On a current project I'm invoking cargo from some rust code, and capturing it's output to add some helpful debugging information to the beginning of the line outputs, i.e. running the cargo command with: .stdout(Stdio::Piped()). (as an example log line instead of printing: Finished dev [unoptimized + debuginfo] target(s) in 0.32s, it'd print something like: Thread #2 | Finished dev [unoptimized + debuginfo] target(s) in 0.32s.

The problem comes in when the tool wants the color output of cargo to be auto detected, similar to how it'd be run without using the tool. Unfortunately Cargo forces color auto detection based off of a tty. While this is a good fallback, it leads to the case where the tool, has to know that cargo supports: --color on certain commands (e.g. cargo fmt --color does not work), and how to append it when it wants to show the user the pretty colors they see without the tool. This means a very tight integration with cargo specifically, as opposed to being able to do something generic like it does for other tools.

Describe the solution you'd like

I'd propose adding support for CLICOLOR which is an environment variable that is not specific to just cargo (it's not standard, but there really isn't any one specific standard for colors here, and is recommended in many other places/tools). Which can be set to 1, to tell a tool to turn on colors. The tool already does this today for other applications.

I should note there is also a semi-standard color option called: NO_COLOR, I'm happy to add support in for this as well, but I really want to focus on 'turning colors on' part which is tied to CLICOLOR.

Notes

  • I'm happy to add support for this myself I just want to make sure moving forward using CLICOLOR, and supporting CLICOLOR is okay.
@Mythra Mythra added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Aug 23, 2021
@ehuss
Copy link
Contributor

ehuss commented Aug 23, 2021

Does the environment variable CARGO_TERM_COLOR=always not work for your case?

@Mythra
Copy link
Author

Mythra commented Aug 23, 2021

I should note rustc also supports CLICOLOR: rust-lang/rust#27867 (a friend pointed this out to me, along with things like clang/llvm) (edit: it seemed this was closed, and I misunderstood my friend!)

Color always doesn't quite do what I want, my tool my be directed to a file in which case there should be no ansi color codes. or if someone does set CLICOLOR=0 I want turn it off. Now could I build a specific env var integration that used a cargo specific variable, swapping between always, and never which:

  1. Isn't in the number format many other tools use for a Boolean state.
  2. Is specific to cargo.

Sure, I could, but again then I'm bound to cargo. I'd rather use the widely supported generic argument that just works for everything else.

@ehuss ehuss added the A-console-output Area: Terminal output, colors, progress bar, etc. label Sep 11, 2021
@epage
Copy link
Contributor

epage commented Oct 23, 2023

This is supported as of #12751

@epage epage closed this as completed Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-console-output Area: Terminal output, colors, progress bar, etc. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

No branches or pull requests

3 participants