* Fixes #5465

Fixes #5465

* Update tty.js

* Update InternalModuleRegistryConstants.h

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
Jarred Sumner
2023-09-15 06:53:39 -07:00
committed by GitHub
parent 6cc5872765
commit a39b0d86a0
3 changed files with 33 additions and 10 deletions

View File

@@ -216,14 +216,12 @@ Object.defineProperty(WriteStream, "prototype", {
}
if ("TEAMCITY_VERSION" in env) {
return RegExpPrototypeExec(/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/, env.TEAMCITY_VERSION) !== null
? COLORS_16
: COLORS_2;
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? COLORS_16 : COLORS_2;
}
switch (env.TERM_PROGRAM) {
case "iTerm.app":
if (!env.TERM_PROGRAM_VERSION || RegExpPrototypeExec(/^[0-2]\./, env.TERM_PROGRAM_VERSION) !== null) {
if (!env.TERM_PROGRAM_VERSION || /^[0-2]\./.test(env.TERM_PROGRAM_VERSION)) {
return COLORS_256;
}
return COLORS_16m;
@@ -239,16 +237,16 @@ Object.defineProperty(WriteStream, "prototype", {
}
if (env.TERM) {
if (RegExpPrototypeExec(/^xterm-256/, env.TERM) !== null) {
if (/^xterm-256/.test(env.TERM) !== null) {
return COLORS_256;
}
const termEnv = StringPrototypeToLowerCase(env.TERM);
const termEnv = env.TERM.toLowerCase();
if (TERM_ENVS[termEnv]) {
return TERM_ENVS[termEnv];
}
if (ArrayPrototypeSome(TERM_ENVS_REG_EXP, term => RegExpPrototypeExec(term, termEnv) !== null)) {
if (TERM_ENVS_REG_EXP.some(term => term.test(termEnv))) {
return COLORS_16;
}
}

File diff suppressed because one or more lines are too long

25
test/js/node/tt.y.test.ts Normal file
View File

@@ -0,0 +1,25 @@
import { describe, it, expect } from "bun:test";
import { WriteStream } from "node:tty";
describe("WriteStream.prototype.getColorDepth", () => {
it("iTerm ancient", () => {
expect(
WriteStream.prototype.getColorDepth.call(undefined, {
TERM_PROGRAM: "iTerm.app",
}),
).toBe(8);
});
it("iTerm modern", () => {
expect(
WriteStream.prototype.getColorDepth.call(undefined, {
TERM_PROGRAM: "iTerm.app",
TERM_PROGRAM_VERSION: 3,
}),
).toBe(24);
});
it("empty", () => {
expect(WriteStream.prototype.getColorDepth.call(undefined, {})).toBe(1);
});
});