Skip to content

Conversation

@thinkimlazy
Copy link

Disables color output with --no-color option for CLI and
"noColor": true for package.json
Resolves #843

@novemberborn
Copy link
Member

@thinkimlazy thanks for your PR.

Reading #843 I can't determine whether @sindresorhus wanted this fixed in chalk, or whether he wanted a flag in AVA. Ideally this just works without needing additional options.

@sindresorhus?

@thinkimlazy
Copy link
Author

thinkimlazy commented Oct 30, 2016

@novemberborn Hey, thats not working ideally as you want because of this code in verbose/mini reporters:

chalk.enabled = true; Object.keys(colors).forEach(function (key) { colors[key].enabled = true; }); 

So when chalk initialized in reporters, --no-color really disables colors, but this loop enables them. So there is no need to fix anything in chalk.
Also we can delete this loops in reporters, then --no-color just works.

@snypelife
Copy link

Killing those forEach's in the reporters seems to work nicely, as well as clean things up a bit. But I noticed that env vars like CI or TEAMCITY_VERSION aren't getting picked up from https://github.com/chalk/supports-color/blob/master/index.js.

@snypelife
Copy link

@novemberborn from my perspective of that conversation in the issue, it looks like both a fix in the supports-color module as well as ava were sought after (ava being the flag needs to be passed down and supports-color needing teamcity <9 support).

Copy link
Member

@sindresorhus sindresorhus left a comment

Choose a reason for hiding this comment

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

This will need a test of both the AVA output and chalk used in a test.

}

if (
hasFlag('--no-color') ||
Copy link
Member

Choose a reason for hiding this comment

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

This is incorrect. It should be:

cli.flags.color === false
) {
chalk.enabled = false;
Object.keys(colors).forEach(function (key) {
colors[key].enabled = false;
Copy link
Member

Choose a reason for hiding this comment

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

I think chalk.enabled = false should be enough.

Copy link
Member

Choose a reason for hiding this comment

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

Actually. None of this should be needed as chalk already supports the --no-color flag.

Copy link
Member

Choose a reason for hiding this comment

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

What actually needs to be done is to pass the flag down to the forked process.

],
"babel": "inherit"
"babel": "inherit",
"noColor": true
Copy link
Member

Choose a reason for hiding this comment

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

"color": false 
@sindresorhus sindresorhus changed the title add --no-color option Resolves #843 add --no-color flag - fixes #843 Nov 4, 2016
@sindresorhus sindresorhus changed the title add --no-color flag - fixes #843 Add --no-color flag - fixes #843 Nov 4, 2016
@thinkimlazy thinkimlazy closed this Nov 5, 2016
@thinkimlazy thinkimlazy deleted the no-color branch November 5, 2016 08:50
@sindresorhus
Copy link
Member

@thinkimlazy Why did you close?

@thinkimlazy
Copy link
Author

@sindresorhus sry, I messed up
I reopened PR

@sindresorhus
Copy link
Member

@thinkimlazy You never have to open a new PR. That just creates noise in the issue tracker. You can always reset the state of an existing PR and start over if you really messed up.

@thinkimlazy
Copy link
Author

@sindresorhus I can't reopen this one because I recreated my branch. Again sorry for spam

@sindresorhus
Copy link
Member

No worries :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants