Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Rework color detection #87

Merged
merged 7 commits into from
Oct 16, 2024
Merged

Rework color detection #87

merged 7 commits into from
Oct 16, 2024

Conversation

alexeyraspopov
Copy link
Owner

@alexeyraspopov alexeyraspopov commented Oct 16, 2024

Closes #41, #44, #62, #67, #71, #80, #83.

picocolors.js Outdated
argv = p.argv || [],
env = p.env || {},
out = p.stdout || {}
let ne = v => v != null && String(v).length > 0

Choose a reason for hiding this comment

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

Do we really need such elaborate check?

v is guaranteed to be undefined or String, so this could be changed to simple v => !!v.
And in this case we don't need this function at all.
Just use !!env.NO_COLOR instead of ne(env.NO_COLOR).

Copy link
Owner Author

Choose a reason for hiding this comment

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

See #62 (comment). The key is to keep treating empty string value as falsy value.

Copy link
Owner Author

Choose a reason for hiding this comment

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

If I understood @lukeed comment correctly 😅

Copy link

@alexeyten alexeyten Oct 16, 2024

Choose a reason for hiding this comment

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

@alexeyraspopov

> !!""
false
> !!"1"
true
> !!undefined
false

Copy link
Owner Author

Choose a reason for hiding this comment

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

I see your point. I tried to recall this behavior but testing it on numbers !!0 tripped me over.

picocolors.js Outdated
(require != null && require("tty").isatty(1) && env.TERM !== "dumb") ||
"CI" in env)
p.platform === "win32" ||
(out.isTTY && env.TERM !== "dumb") ||

Choose a reason for hiding this comment

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

out is used only once.
Could be shorter to write
(p.stdout || {}).isTTY && ...

Copy link
Owner Author

Choose a reason for hiding this comment

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

Good point, missed that

@@ -1,12 +1,13 @@
let argv = process.argv || [],
env = process.env
let p = process || {},

This comment was marked as outdated.

Choose a reason for hiding this comment

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

Oh actually using globalThis would make this library not work in older Node.js version :/

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Colors are always enabled in CI, even when output is piped
3 participants