Skip to content

Commit d853af8

Browse files
committed
fix ctrl-d handling
1 parent 697f0e2 commit d853af8

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

src/tty-bridge.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { createNodePrompts } from "./prompts.js";
66
import { normalizeServerUrl, webSocketUrlForServer } from "./tls-policy.js";
77

88
const webSocketOpenReadyState = 1;
9-
const ctrlD = "\x04";
109
const secretPromptMessages = {
1110
password_required: {
1211
labelFor: (message) => message.prompt ?? "Password: ",
@@ -142,9 +141,6 @@ export class TermixTtyBridge {
142141
}
143142

144143
this.send({ type: "input", data });
145-
if (data === ctrlD) {
146-
this.finish(0);
147-
}
148144
}
149145

150146
resize(cols = this.stdout.columns || this.cols, rows = this.stdout.rows || this.rows) {

test/tty-bridge.test.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,31 @@ describe("TTY bridge", () => {
310310
assert.equal(ws.sent.at(-1).type, "disconnect");
311311
});
312312

313-
it("treats raw Ctrl-D as local EOF after sending EOT to the remote session", async () => {
313+
it("forwards raw Ctrl-D without locally closing the active session", async () => {
314+
const { bridge, ws, stdin } = bridgeFixture();
315+
bridge.start();
316+
ws.emit("open");
317+
318+
stdin.write(Buffer.from([0x04]));
319+
await flushImmediate();
320+
321+
assert.equal(bridge.closed, false);
322+
assert.deepEqual(ws.sent.slice(1), [
323+
{ type: "input", data: "\x04" },
324+
]);
325+
assert.deepEqual(stdin.rawModes, [true]);
326+
assert.equal(stdin.pauseCalls, 0);
327+
328+
bridge.finish(0);
329+
});
330+
331+
it("exits after Ctrl-D when the remote shell ends the session", async () => {
314332
const { bridge, ws, stdin } = bridgeFixture();
315333
const done = bridge.start();
316334
ws.emit("open");
317335

318336
stdin.write(Buffer.from([0x04]));
337+
ws.serverMessage({ type: "session_ended", code: 0 });
319338

320339
assert.equal(await done, 0);
321340
assert.deepEqual(ws.sent.slice(1), [

0 commit comments

Comments
 (0)