Skip to content

Commit 90a6f05

Browse files
maxpaulus43Max Paulus 🥪
andauthored
fix: expose exit result in Terminal class (#46)
- 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 Co-authored-by: Max Paulus 🥪 <max@cline.bot>
1 parent 515dfe6 commit 90a6f05

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

src/terminal/term.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,13 @@ export class Terminal {
109109
private readonly _pty: IPtyBackend;
110110
private readonly _term: xterm.Terminal;
111111
private readonly _returnChar: string;
112-
private _exited: boolean = false;
112+
private _exitResult: { exitCode: number; signal?: number } | null = null;
113+
private get _exited(): boolean {
114+
return this._exitResult !== null;
115+
}
116+
get exitResult() {
117+
return this._exitResult;
118+
}
113119
readonly onExit: (
114120
callback: (exit: { exitCode: number; signal?: number }) => void
115121
) => void;
@@ -138,10 +144,16 @@ export class Terminal {
138144
}
139145
this._term.write(data);
140146
});
141-
this._pty.onExit(() => {
142-
this._exited = true;
147+
this._pty.onExit((exitResult) => {
148+
this._exitResult = exitResult;
143149
});
144-
this.onExit = (callback) => this._pty.onExit(callback);
150+
this.onExit = (callback) => {
151+
if (this._exitResult) {
152+
callback(this._exitResult);
153+
} else {
154+
this._pty.onExit(callback);
155+
}
156+
};
145157
}
146158

147159
/**

0 commit comments

Comments
 (0)