From 5a35206e5330a007b63adbeb959f1397fbeadb10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20Paulus=20=F0=9F=A5=AA?= Date: Fri, 13 Mar 2026 12:40:22 -0700 Subject: [PATCH] expose exit result in Terminal class - sometimes the terminal exits before I can even register the terminal.onExit callback. I need to know what the exit code was, so this fixes that --- src/terminal/term.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/terminal/term.ts b/src/terminal/term.ts index f3acfeb..c6ad5e9 100644 --- a/src/terminal/term.ts +++ b/src/terminal/term.ts @@ -109,7 +109,13 @@ export class Terminal { private readonly _pty: IPtyBackend; private readonly _term: xterm.Terminal; private readonly _returnChar: string; - private _exited: boolean = false; + private _exitResult: { exitCode: number; signal?: number } | null = null; + private get _exited(): boolean { + return this._exitResult !== null; + } + get exitResult() { + return this._exitResult; + } readonly onExit: ( callback: (exit: { exitCode: number; signal?: number }) => void ) => void; @@ -138,10 +144,16 @@ export class Terminal { } this._term.write(data); }); - this._pty.onExit(() => { - this._exited = true; + this._pty.onExit((exitResult) => { + this._exitResult = exitResult; }); - this.onExit = (callback) => this._pty.onExit(callback); + this.onExit = (callback) => { + if (this._exitResult) { + callback(this._exitResult); + } else { + this._pty.onExit(callback); + } + }; } /**