Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Update terminal environment variables to detect colors #27609

Closed
BridgeAR opened this issue May 8, 2019 · 28 comments
Closed

Update terminal environment variables to detect colors #27609

BridgeAR opened this issue May 8, 2019 · 28 comments
Labels
good first issue Issues that are suitable for first-time contributors. help wanted Issues that need assistance from volunteers or PRs that need help to proceed. tty Issues and PRs related to the tty subsystem.

Comments

@BridgeAR
Copy link
Member

BridgeAR commented May 8, 2019

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 $TERM but 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.

@BridgeAR BridgeAR added help wanted Issues that need assistance from volunteers or PRs that need help to proceed. good first issue Issues that are suitable for first-time contributors. tty Issues and PRs related to the tty subsystem. labels May 8, 2019
@mscdex
Copy link
Contributor

mscdex commented May 8, 2019

VTE-based terminals should automatically export VTE_VERSION with the VTE version value (e.g. 5202 for v0.52.2).

However, other terminals like qterminal (which does support truecolor) don't set anything, not even COLORTERM currently.

Something else to keep in mind is that environment variables like these typically are not allowed to pass through on SSH connections.

@rpgeeganage
Copy link
Contributor

@BridgeAR ,
May I give this a try? (I hope this only in Javascript code :) )

@BridgeAR
Copy link
Member Author

BridgeAR commented May 8, 2019

@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.

@rpgeeganage
Copy link
Contributor

@BridgeAR
Thank you very much. I'll start working on it probably from tomorrow onward.

@3mard
Copy link

3mard commented May 13, 2019

Can I give this a try ? :)

@rpgeeganage
Copy link
Contributor

@3mard ,
Please go ahead, Thanks a lot.

@dlionz
Copy link

dlionz commented May 15, 2019

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?

@BridgeAR
Copy link
Member Author

@dlionz that is pretty much exactly what's required. We could also start a list here.

@dlionz
Copy link

dlionz commented May 15, 2019

@BridgeAR, thanks for the quick response.

Ok, I'm using iTerm2, and I ran the script above printf "\x1b[38;2;255;100;0mTRUECOLOR\x1b[0m\n"
and it returns 'TURECOLOR'. Here is also a screen cap of my terminal running this function from the docs above about terminal color.

Screen Shot 2019-05-15 at 3 14 18 PM

is this all that is needed?

@dlionz
Copy link

dlionz commented May 15, 2019

@BridgeAR I went ahead and created this PR tty: add color support for iterm2 #27722 please let me know if there is anything I can do if there is an issue.

thanks,
Damien

@rpgeeganage
Copy link
Contributor

@dlionz,
Your PR seems to be not following the contributing guideline. Can you please check it?

@dlionz
Copy link

dlionz commented May 15, 2019

@rpgeeganage Yeah can do, just realized I did it wrong.

@dlionz
Copy link

dlionz commented May 15, 2019

@rpgeeganage corrected my pr
tty: add color support for iterm2 #27723

@dmaynard51
Copy link

I wanted to give it a shot to see if I could contribute in some way (my first time). I added my screenshot below of my terminal screen (using AWS - cloud9).

Screen Shot 2019-05-18 at 10 30 53 PM

@BridgeAR
Copy link
Member Author

@dmaynard51 please check what terminal you're using and what environment variables are set that correspond with the terminal.

@BridgeAR
Copy link
Member Author

I just updated the initial description to include some further information about the environment variables.

@dmaynard51
Copy link

I just updated the initial description to include some further information about the environment variables.

Thank you, hopefully I am showing the correct information. Using the command above my term shows:
TERM: 'xterm-256color',

Also I ran a script like dlionz did above to show some color output.

color

@karansapolia
Copy link

karansapolia commented May 29, 2019

I am using Hyper, version: 3.0.2. Some settings I think that are set by the terminal are:

COLORTERM: 'truecolor',
TERM_PROGRAM_VERSION: '3.0.2',
CHROME_DESKTOP: 'Hyper.desktop',
TERM: 'xterm-256color',
TERM_PROGRAM: 'Hyper'

Screenshot from 2019-05-29 21-30-23

It seems to support only 256 color. I would like to submit a little PR for this @BridgeAR.

@EddieGriffiths
Copy link

I am using mintty 2.7.7 installed with Git for Windows

image

@JEVBR
Copy link

JEVBR commented Jul 2, 2019

On Ubuntu 19.04,

my process.env =
VTE_VERSION: '5602',
TERM: 'xterm-256color',
COLORTERM: 'truecolor',

Screenshot from 2019-07-02 15-19-02

@joe9111
Copy link

joe9111 commented Jul 9, 2019

On MacOS terminal,

TERM: 'xterm-256color'

That is the only env variable that seems to correspond to the terminal.

@duncanhealy
Copy link
Contributor

The check for the (env.COLORTERM) should occur before the check for env.TERM
as env.TERM will allways give you a 256 colour terminal when it is a truecolor term
Should I add a pull request to fix @BridgeAR ?
it never reaches the code below as the prior if check will always?! return

    if (env.COLORTERM === 'truecolor' || env.COLORTERM === '24bit')
      return COLORS_16m;
    return COLORS_16;
  }```

@sarthak0906
Copy link

Hey is this issue still open
I would like to contribute

@duncanhealy
Copy link
Contributor

Hey is this issue still open
I would like to contribute

if you run env |grep TERM you can check if your terminal settings are covered in
test/pseudo-tty/test-tty-color-support.js

@sarthak0906
Copy link

On Ubuntu 18.04.3

COLORTERM=truecolor
TERM=xterm-256color
GNOME_TERMINAL_SERVICE=:1.122

COLORTERM:truecolor is covered in test/pseudo-tty/test-tty-color-support.js but TERM: xterm-256color is not covered.
Although TERM: xterm is in the file
Please confirm if I whould edit it

@BridgeAR
Copy link
Member Author

@sarthak0906 it is covered by TERM='xterm-256'. So there's no need to add another entry. Thanks a lot for checking your term settings!

addaleax pushed a commit that referenced this issue Nov 27, 2019
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 <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
addaleax pushed a commit that referenced this issue Nov 30, 2019
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 <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
targos pushed a commit that referenced this issue Dec 1, 2019
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 <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
MylesBorins pushed a commit that referenced this issue Dec 17, 2019
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 <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
@nodejs nodejs deleted a comment from tacoto12 Apr 8, 2020
@Edu93Jer
Copy link

Edu93Jer commented Dec 26, 2020

Hi @BridgeAR a question, is this issue still open? I've seen that the last comment or commit referencing this issue was like a year ago, I am new to open source and I know is nothing about coding, but would like to at least contribute with something.
Or do you know if there's a good new issue to work with?

@Mesteery
Copy link
Contributor

Mesteery commented Aug 10, 2021

Yes, this issue is resolved by #30474.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Issues that are suitable for first-time contributors. help wanted Issues that need assistance from volunteers or PRs that need help to proceed. tty Issues and PRs related to the tty subsystem.
Projects
None yet
Development

No branches or pull requests