FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

tty: truecolor check moved before 256 check by duncanhealy · Pull Request #30474 · nodejs/node · GitHub

/ node Public

tty: truecolor check moved before 256 check - #30474

Closed
duncanhealy wants to merge 4 commits into
nodejs:masterfrom
duncanhealy:truecolor-before-256
Closed

tty: truecolor check moved before 256 check#30474
duncanhealy wants to merge 4 commits into
nodejs:masterfrom
duncanhealy:truecolor-before-256

Conversation

Copy link
Copy Markdown
Contributor

256 color would be return instead of 16m if both env variables were set
Test added to pseudo-tty/test-tty-color-support
Related Issue: #27609

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

nodejs-github-bot added the tty Issues and PRs related to the tty subsystem. label Nov 13, 2019

BridgeAR left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM. Thanks for the fix!

BridgeAR added the author ready PRs that have at least one approval, no outstanding review comments, and a CI started. label Nov 13, 2019

Copy link
Copy Markdown
Collaborator

Comment thread lib/internal/tty.js Outdated
return COLORS_256;
}

if (env.COLORTERM) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I looks like this if statement can be removed, if (env.COLORTERM === 'truecolor' || env.COLORTERM === '24bit') { /* ... */ } is sufficient.

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Hi @lpinca this is to catch the case when no TERM environment variable is set
without this COLORS_2 is returned which fails an existing test

lpinca Nov 17, 2019
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I don't get it, if env.COLORTERM is truthy, COLORS_16m is returned only if env.COLORTERM === 'truecolor' || env.COLORTERM === '24bit' otherwise nothing is done so why not using only

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

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

COLORTERM can be set to values other than truecolor and 24bit . yes no gnome-terminal are other values used. We want to return the higest spec tty capability available first. If you remove the second check for env.COLORTERM you miss the case when TERM is not set but COLORTERM is not truecolor or 24bit. If you leave the code as it was before you get 256 color terminal when your terminal is capable of 16M. Basically we are moving the COLORS_256 check inbetween the COLORS_16m and the COLORS_16 checks

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

FWIW this is what I'm suggesting

diff --git a/lib/internal/tty.js b/lib/internal/tty.js
index faf5df9b42..63832ef220 100644
--- a/lib/internal/tty.js
+++ b/lib/internal/tty.js
@@ -173,6 +173,9 @@ function getColorDepth(env = process.env) {
       return COLORS_256;
   }
 
+  if (env.COLORTERM === 'truecolor' || env.COLORTERM === '24bit')
+    return COLORS_16m;
+
   if (env.TERM) {
     if (/^xterm-256/.test(env.TERM))
       return COLORS_256;
@@ -188,13 +191,10 @@ function getColorDepth(env = process.env) {
       }
     }
   }
-
+  // Move 16 color COLORTERM below 16m and 256
   if (env.COLORTERM) {
-    if (env.COLORTERM === 'truecolor' || env.COLORTERM === '24bit')
-      return COLORS_16m;
     return COLORS_16;
   }
-
   return COLORS_2;
 }
 
diff --git a/test/pseudo-tty/test-tty-color-support.js b/test/pseudo-tty/test-tty-color-support.js
index b2cfc804c3..57ed640d4d 100644
--- a/test/pseudo-tty/test-tty-color-support.js
+++ b/test/pseudo-tty/test-tty-color-support.js
@@ -71,6 +71,7 @@ const writeStream = new WriteStream(fd);
   [{ NO_COLOR: '', COLORTERM: '24bit' }, 1],
   [{ TMUX: '1', FORCE_COLOR: 0 }, 1],
   [{ NO_COLOR: 'true', FORCE_COLOR: 0, COLORTERM: 'truecolor' }, 1],
+  [{ TERM: 'xterm-256color', COLORTERM: 'truecolor' }, 24],
 ].forEach(([env, depth], i) => {
   const actual = writeStream.getColorDepth(env);
   assert.strictEqual(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
if (env.COLORTERM) {
  if (env.COLORTERM === 'truecolor' || env.COLORTERM === '24bit')
    return COLORS_16m;
}

is equal to

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

which is equal to

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

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

if you remove the bottom if and make test you can see the case when it fails

lpinca Nov 17, 2019
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I've applied the patch in my previous comment and tests pass.

What you mean with bottom if? The one on line 197? If so I'm not suggesting to remove it. I never did. Anyway it does not matter, it is not very important :)

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

ok yes we can remove the nested if - I thought you were talking about the second if (env.COLORTERM) - I'll update the pull request now

Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Member

Landed in 80ac428, thanks for the PR! 🎉

addaleax pushed a commit that referenced this pull request 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 <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>
addaleax closed this Nov 27, 2019
addaleax pushed a commit that referenced this pull request 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 <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>
targos pushed a commit that referenced this pull request 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 <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>
BridgeAR mentioned this pull request Dec 3, 2019
BethGriggs mentioned this pull request Dec 9, 2019
MylesBorins pushed a commit that referenced this pull request 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 <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>
BethGriggs mentioned this pull request Dec 23, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no outstanding review comments, and a CI started. tty Issues and PRs related to the tty subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants


Back | FazBrowse Home | New Git URL