diff --git a/lib/internal/tty.js b/lib/internal/tty.js index faf5df9b42e6b2..98975fa68a436f 100644 --- a/lib/internal/tty.js +++ b/lib/internal/tty.js @@ -173,6 +173,10 @@ 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 +192,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 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(