Skip to content

Commit 574d56d

Browse files
committed
feat: handle process exit
1 parent 3454680 commit 574d56d

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/components/terminal/terminal.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Unicode11Addon } from "@xterm/addon-unicode11";
1111
import { WebLinksAddon } from "@xterm/addon-web-links";
1212
import { WebglAddon } from "@xterm/addon-webgl";
1313
import { Terminal as Xterm } from "@xterm/xterm";
14+
import toast from "components/toast";
1415
import confirm from "dialogs/confirm";
1516
import fonts from "lib/fonts";
1617
import keyBindings from "lib/keyBindings";
@@ -524,7 +525,8 @@ export default class TerminalComponent {
524525

525526
// If AXS still not running after retries, throw error
526527
if (!(await Terminal.isAxsRunning())) {
527-
throw new Error("Failed to start AXS server after multiple attempts");
528+
toast("Failed to start AXS server after multiple attempts");
529+
//throw new Error("Failed to start AXS server after multiple attempts");
528530
}
529531
}
530532

@@ -589,6 +591,22 @@ export default class TerminalComponent {
589591
this.fit();
590592
};
591593

594+
this.websocket.onmessage = (event) => {
595+
// Handle text messages (exit events)
596+
if (typeof event.data === "string") {
597+
try {
598+
const message = JSON.parse(event.data);
599+
if (message.type === "exit") {
600+
this.onProcessExit?.(message.data);
601+
return;
602+
}
603+
} catch (error) {
604+
// Not a JSON message, let attachAddon handle it
605+
}
606+
}
607+
// For binary data or non-exit text messages, let attachAddon handle them
608+
};
609+
592610
this.websocket.onclose = (event) => {
593611
this.isConnected = false;
594612
this.onDisconnect?.();
@@ -918,4 +936,5 @@ export default class TerminalComponent {
918936
onError(error) {}
919937
onTitleChange(title) {}
920938
onBell() {}
939+
onProcessExit(exitData) {}
921940
}

src/components/terminal/terminalManager.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import EditorFile from "lib/editorFile";
77
import TerminalComponent from "./terminal";
88
import "@xterm/xterm/css/xterm.css";
9+
import toast from "components/toast";
910

1011
class TerminalManager {
1112
constructor() {
@@ -345,6 +346,22 @@ class TerminalManager {
345346
}
346347
};
347348

349+
terminalComponent.onProcessExit = (exitData) => {
350+
// Format exit message based on exit code and signal
351+
let message;
352+
if (exitData.signal) {
353+
message = `Process terminated by signal ${exitData.signal}`;
354+
} else if (exitData.exit_code === 0) {
355+
message = `Process exited successfully (code ${exitData.exit_code})`;
356+
} else {
357+
message = `Process exited with code ${exitData.exit_code}`;
358+
}
359+
360+
this.closeTerminal(terminalId);
361+
terminalFile.remove(true);
362+
toast(message);
363+
};
364+
348365
// Store references for cleanup
349366
terminalFile._terminalId = terminalId;
350367
terminalFile.terminalComponent = terminalComponent;

0 commit comments

Comments
 (0)