Support CLICOLOR
#9835
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`
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 to1
, 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 toCLICOLOR
.Notes
The text was updated successfully, but these errors were encountered: