Skip to content

Commit 8ca70b8

Browse files
committed
Fixes #5465
Fixes #5465
1 parent 4b00144 commit 8ca70b8

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

src/js/node/tty.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,12 @@ Object.defineProperty(WriteStream, "prototype", {
216216
}
217217

218218
if ("TEAMCITY_VERSION" in env) {
219-
return RegExpPrototypeExec(/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/, env.TEAMCITY_VERSION) !== null
220-
? COLORS_16
221-
: COLORS_2;
219+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) !== null ? COLORS_16 : COLORS_2;
222220
}
223221

224222
switch (env.TERM_PROGRAM) {
225223
case "iTerm.app":
226-
if (!env.TERM_PROGRAM_VERSION || RegExpPrototypeExec(/^[0-2]\./, env.TERM_PROGRAM_VERSION) !== null) {
224+
if (!env.TERM_PROGRAM_VERSION || /^[0-2]\./.test(env.TERM_PROGRAM_VERSION)) {
227225
return COLORS_256;
228226
}
229227
return COLORS_16m;
@@ -239,16 +237,16 @@ Object.defineProperty(WriteStream, "prototype", {
239237
}
240238

241239
if (env.TERM) {
242-
if (RegExpPrototypeExec(/^xterm-256/, env.TERM) !== null) {
240+
if (/^xterm-256/.test(env.TERM) !== null) {
243241
return COLORS_256;
244242
}
245243

246-
const termEnv = StringPrototypeToLowerCase(env.TERM);
244+
const termEnv = env.TERM.toLowerCase();
247245

248246
if (TERM_ENVS[termEnv]) {
249247
return TERM_ENVS[termEnv];
250248
}
251-
if (ArrayPrototypeSome(TERM_ENVS_REG_EXP, term => RegExpPrototypeExec(term, termEnv) !== null)) {
249+
if (TERM_ENVS_REG_EXP.some(term => term.test(termEnv))) {
252250
return COLORS_16;
253251
}
254252
}

test/js/node/tt.y.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { describe, it, expect } from "bun:test";
2+
import { WriteStream } from "node:tty";
3+
4+
describe("WriteStream.prototype.getColorDepth", () => {
5+
it("iTerm ancient", () => {
6+
expect(
7+
WriteStream.prototype.getColorDepth.call(undefined, {
8+
TERM_PROGRAM: "iTerm.app",
9+
}),
10+
).toBe(8);
11+
});
12+
13+
it("iTerm modern", () => {
14+
expect(
15+
WriteStream.prototype.getColorDepth.call(undefined, {
16+
TERM_PROGRAM: "iTerm.app",
17+
TERM_PROGRAM_VERSION: 3,
18+
}),
19+
).toBe(24);
20+
});
21+
22+
it("empty", () => {
23+
expect(WriteStream.prototype.getColorDepth.call(undefined, {})).toBe(1);
24+
});
25+
});

0 commit comments

Comments
 (0)