@@ -8,7 +8,7 @@ import { CancellationError } from '../../../../../../base/common/errors.js';
88import { Emitter , Event } from '../../../../../../base/common/event.js' ;
99import { DisposableStore , MutableDisposable } from '../../../../../../base/common/lifecycle.js' ;
1010import { isNumber } from '../../../../../../base/common/types.js' ;
11- import type { ICommandDetectionCapability , ITerminalCommand } from '../../../../../../platform/terminal/common/capabilities/capabilities.js' ;
11+ import type { ICommandDetectionCapability } from '../../../../../../platform/terminal/common/capabilities/capabilities.js' ;
1212import { ITerminalLogService } from '../../../../../../platform/terminal/common/terminal.js' ;
1313import type { ITerminalInstance } from '../../../../terminal/browser/terminal.js' ;
1414import { trackIdleOnPrompt , type ITerminalExecuteStrategy , type ITerminalExecuteStrategyResult } from './executeStrategy.js' ;
@@ -46,14 +46,21 @@ export class RichExecuteStrategy implements ITerminalExecuteStrategy {
4646 throw new Error ( 'Xterm is not available' ) ;
4747 }
4848
49- const onDone : Promise < ITerminalCommand | void > = Promise . race ( [
49+ const onDone = Promise . race ( [
5050 Event . toPromise ( this . _commandDetection . onCommandFinished , store ) . then ( e => {
5151 this . _log ( 'onDone via end event' ) ;
52- return e ;
52+ return {
53+ 'type' : 'success' ,
54+ command : e
55+ } as const ;
5356 } ) ,
5457 Event . toPromise ( token . onCancellationRequested as Event < undefined > , store ) . then ( ( ) => {
5558 this . _log ( 'onDone via cancellation' ) ;
5659 } ) ,
60+ Event . toPromise ( this . _instance . onDisposed , store ) . then ( ( ) => {
61+ this . _log ( 'onDone via terminal disposal' ) ;
62+ return { type : 'disposal' } as const ;
63+ } ) ,
5764 trackIdleOnPrompt ( this . _instance , 1000 , store ) . then ( ( ) => {
5865 this . _log ( 'onDone via idle prompt' ) ;
5966 } ) ,
@@ -73,7 +80,12 @@ export class RichExecuteStrategy implements ITerminalExecuteStrategy {
7380
7481 // Wait for the terminal to idle
7582 this . _log ( 'Waiting for done event' ) ;
76- const finishedCommand = await onDone ;
83+ const onDoneResult = await onDone ;
84+ if ( onDoneResult && onDoneResult . type === 'disposal' ) {
85+ throw new Error ( 'The terminal was closed' ) ;
86+ }
87+ const finishedCommand = onDoneResult && onDoneResult . type === 'success' ? onDoneResult . command : undefined ;
88+
7789 if ( token . isCancellationRequested ) {
7890 throw new CancellationError ( ) ;
7991 }
0 commit comments