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

Disable coloured logs #1450

Merged
merged 2 commits into from
Apr 29, 2022
Merged

Conversation

zk-tarts
Copy link
Contributor

Motivation

A couple issues (#1295,#1029) raise the concern of wanting an option to disable colours in the terminal output.

Solution

Added a check when forge or cast is invoked that turns off colours if the terminal is a basic windows terminal, or if NO_COLOR is set in env.

In order to do this I swapped out the ansi_term dependency across the whole crate for yansi
It has some very simple built in support for the exact feature wanted: disabling colour on unsupporting windows terminals.
It also seems like ansi-term is not being maintained so its not a bad idea to change to a more recently updated crate.

Didn't add any tests but I can confirm running:

$ NO_COLOR=1 forge test

now outputs logs with no colours.

zk-tarts added 2 commits April 28, 2022 21:46
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great!
thank you

/// Disables terminal colours if either:
/// - Running windows and the terminal does not support colour codes.
/// - Colour has been disabled by some environment variable.
pub fn enable_paint() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@mattsse mattsse merged commit e6d1bdb into foundry-rs:master Apr 29, 2022
@onbjerg onbjerg mentioned this pull request Apr 30, 2022
2 tasks
@onbjerg onbjerg added the T-feature Type: feature label Apr 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-feature Type: feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants