Add support for using is_terminal
and environment variables to determine whether to output ANSI colour sequences.
#275
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This makes use of the trait
IsTerminal
, stabilised in Rust 1.70. If the Rust version is at least 1.70, then the library uses this trait to detect whether stdout is a terminal and only outputs colours by default if that is the case. When used on prior Rust versions, the library does not detect whether the output is a terminal and defaults to not outputing colours.This also introduces support for two environment variables to override the default behaviour defined above:
NO_COLOR
, described in http://no-color.org.FORCE_COLOR
, which is supported by a range of tools such as Node.js.The environment variable
GTEST_RUST_NO_COLOR
is hereby no longer supported.This also removes the ANSI colour sequences from nearly all tests. It creates two integration tests which specifically test the colourised output respectively the behaviour of the environment variable
NO_COLOR
. Otherwise, it globally setsNO_COLOR
to suppress colourised output. This greatly reduces the noise in the existing test assertions and makes sure the tests continue to be compatible with all environments.Since the use of
IsTerminal
is optional and conditional on the Rust version, this does not change the minimum supported Rust version.