@@ -111,6 +111,7 @@ export class CommandDetectionCapability extends Disposable implements ICommandDe
111
111
} ;
112
112
this . _register ( this . _terminal . onResize ( e => this . _handleResize ( e ) ) ) ;
113
113
this . _register ( this . _terminal . onCursorMove ( ( ) => this . _handleCursorMove ( ) ) ) ;
114
+ this . _register ( this . _terminal . onData ( ( ) => this . _handleInput ( ) ) ) ;
114
115
}
115
116
116
117
private _handleResize ( e : { cols : number ; rows : number } ) {
@@ -233,6 +234,10 @@ export class CommandDetectionCapability extends Disposable implements ICommandDe
233
234
return undefined ;
234
235
}
235
236
237
+ private _handleInput ( ) : void {
238
+ this . _ptyHeuristics . value . handleInput ( ) ;
239
+ }
240
+
236
241
handlePromptStart ( options ?: IHandleCommandOptions ) : void {
237
242
// Adjust the last command's finished marker when needed. The standard position for the
238
243
// finished marker `D` to appear is at the same position as the following prompt started
@@ -447,6 +452,8 @@ class UnixPtyHeuristics extends Disposable {
447
452
} ) ) ;
448
453
}
449
454
455
+ handleInput ( ) { }
456
+
450
457
async handleCommandStart ( options ?: IHandleCommandOptions ) {
451
458
this . _hooks . commitCommandFinished ( ) ;
452
459
@@ -600,6 +607,19 @@ class WindowsPtyHeuristics extends Disposable {
600
607
}
601
608
}
602
609
610
+ handleInput ( ) {
611
+ if ( this . _capability . currentCommand . isAdjusted === true || this . _capability . currentCommand . isInputAdjusted === true ) {
612
+ return ;
613
+ }
614
+ this . _capability . currentCommand . isInputAdjusted = true ;
615
+ this . _logService . debug ( 'CommandDetectionCapability#handleInput attempting start marker adjustment' ) ;
616
+
617
+ this . _tryAdjustCommandStartMarkerScannedLineCount = 0 ;
618
+ this . _tryAdjustCommandStartMarkerPollCount = 0 ;
619
+ this . _tryAdjustCommandStartMarkerScheduler = new RunOnceScheduler ( ( ) => this . _tryAdjustCommandStartMarker ( this . _terminal . registerMarker ( 0 ) ! ) , AdjustCommandStartMarkerConstants . Interval ) ;
620
+ this . _tryAdjustCommandStartMarkerScheduler . schedule ( ) ;
621
+ }
622
+
603
623
async handleCommandStart ( ) {
604
624
this . _capability . currentCommand . commandStartX = this . _terminal . buffer . active . cursorX ;
605
625
@@ -661,21 +681,24 @@ class WindowsPtyHeuristics extends Disposable {
661
681
if ( prompt ) {
662
682
const adjustedPrompt = typeof prompt === 'string' ? prompt : prompt . prompt ;
663
683
this . _capability . currentCommand . commandStartMarker = this . _terminal . registerMarker ( 0 ) ! ;
664
- if ( typeof prompt === 'object' && prompt . likelySingleLine ) {
665
- this . _logService . debug ( 'CommandDetectionCapability#_tryAdjustCommandStartMarker adjusted promptStart' , `${ this . _capability . currentCommand . promptStartMarker ?. line } -> ${ this . _capability . currentCommand . commandStartMarker . line } ` ) ;
666
- this . _capability . currentCommand . promptStartMarker ?. dispose ( ) ;
667
- this . _capability . currentCommand . promptStartMarker = cloneMarker ( this . _terminal , this . _capability . currentCommand . commandStartMarker ) ;
668
- // Adjust the last command if it's not in the same position as the following
669
- // prompt start marker
670
- const lastCommand = this . _capability . commands . at ( - 1 ) ;
671
- if ( lastCommand && this . _capability . currentCommand . commandStartMarker . line !== lastCommand . endMarker ?. line ) {
672
- lastCommand . endMarker ?. dispose ( ) ;
673
- lastCommand . endMarker = cloneMarker ( this . _terminal , this . _capability . currentCommand . commandStartMarker ) ;
674
- }
684
+
685
+ // Adjust the prompt start marker to the command start marker
686
+ this . _logService . debug ( 'CommandDetectionCapability#_tryAdjustCommandStartMarker adjusted promptStart' , `${ this . _capability . currentCommand . promptStartMarker ?. line } -> ${ this . _capability . currentCommand . commandStartMarker . line } ` ) ;
687
+ this . _capability . currentCommand . promptStartMarker ?. dispose ( ) ;
688
+ this . _capability . currentCommand . promptStartMarker = cloneMarker ( this . _terminal , this . _capability . currentCommand . commandStartMarker ) ;
689
+
690
+ // Adjust the last command if it's not in the same position as the following
691
+ // prompt start marker
692
+ const lastCommand = this . _capability . commands . at ( - 1 ) ;
693
+ if ( lastCommand && this . _capability . currentCommand . commandStartMarker . line !== lastCommand . endMarker ?. line ) {
694
+ lastCommand . endMarker ?. dispose ( ) ;
695
+ lastCommand . endMarker = cloneMarker ( this . _terminal , this . _capability . currentCommand . commandStartMarker ) ;
675
696
}
697
+
676
698
// use the regex to set the position as it's possible input has occurred
677
699
this . _capability . currentCommand . commandStartX = adjustedPrompt . length ;
678
700
this . _logService . debug ( 'CommandDetectionCapability#_tryAdjustCommandStartMarker adjusted commandStart' , `${ start . line } -> ${ this . _capability . currentCommand . commandStartMarker . line } :${ this . _capability . currentCommand . commandStartX } ` ) ;
701
+ this . _capability . currentCommand . isAdjusted = true ;
679
702
this . _flushPendingHandleCommandStartTask ( ) ;
680
703
return ;
681
704
}
0 commit comments