Skip to content

Add basic color detection - #5

Merged
sindresorhus merged 15 commits into
sindresorhus:mainfrom
Richienb:patch-1
Oct 27, 2021
Merged

sindresorhus merged 15 commits into
sindresorhus:mainfrom
Richienb:patch-1

Conversation

@Richienb

@Richienb Richienb commented Oct 8, 2021

Copy link
Copy Markdown
Contributor

No description provided.

@Richienb
Richienb marked this pull request as ready for review October 8, 2021 01:52
Comment thread readme.md Outdated
@Richienb
Richienb requested a review from sindresorhus October 8, 2021 06:47
@sindresorhus

Copy link
Copy Markdown
Owner

Sorry, I was unclear. The todo comment should be in the code, not readme.

@sindresorhus

Copy link
Copy Markdown
Owner

Tests are failing.

And thinking more about this, I think we should document the supported flags & env variables (FORCE_COLOR and NO_COLOR), since the Node.js docs seem to not do that: https://github.com/nodejs/node/blob/69b6d1d17b90892ec4aceb2136133d1f44646771/lib/internal/tty.js

@Richienb

Richienb commented Oct 9, 2021 •

Copy link
Copy Markdown
Contributor Author

@sindresorhus The build is failing because Node.js is not detecting features on the GitHub Actions terminal that indicate color support. See the related supports-color issue. The best solution might be to sync the Node.js implementation with the fixes.

@sindresorhus

Copy link
Copy Markdown
Owner

The best solution might be to sync the Node.js implementation with the fixes.

I think that should be done regardless.

@sindresorhus

Copy link
Copy Markdown
Owner

I think a better fix would be to use FORCE_COLOR as it would work in other environments too, like when using np (since it spawns).

@sindresorhus

Copy link
Copy Markdown
Owner

And thinking more about this, I think we should document the supported flags & env variables (FORCE_COLOR and NO_COLOR), since the Node.js docs seem to not do that: nodejs/node@69b6d1d/lib/internal/tty.js

Did you see ^?

@sindresorhus

Copy link
Copy Markdown
Owner

And thinking more about this, I think we should document the supported flags & env variables (FORCE_COLOR and NO_COLOR), since the Node.js docs seem to not do that: nodejs/node@69b6d1d/lib/internal/tty.js

Maybe also worth doing a Node.js PR to document these things?

@Richienb

Copy link
Copy Markdown
Contributor Author

@sindresorhus FORCE_COLOR, NO_COLOR and NODE_DISABLE_COLORS are already documented. Is it missing something else?

Also, this PR should be good to go.

targos pushed a commit to nodejs/node that referenced this pull request Oct 23, 2021
PR-URL: #40385
Refs: sindresorhus/yoctocolors#5
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
targos pushed a commit to nodejs/node that referenced this pull request Oct 23, 2021
PR-URL: #40385
Refs: sindresorhus/yoctocolors#5
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@sindresorhus

Copy link
Copy Markdown
Owner

FORCE_COLOR, NO_COLOR and NODE_DISABLE_COLORS are already documented. Is it missing something else?

That's not the docs we are linking to in the readme though. And I think it's good to just document it here anyway for ease of discovery.

@Richienb

Copy link
Copy Markdown
Contributor Author

Config errors caused the build to fail - fixed now.

@sindresorhus
sindresorhus merged commit 2aa7cec into sindresorhus:main Oct 27, 2021
kirillgroshkov added a commit to kirillgroshkov/nodejs-lib that referenced this pull request Oct 31, 2021
It is now a constant, not a function. Dependency-free detection.

Credit to sindresorhus/yoctocolors#5
BethGriggs pushed a commit to nodejs/node that referenced this pull request Nov 24, 2021
PR-URL: #40385
Refs: sindresorhus/yoctocolors#5
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Comment thread index.js
import tty from 'node:tty';

// TODO: Use a better method when it's added to Node.js (https://github.com/nodejs/node/pull/40240)
const hasColors = tty.WriteStream.prototype.hasColors();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@Richienb

Was there a reason for doing this instead of process.stdout.hasColors()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't remember.

@sindresorhus

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I believe the answer is in the TODO comment. process.stdout.hasColors() was not available then.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry, I missed that.

Seems process.stdout.hasColors() has been available. However, they're trying to deprecate it because:

In the PR, they're trying to expose a standalone function but is blocked by deprecation strategy for the prototype method.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants