You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed util.styleText() supports colorizing text in GitLab CI and GitHub Actions in 22.14, but not in 22.15. And in 22.14, only when the color input is an array. The cause is #56722. That PR correctly solves the bug it references. But it does raise a question: Should util.styleText() enable colors if it runs in a CI provider that supports it? I think it would be nice to have.
What is the feature you are proposing to solve the problem?
Enable colorizing text if Node.js runs in a CI provider that is known to support colors.
What alternatives have you considered?
Keep the status quo. Don’t support colorizing text in CI by default.
I don’t necessarily really Docker output to be colorized. This can run in many contexts. But I do think it would be nice to support colors in some common specific environments that are known to support colors, notably in CI.
I think everything works as expected. There are just some situations where a non-interactive shell still supports colors. Mainly CI output comes to mind.
For an individual case is fine of course, but I think every project should do this. And also every project should support other CI environments as well. So realistically one currently still needs a userland library to support terminal colors.
You could also assume that basic colors are supported when process.env.CI === 'true'. I’m familiar with GitLab and GitHub. I don’t know if it’s common for other CI environments to support colors.
There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the
never-staleIssues and PRs exempt from automated stale handling.
label or close this issue if it should be closed. If not, the issue will be automatically closed 6 months after the last non-automated comment.
For more information on how the project manages feature requests, please consult the feature request management document.
There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.
Activity
ChaseKnowlden commentedon Apr 24, 2025
Already implemented.
AugustinMauroy commentedon Apr 26, 2025
check you CI env var maybe no color is enabled
remcohaszing commentedon Apr 28, 2025
No. Colors are disabled by default on GitHub actions. I made a reproduction: https://github.com/remcohaszing/node-issue-styletext. You can see the CI output here: https://github.com/remcohaszing/node-issue-styletext/actions/runs/14704349430/job/41260837797
[-]Allow terminal colors in CI[/-][+]Enable terminal colors in CI[/+]AugustinMauroy commentedon Apr 28, 2025
It's strange because I can't reproduce the result on my Mac M1. Could it be GH?? no idea, I'm going to make myself a docker with ubuntu.
EDIT:
I can reproduce it with docker using ubuntu lasted. So it's mean it's an ubuntu issue or node ubuntu build.
remcohaszing commentedon Apr 28, 2025
The following yields the same result:
docker run --rm node:22.15 -e 'console.log(util.styleText(["red"], "array")); console.log(util.styleText("red", "string")); console.dir(process.env)'Whereas the same command on my own Linux laptop does yield colors:
node -e 'console.log(util.styleText(["red"], "array")); console.log(util.styleText("red", "string")); console.dir(process.env)'I don’t necessarily really Docker output to be colorized. This can run in many contexts. But I do think it would be nice to support colors in some common specific environments that are known to support colors, notably in CI.
AugustinMauroy commentedon Apr 28, 2025
I just used docker to have a local ubuntu environment.
remcohaszing commentedon Apr 28, 2025
You can start an interactive Node.js shell with:
Or an interactive bash shell with:
In both these cases
util.styleText()yields colored content on my machine.It just doesn’t add colors for non-interactive stdout. Another example to explicitly disallow colors piping the output through
cat.I think everything works as expected. There are just some situations where a non-interactive shell still supports colors. Mainly CI output comes to mind.
targos commentedon Apr 28, 2025
According to https://github.com/chalk/supports-color/blob/ae809ecabd5965d0685e7fc121efe98c47ad8724/index.js#L126-L129, the only way to enable colors support by default on CI hosts is to hardcode them.
AugustinMauroy commentedon Apr 28, 2025
Do we want that on node core ??? and do we have a fix for that using force_color ?
remcohaszing commentedon May 2, 2025
Ideological I’m in doubt. I believe CI systems that support colors, should signal that.
In practice however, I think this will never happen, but individual users of
util.styleText()will receive requests to support this.As a practical example, I use this in
eslint-formatter-gitlab. If I want to colorize output in CI jobs, I need to specify a function like this:For an individual case is fine of course, but I think every project should do this. And also every project should support other CI environments as well. So realistically one currently still needs a userland library to support terminal colors.
You could also assume that basic colors are supported when
process.env.CI === 'true'. I’m familiar with GitLab and GitHub. I don’t know if it’s common for other CI environments to support colors.targos commentedon May 2, 2025
Wait, we already have the hardcoded CI variables:
node/lib/internal/tty.js
Lines 161 to 174 in fca4107
This might actually be a bug in
util.styleTextafter all.AugustinMauroy commentedon May 2, 2025
I think the function itself is good, it's the function itself
node/lib/internal/util/colors.js
Line 18 in fca4107
tty: improve color terminal color detection
tty: improve color terminal color detection
tty: improve color terminal color detection
github-actions commentedon Dec 1, 2025
There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the never-staleIssues and PRs exempt from automated stale handling.
label or close this issue if it should be closed. If not, the issue will be automatically closed 6 months after the last non-automated comment.
For more information on how the project manages feature requests, please consult the feature request management document.
github-actions commentedon Jan 1, 2026
There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.
For more information on how the project manages feature requests, please consult the feature request management document.