-
-
Notifications
You must be signed in to change notification settings - Fork 27
Handling ANSI colors
This was implemented in https://github.com/sourcefrog/cargo-mutants/pull/263 and https://github.com/sourcefrog/cargo-mutants/issues/178.
The requirements for when to draw ANSI colors are a bit complicated.
Coloring is related to, but different from, drawing progress bars: in CI we typically do want colors but not progress bars.
Colors apply to tracing
output, progress bar content, and stdout listing of mutants and results, including outcome codes and syntax highlighting in mutant names.
Overrides:
- If
NO_COLOR
is set or--color=false
(ornever
) is passed then colors definitely are not drawn. - If
CLICOLOR_FORCE
is set or--color=true
(oralways
) is passed then colors definitely should be drawn.
If colors are neither forced on or off then:
- In CI colors should be drawn (but no progress bars): maybe the script should set --color or maybe we should look at
$CI
. - If output is piped (i.e. not a tty) then colors should not be drawn.
- In most unit and integration tests that inspect stdout/stderr it would be easier if colors were not drawn, so that it's easier to match text and so that debug output isn't cluttered by quoted escape sequences. However, some tests might want to match the coloring.
The environment variables probably should be removed when running CLI tests so that the test results aren't affected by whatever happens to be in the environment where they're run.
It's not uncommon that stderr is a tty and stdout is redirected, and so is not. So, we independently detect whether each of them is a tty, so that you can redirect json to a file but still potentially see progress bars on stderr.