mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
tty: refactor to use more primordials
PR-URL: https://github.com/nodejs/node/pull/36272 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
@@ -22,6 +22,12 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const {
|
||||
RegExpPrototypeTest,
|
||||
StringPrototypeSplit,
|
||||
StringPrototypeToLowerCase,
|
||||
} = primordials;
|
||||
|
||||
const {
|
||||
ERR_INVALID_ARG_TYPE,
|
||||
ERR_OUT_OF_RANGE
|
||||
@@ -134,7 +140,7 @@ function getColorDepth(env = process.env) {
|
||||
// Lazy load for startup performance.
|
||||
if (OSRelease === undefined) {
|
||||
const { release } = require('os');
|
||||
OSRelease = release().split('.');
|
||||
OSRelease = StringPrototypeSplit(release(), '.');
|
||||
}
|
||||
// Windows 10 build 10586 is the first Windows release that supports 256
|
||||
// colors. Windows 10 build 14931 is the first release that supports
|
||||
@@ -163,14 +169,15 @@ function getColorDepth(env = process.env) {
|
||||
}
|
||||
|
||||
if ('TEAMCITY_VERSION' in env) {
|
||||
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ?
|
||||
return RegExpPrototypeTest(/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/, env.TEAMCITY_VERSION) ?
|
||||
COLORS_16 : COLORS_2;
|
||||
}
|
||||
|
||||
switch (env.TERM_PROGRAM) {
|
||||
case 'iTerm.app':
|
||||
if (!env.TERM_PROGRAM_VERSION ||
|
||||
/^[0-2]\./.test(env.TERM_PROGRAM_VERSION)) {
|
||||
RegExpPrototypeTest(/^[0-2]\./, env.TERM_PROGRAM_VERSION)
|
||||
) {
|
||||
return COLORS_256;
|
||||
}
|
||||
return COLORS_16m;
|
||||
@@ -186,16 +193,17 @@ function getColorDepth(env = process.env) {
|
||||
}
|
||||
|
||||
if (env.TERM) {
|
||||
if (/^xterm-256/.test(env.TERM))
|
||||
if (RegExpPrototypeTest(/^xterm-256/, env.TERM)) {
|
||||
return COLORS_256;
|
||||
}
|
||||
|
||||
const termEnv = env.TERM.toLowerCase();
|
||||
const termEnv = StringPrototypeToLowerCase(env.TERM);
|
||||
|
||||
if (TERM_ENVS[termEnv]) {
|
||||
return TERM_ENVS[termEnv];
|
||||
}
|
||||
for (const term of TERM_ENVS_REG_EXP) {
|
||||
if (term.test(termEnv)) {
|
||||
if (RegExpPrototypeTest(term, termEnv)) {
|
||||
return COLORS_16;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user