Skip to content

Commit 917b6e8

Browse files
fix(terminal): advertise truecolor for both PTY backends
1 parent 85ed49b commit 917b6e8

4 files changed

Lines changed: 32 additions & 62 deletions

File tree

‎apps/server/src/terminal/Manager.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,6 +1687,31 @@ it.layer(
16871687
}),
16881688
);
16891689

1690+
it.effect.each(["linux", "darwin", "win32"] as const)(
1691+
"advertises truecolor before the PTY backend on %s without replacing explicit values",
1692+
(platform) =>
1693+
Effect.gen(function* () {
1694+
for (const [parentColor, runtimeColor, expected] of [
1695+
[undefined, undefined, "truecolor"],
1696+
["", undefined, "truecolor"],
1697+
["24bit", undefined, "24bit"],
1698+
["24bit", "", "truecolor"],
1699+
["24bit", "custom", "custom"],
1700+
] as const) {
1701+
const env = Object.freeze({ COLORTERM: parentColor });
1702+
const { manager, ptyAdapter } = yield* createManager(5, {
1703+
shellResolver: () => "/bin/sh",
1704+
env,
1705+
}).pipe(Effect.provide(withHostPlatform(platform)));
1706+
yield* manager.open(
1707+
openInput({ env: runtimeColor === undefined ? {} : { COLORTERM: runtimeColor } }),
1708+
);
1709+
expect(ptyAdapter.spawnInputs[0]?.env.COLORTERM).toBe(expected);
1710+
expect(env.COLORTERM).toBe(parentColor);
1711+
}
1712+
}),
1713+
);
1714+
16901715
it.effect("filters app runtime env variables from terminal sessions", () =>
16911716
Effect.gen(function* () {
16921717
const { manager, ptyAdapter } = yield* createManager(5, {

‎apps/server/src/terminal/Manager.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,10 @@ function createTerminalSpawnEnv(
12701270
spawnEnv[key] = value;
12711271
}
12721272
}
1273+
// Both PTY backends feed truecolor-capable terminal clients.
1274+
if (spawnEnv.COLORTERM === undefined || spawnEnv.COLORTERM === "") {
1275+
spawnEnv.COLORTERM = "truecolor";
1276+
}
12731277
return stripAppImageRuntimeEnv(spawnEnv);
12741278
}
12751279

‎apps/server/src/terminal/NodePtyAdapter.test.ts‎

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ it.effect("spawns through the public adapter with the provided host references",
5353
cwd: "C:\\workspace",
5454
cols: 120,
5555
rows: 40,
56-
env: { TERM: "xterm-256color", COLORTERM: "truecolor" },
56+
env: { TERM: "xterm-256color" },
5757
name: "xterm-256color",
5858
},
5959
]);
@@ -80,61 +80,7 @@ it.effect("preserves a caller-provided TERM in the spawn env on win32", () =>
8080
cwd: "C:\\workspace",
8181
cols: 80,
8282
rows: 24,
83-
env: { TERM: "xterm-direct", COLORTERM: "truecolor" },
84-
name: "xterm-256color",
85-
},
86-
]);
87-
}).pipe(Effect.provide(testLayer)),
88-
);
89-
90-
it.effect("defaults COLORTERM to truecolor when it is missing or empty", () =>
91-
Effect.gen(function* () {
92-
spawn.mockClear();
93-
const adapter = yield* PtyAdapter.PtyAdapter;
94-
yield* adapter.spawn({
95-
shell: "powershell.exe",
96-
cwd: "C:\\workspace",
97-
cols: 80,
98-
rows: 24,
99-
env: { COLORTERM: "" },
100-
});
101-
102-
assert.equal(spawn.mock.calls.length, 1);
103-
assert.deepEqual(spawn.mock.calls[0], [
104-
"powershell.exe",
105-
[],
106-
{
107-
cwd: "C:\\workspace",
108-
cols: 80,
109-
rows: 24,
110-
env: { COLORTERM: "truecolor", TERM: "xterm-256color" },
111-
name: "xterm-256color",
112-
},
113-
]);
114-
}).pipe(Effect.provide(testLayer)),
115-
);
116-
117-
it.effect("preserves a caller-provided COLORTERM in the spawn env", () =>
118-
Effect.gen(function* () {
119-
spawn.mockClear();
120-
const adapter = yield* PtyAdapter.PtyAdapter;
121-
yield* adapter.spawn({
122-
shell: "powershell.exe",
123-
cwd: "C:\\workspace",
124-
cols: 80,
125-
rows: 24,
126-
env: { COLORTERM: "24bit" },
127-
});
128-
129-
assert.equal(spawn.mock.calls.length, 1);
130-
assert.deepEqual(spawn.mock.calls[0], [
131-
"powershell.exe",
132-
[],
133-
{
134-
cwd: "C:\\workspace",
135-
cols: 80,
136-
rows: 24,
137-
env: { COLORTERM: "24bit", TERM: "xterm-256color" },
83+
env: { TERM: "xterm-direct" },
13884
name: "xterm-256color",
13985
},
14086
]);

‎apps/server/src/terminal/NodePtyAdapter.ts‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,10 @@ export const make = Effect.fn("NodePtyAdapter.make")(function* (
144144
// node-pty only writes `name` into the child's TERM on the Unix path;
145145
// the ConPTY path leaves the environment untouched, so Windows children
146146
// inherit a missing or 16-color TERM unless it is set here.
147-
let env =
147+
const env =
148148
platform === "win32" && input.env["TERM"] === undefined
149149
? { ...input.env, TERM: "xterm-256color" }
150150
: input.env;
151-
// Ghostty VT renders 24-bit color, but TUIs that inspect COLORTERM
152-
// downsample when it is missing or empty.
153-
if (env["COLORTERM"] === undefined || env["COLORTERM"] === "") {
154-
env = { ...env, COLORTERM: "truecolor" };
155-
}
156151
const ptyProcess = yield* Effect.try({
157152
try: () =>
158153
nodePty.spawn(input.shell, input.args ?? [], {

0 commit comments

Comments
 (0)