Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upUpdate terminal environment variables to detect colors #27609
Comments
This comment has been minimized.
This comment has been minimized.
|
VTE-based terminals should automatically export However, other terminals like qterminal (which does support truecolor) don't set anything, not even Something else to keep in mind is that environment variables like these typically are not allowed to pass through on SSH connections. |
This comment has been minimized.
This comment has been minimized.
|
@BridgeAR , |
This comment has been minimized.
This comment has been minimized.
|
@rpgeeganage please go for it. It is all JS. This is mainly meant as a tracking issue. @mscdex it's definitely not a fool prove solution. I tried very hard to come up with anything or find something but this seemed to be the best we can do so far. If there's any reliable alternative (even only to reliable detect a few terminals), we should go for that instead. |
This comment has been minimized.
This comment has been minimized.
|
@BridgeAR |
This comment has been minimized.
This comment has been minimized.
|
Can I give this a try ? :) |
This comment has been minimized.
This comment has been minimized.
|
@3mard , |
This comment has been minimized.
This comment has been minimized.
|
Hello, Id like to give this a go as well, but I'm not entirely sure what is expected. is it just as simple as adding my Terminal name to the TERM_ENVS object and the colors it supports? |
This comment has been minimized.
This comment has been minimized.
|
@dlionz that is pretty much exactly what's required. We could also start a list here. |
This comment has been minimized.
This comment has been minimized.
|
@BridgeAR, thanks for the quick response. Ok, I'm using iTerm2, and I ran the script above is this all that is needed? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@dlionz, |
This comment has been minimized.
This comment has been minimized.
|
@rpgeeganage Yeah can do, just realized I did it wrong. |
This comment has been minimized.
This comment has been minimized.
|
@rpgeeganage corrected my pr |
This comment has been minimized.
This comment has been minimized.
This comment was marked as off-topic.
This comment was marked as off-topic.
|
Maximus Brewer has sent you an email via Gmail confidential mode:Re: [nodejs/node] Update terminal environment variables to detect colors (#27609)This message was sent on May 18, 2019 at 10:47:36 PM PDTYou can open it by clicking the link below. This link will only work for reply@reply.github.com.View the emailGmail confidential mode gives you more control over the messages you send. Set an expiration time, disable printing or forwarding of a message and more. Learn moreGmail: Email by GoogleUse is subject to the Google Privacy PolicyGoogle LLC, 1600 Amphitheatre Parkway, Mountain View, CA 94043, USAYou have received this message because someone sent you an email via Gmail confidential mode.
|
This comment has been minimized.
This comment has been minimized.
|
@dmaynard51 please check what terminal you're using and what environment variables are set that correspond with the terminal. |
This comment has been minimized.
This comment has been minimized.
|
I just updated the initial description to include some further information about the environment variables. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I am using Hyper, version: 3.0.2. Some settings I think that are set by the terminal are:
It seems to support only 256 color. I would like to submit a little PR for this @BridgeAR. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
On MacOS terminal,
That is the only env variable that seems to correspond to the terminal. |
This comment has been minimized.
This comment has been minimized.
|
The check for the (env.COLORTERM) should occur before the check for env.TERM
|
This comment has been minimized.
This comment has been minimized.
|
Hey is this issue still open |
This comment has been minimized.
This comment has been minimized.
if you run |
This comment has been minimized.
This comment has been minimized.
|
On Ubuntu 18.04.3
|
This comment has been minimized.
This comment has been minimized.
|
@sarthak0906 it is covered by |
256 color would be return instead of 16m if both env variables were set * tty: improve color check order highest spec first * tty: add test for TERM and COLORTERM set * tty: move COLORTERM check outside TERM closure * tty: remove extra if check for COLORTERM Refs: #27609 PR-URL: #30474 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
256 color would be return instead of 16m if both env variables were set * tty: improve color check order highest spec first * tty: add test for TERM and COLORTERM set * tty: move COLORTERM check outside TERM closure * tty: remove extra if check for COLORTERM Refs: #27609 PR-URL: #30474 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
256 color would be return instead of 16m if both env variables were set * tty: improve color check order highest spec first * tty: add test for TERM and COLORTERM set * tty: move COLORTERM check outside TERM closure * tty: remove extra if check for COLORTERM Refs: #27609 PR-URL: #30474 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
256 color would be return instead of 16m if both env variables were set * tty: improve color check order highest spec first * tty: add test for TERM and COLORTERM set * tty: move COLORTERM check outside TERM closure * tty: remove extra if check for COLORTERM Refs: nodejs#27609 PR-URL: nodejs#30474 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
256 color would be return instead of 16m if both env variables were set * tty: improve color check order highest spec first * tty: add test for TERM and COLORTERM set * tty: move COLORTERM check outside TERM closure * tty: remove extra if check for COLORTERM Refs: nodejs#27609 PR-URL: nodejs#30474 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
256 color would be return instead of 16m if both env variables were set * tty: improve color check order highest spec first * tty: add test for TERM and COLORTERM set * tty: move COLORTERM check outside TERM closure * tty: remove extra if check for COLORTERM Refs: #27609 PR-URL: #30474 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>






Right now we have a pretty decent list of environment variables to detect different terminals that support colors. However, it is often not exactly known from what version on these terminals actually support the colors, if that's detectable and how many colors these support.
I would like to start a list of different terminals / CIs and other things including their corresponding environment variables or other information to detect these and the information how many colors they support.
The current code can be found here: https://github.com/nodejs/node/blob/master/lib/internal/tty.js
A lot of information about terminals that support 16 million colors can be found here: https://github.com/termstandard/colors
Anyone can please check their terminal and post the name, version, corresponding env settings (not all) and the supported colors. This should be pretty straight forward and a good first contribution! The more information we gather here, the better Node.js will become in properly supporting colors.
Just enter the following in your terminal to check for true color:
printf "\x1b[38;2;255;100;0mTRUECOLOR\x1b[0m\n"Update: Please make sure you check what environment variables are set by your terminal! That is important since not all correspond to
$TERMbut some also to e.g.,$TERM_PROGRAM. You can check what environment variables are set by running:node -e 'console.log(process.env)'. You have to check what environment variables correspond to the terminal. Please do not post any environment variables besides those.