3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
+ import { IHighlight } from '../../../../base/browser/ui/highlightedlabel/highlightedLabel.js' ;
6
7
import { Color , RGBA } from '../../../../base/common/color.js' ;
7
8
import { isDefined } from '../../../../base/common/types.js' ;
8
9
import { editorHoverBackground , listActiveSelectionBackground , listFocusBackground , listInactiveFocusBackground , listInactiveSelectionBackground } from '../../../../platform/theme/common/colorRegistry.js' ;
@@ -16,7 +17,7 @@ import { ILinkDetector } from './linkDetector.js';
16
17
* @param text The content to stylize.
17
18
* @returns An {@link HTMLSpanElement} that contains the potentially stylized text.
18
19
*/
19
- export function handleANSIOutput ( text : string , linkDetector : ILinkDetector , workspaceFolder : IWorkspaceFolder | undefined ) : HTMLSpanElement {
20
+ export function handleANSIOutput ( text : string , linkDetector : ILinkDetector , workspaceFolder : IWorkspaceFolder | undefined , highlights : IHighlight [ ] | undefined ) : HTMLSpanElement {
20
21
21
22
const root : HTMLSpanElement = document . createElement ( 'span' ) ;
22
23
const textLength : number = text . length ;
@@ -27,6 +28,7 @@ export function handleANSIOutput(text: string, linkDetector: ILinkDetector, work
27
28
let customUnderlineColor : RGBA | string | undefined ;
28
29
let colorsInverted : boolean = false ;
29
30
let currentPos : number = 0 ;
31
+ let unprintedChars = 0 ;
30
32
let buffer : string = '' ;
31
33
32
34
while ( currentPos < textLength ) {
@@ -58,8 +60,10 @@ export function handleANSIOutput(text: string, linkDetector: ILinkDetector, work
58
60
59
61
if ( sequenceFound ) {
60
62
63
+ unprintedChars += 2 + ansiSequence . length ;
64
+
61
65
// Flush buffer with previous styles.
62
- appendStylizedStringToContainer ( root , buffer , styleNames , linkDetector , workspaceFolder , customFgColor , customBgColor , customUnderlineColor ) ;
66
+ appendStylizedStringToContainer ( root , buffer , styleNames , linkDetector , workspaceFolder , customFgColor , customBgColor , customUnderlineColor , highlights , currentPos - buffer . length - unprintedChars ) ;
63
67
64
68
buffer = '' ;
65
69
@@ -105,7 +109,7 @@ export function handleANSIOutput(text: string, linkDetector: ILinkDetector, work
105
109
106
110
// Flush remaining text buffer if not empty.
107
111
if ( buffer ) {
108
- appendStylizedStringToContainer ( root , buffer , styleNames , linkDetector , workspaceFolder , customFgColor , customBgColor , customUnderlineColor ) ;
112
+ appendStylizedStringToContainer ( root , buffer , styleNames , linkDetector , workspaceFolder , customFgColor , customBgColor , customUnderlineColor , highlights , currentPos - buffer . length ) ;
109
113
}
110
114
111
115
return root ;
@@ -395,22 +399,33 @@ export function handleANSIOutput(text: string, linkDetector: ILinkDetector, work
395
399
* @param customTextColor If provided, will apply custom color with inline style.
396
400
* @param customBackgroundColor If provided, will apply custom backgroundColor with inline style.
397
401
* @param customUnderlineColor If provided, will apply custom textDecorationColor with inline style.
402
+ * @param highlights The ranges to highlight.
403
+ * @param offset The starting index of the stringContent in the original text.
398
404
*/
399
405
export function appendStylizedStringToContainer (
400
406
root : HTMLElement ,
401
407
stringContent : string ,
402
408
cssClasses : string [ ] ,
403
409
linkDetector : ILinkDetector ,
404
410
workspaceFolder : IWorkspaceFolder | undefined ,
405
- customTextColor ?: RGBA | string ,
406
- customBackgroundColor ?: RGBA | string ,
407
- customUnderlineColor ?: RGBA | string ,
411
+ customTextColor : RGBA | string | undefined ,
412
+ customBackgroundColor : RGBA | string | undefined ,
413
+ customUnderlineColor : RGBA | string | undefined ,
414
+ highlights : IHighlight [ ] | undefined ,
415
+ offset : number ,
408
416
) : void {
409
417
if ( ! root || ! stringContent ) {
410
418
return ;
411
419
}
412
420
413
- const container = linkDetector . linkify ( stringContent , true , workspaceFolder ) ;
421
+ const container = linkDetector . linkify (
422
+ stringContent ,
423
+ true ,
424
+ workspaceFolder ,
425
+ undefined ,
426
+ undefined ,
427
+ highlights ?. map ( h => ( { start : h . start - offset , end : h . end - offset , extraClasses : h . extraClasses } ) ) ,
428
+ ) ;
414
429
415
430
container . className = cssClasses . join ( ' ' ) ;
416
431
if ( customTextColor ) {
0 commit comments