diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2018-04-01 11:37:13 +0200 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-04-04 15:14:05 +0200 |
commit | ceaeee012066e7e56332ba9d9f9306401c971560 (patch) | |
tree | f8d53af1e92fa5d9f567800b298b1071cccfd5da /lib | |
parent | 1b715221b9b875fc24d6aae3480c4c55d7f3dd76 (diff) | |
download | android-node-v8-ceaeee012066e7e56332ba9d9f9306401c971560.tar.gz android-node-v8-ceaeee012066e7e56332ba9d9f9306401c971560.tar.bz2 android-node-v8-ceaeee012066e7e56332ba9d9f9306401c971560.zip |
tty: add color support for more terminals
This adds support for a couple more terminals.
PR-URL: https://github.com/nodejs/node/pull/19730
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/internal/tty.js | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/lib/internal/tty.js b/lib/internal/tty.js index a581ac312f..c4edab24fb 100644 --- a/lib/internal/tty.js +++ b/lib/internal/tty.js @@ -31,6 +31,41 @@ const COLORS_16 = 4; const COLORS_256 = 8; const COLORS_16m = 24; +// Some entries were taken from `dircolors` +// (https://linux.die.net/man/1/dircolors). The corresponding terminals might +// support more than 16 colors, but this was not tested for. +// +// Copyright (C) 1996-2016 Free Software Foundation, Inc. Copying and +// distribution of this file, with or without modification, are permitted +// provided the copyright notice and this notice are preserved. +const TERM_ENVS = [ + 'Eterm', + 'cons25', + 'console', + 'cygwin', + 'dtterm', + 'gnome', + 'hurd', + 'jfbterm', + 'konsole', + 'kterm', + 'mlterm', + 'putty', + 'st', + 'terminator' +]; + +const TERM_ENVS_REG_EXP = [ + /ansi/, + /color/, + /linux/, + /^con[0-9]*x[0-9]/, + /^rxvt/, + /^screen/, + /^xterm/, + /^vt100/ +]; + // The `getColorDepth` API got inspired by multiple sources such as // https://github.com/chalk/supports-color, // https://github.com/isaacs/color-support. @@ -89,8 +124,19 @@ function getColorDepth(env = process.env) { if (env.TERM) { if (/^xterm-256/.test(env.TERM)) return COLORS_256; - if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(env.TERM)) - return COLORS_16; + + const termEnv = env.TERM.toLowerCase(); + + for (const term of TERM_ENVS) { + if (termEnv === term) { + return COLORS_16; + } + } + for (const term of TERM_ENVS_REG_EXP) { + if (term.test(termEnv)) { + return COLORS_16; + } + } } if (env.COLORTERM) |