@@ -490,7 +490,7 @@ export class CommandDetectionCapability implements ICommandDetectionCapability {
490
490
commandStartLineContent : this . _currentCommand . commandStartLineContent ,
491
491
hasOutput : ( ) => ! executedMarker ?. isDisposed && ! endMarker ?. isDisposed && ! ! ( executedMarker && endMarker && executedMarker ?. line < endMarker ! . line ) ,
492
492
getOutput : ( ) => getOutputForCommand ( executedMarker , endMarker , buffer ) ,
493
- getOutputMatch : ( outputMatcher ? : { lineMatcher : string | RegExp ; anchor ?: 'top' | 'bottom' ; offset ?: number ; length ?: number } ) => getOutputMatchForCommand ( executedMarker , endMarker , buffer , this . _terminal . cols , outputMatcher ) ,
493
+ getOutputMatch : ( outputMatcher : { lineMatcher : string | RegExp ; anchor ?: 'top' | 'bottom' ; offset ?: number ; length ?: number } ) => getOutputMatchForCommand ( executedMarker , endMarker , buffer , this . _terminal . cols , outputMatcher ) ,
494
494
markProperties : options ?. markProperties
495
495
} ;
496
496
this . _commands . push ( newCommand ) ;
@@ -647,43 +647,35 @@ function getOutputForCommand(executedMarker: IMarker | undefined, endMarker: IMa
647
647
return output === '' ? undefined : output ;
648
648
}
649
649
650
- export function getOutputMatchForCommand ( executedMarker : IMarker | undefined , endMarker : IMarker | undefined , buffer : IBuffer , cols : number , outputMatcher : { lineMatcher : string | RegExp ; anchor ?: 'top' | 'bottom' ; offset ?: number ; length ?: number } | undefined ) : RegExpMatchArray | undefined {
650
+ export function getOutputMatchForCommand ( executedMarker : IMarker | undefined , endMarker : IMarker | undefined , buffer : IBuffer , cols : number , outputMatcher : { lineMatcher : string | RegExp ; anchor ?: 'top' | 'bottom' ; offset ?: number ; length ?: number } ) : RegExpMatchArray | undefined {
651
651
if ( ! executedMarker || ! endMarker ) {
652
652
return undefined ;
653
653
}
654
654
const startLine = executedMarker . line ;
655
655
const endLine = endMarker . line ;
656
656
657
- if ( startLine === endLine ) {
658
- return undefined ;
659
- }
660
-
661
- let line : string | undefined ;
662
- if ( outputMatcher ?. anchor === 'bottom' ) {
657
+ const matcher = outputMatcher . lineMatcher ;
658
+ const linesToCheck = typeof matcher === 'string' ? 1 : countNewLines ( matcher ) ;
659
+ const lines : string [ ] = [ ] ;
660
+ if ( outputMatcher . anchor === 'bottom' ) {
663
661
for ( let i = endLine - ( outputMatcher . offset || 0 ) ; i >= startLine ; i -- ) {
664
- let wrappedLineStart = i ;
665
- const wrappedLineEnd = i ;
666
- while ( wrappedLineStart >= startLine && buffer . getLine ( wrappedLineStart ) ?. isWrapped ) {
667
- wrappedLineStart -- ;
662
+ lines . unshift ( getXtermLineContent ( buffer , i , i , cols ) ) ;
663
+ if ( lines . length > linesToCheck ) {
664
+ lines . pop ( ) ;
668
665
}
669
- i = wrappedLineStart ;
670
- line = getXtermLineContent ( buffer , wrappedLineStart , wrappedLineEnd , cols ) ;
671
- const match = line . match ( outputMatcher . lineMatcher ) ;
666
+ const match = lines . join ( '\n' ) . match ( matcher ) ;
672
667
if ( match ) {
673
668
return match ;
674
669
}
675
670
}
676
671
} else {
677
- for ( let i = startLine + ( outputMatcher ?. offset || 0 ) ; i < endLine ; i ++ ) {
678
- const wrappedLineStart = i ;
679
- let wrappedLineEnd = i ;
680
- while ( wrappedLineEnd + 1 < endLine && buffer . getLine ( wrappedLineEnd + 1 ) ?. isWrapped ) {
681
- wrappedLineEnd ++ ;
672
+ for ( let i = startLine + ( outputMatcher . offset || 0 ) ; i < endLine ; i ++ ) {
673
+ lines . push ( getXtermLineContent ( buffer , i , i , cols ) ) ;
674
+ if ( lines . length === linesToCheck ) {
675
+ lines . shift ( ) ;
682
676
}
683
- i = wrappedLineEnd ;
684
- line = getXtermLineContent ( buffer , wrappedLineStart , wrappedLineEnd , cols ) ;
685
677
if ( outputMatcher ) {
686
- const match = line . match ( outputMatcher . lineMatcher ) ;
678
+ const match = lines . join ( '\n' ) . match ( matcher ) ;
687
679
if ( match ) {
688
680
return match ;
689
681
}
@@ -709,3 +701,17 @@ function getXtermLineContent(buffer: IBuffer, lineStart: number, lineEnd: number
709
701
}
710
702
return content ;
711
703
}
704
+
705
+ function countNewLines ( regex : RegExp ) : number {
706
+ if ( ! regex . multiline ) {
707
+ return 1 ;
708
+ }
709
+ const source = regex . source ;
710
+ let count = 1 ;
711
+ let i = source . indexOf ( '\\n' ) ;
712
+ while ( i !== - 1 ) {
713
+ count ++ ;
714
+ i = source . indexOf ( '\\n' , i + 1 ) ;
715
+ }
716
+ return count ;
717
+ }
0 commit comments