From 9f3139c8810a4f0102d30c7b999614d5d7cc08d8 Mon Sep 17 00:00:00 2001 From: Duncan Healy Date: Wed, 13 Nov 2019 17:59:45 +0000 Subject: [PATCH 1/4] tty: improve color check order highest spec first --- lib/internal/tty.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/internal/tty.js b/lib/internal/tty.js index faf5df9b42e6b2..05d5aac2317409 100644 --- a/lib/internal/tty.js +++ b/lib/internal/tty.js @@ -173,6 +173,11 @@ function getColorDepth(env = process.env) { return COLORS_256; } + if (env.COLORTERM) { + if (env.COLORTERM === 'truecolor' || env.COLORTERM === '24bit') + return COLORS_16m; + } + if (env.TERM) { if (/^xterm-256/.test(env.TERM)) return COLORS_256; @@ -187,12 +192,10 @@ function getColorDepth(env = process.env) { return COLORS_16; } } - } - - if (env.COLORTERM) { - if (env.COLORTERM === 'truecolor' || env.COLORTERM === '24bit') - return COLORS_16m; - return COLORS_16; + // Move 16 color COLORTERM below 16m and 256 + if (env.COLORTERM) { + return COLORS_16; + } } return COLORS_2; From 4cd885ffee396db6fde994a6320a4dc768896565 Mon Sep 17 00:00:00 2001 From: Duncan Healy Date: Wed, 13 Nov 2019 18:32:23 +0000 Subject: [PATCH 2/4] tty: add test for TERM and COLORTERM set --- test/pseudo-tty/test-tty-color-support.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/pseudo-tty/test-tty-color-support.js b/test/pseudo-tty/test-tty-color-support.js index b2cfc804c30281..57ed640d4d813f 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( From 7dde89e78f6e30748faa31a0882a44d26cf5f778 Mon Sep 17 00:00:00 2001 From: Duncan Healy Date: Wed, 13 Nov 2019 18:34:20 +0000 Subject: [PATCH 3/4] tty: move COLORTERM check outside TERM closure --- lib/internal/tty.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/internal/tty.js b/lib/internal/tty.js index 05d5aac2317409..34b24f8deec38d 100644 --- a/lib/internal/tty.js +++ b/lib/internal/tty.js @@ -192,12 +192,11 @@ function getColorDepth(env = process.env) { return COLORS_16; } } - // Move 16 color COLORTERM below 16m and 256 - if (env.COLORTERM) { - return COLORS_16; - } } - + // Move 16 color COLORTERM below 16m and 256 + if (env.COLORTERM) { + return COLORS_16; + } return COLORS_2; } From 7df205f97d3978103d134759965d96d93e80feef Mon Sep 17 00:00:00 2001 From: Duncan Healy Date: Sun, 17 Nov 2019 18:55:59 +0000 Subject: [PATCH 4/4] tty: remove extra if check for COLORTERM --- lib/internal/tty.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/internal/tty.js b/lib/internal/tty.js index 34b24f8deec38d..98975fa68a436f 100644 --- a/lib/internal/tty.js +++ b/lib/internal/tty.js @@ -173,9 +173,8 @@ function getColorDepth(env = process.env) { return COLORS_256; } - if (env.COLORTERM) { - if (env.COLORTERM === 'truecolor' || env.COLORTERM === '24bit') - return COLORS_16m; + if (env.COLORTERM === 'truecolor' || env.COLORTERM === '24bit') { + return COLORS_16m; } if (env.TERM) {