File tree Expand file tree Collapse file tree 3 files changed +26
-9
lines changed Expand file tree Collapse file tree 3 files changed +26
-9
lines changed Original file line number Diff line number Diff line change @@ -2,10 +2,11 @@ import type { ChildProcessWithoutNullStreams } from 'child_process';
2
2
import { spawn } from 'child_process' ;
3
3
4
4
import { getEnvConfig } from '../config/config' ;
5
+ import { TerminalColors } from '../terminal/TerminalColors' ;
5
6
import type { Logger } from '../util/Logger' ;
6
7
7
8
const NEWLINE_SEPARATOR = / \r \n | \r | \n / ;
8
- const STDOUT_PREFIX = / ^ [ a - z ] + : / ;
9
+ const OUTPUT_PREFIX = / ^ ( [ a - z ] + : ) / ;
9
10
10
11
export class CLI {
11
12
constructor ( private readonly logger : Logger ) { }
@@ -44,10 +45,25 @@ export class CLI {
44
45
. join ( '\n' ) ;
45
46
}
46
47
48
+ public static colorizeOutput ( output : string ) : string {
49
+ return output
50
+ . split ( NEWLINE_SEPARATOR )
51
+ . map ( line => {
52
+ if ( line . startsWith ( 'warn:' ) ) {
53
+ return (
54
+ line . replace ( OUTPUT_PREFIX , `$1${ TerminalColors . yellow } ` ) +
55
+ TerminalColors . reset
56
+ ) ;
57
+ }
58
+ return line ;
59
+ } )
60
+ . join ( '\n' ) ;
61
+ }
62
+
47
63
public static removePrefixFromStdOut ( output : string ) : string {
48
64
return output
49
65
. split ( NEWLINE_SEPARATOR )
50
- . map ( line => line . replace ( STDOUT_PREFIX , '' ) )
66
+ . map ( line => line . replace ( OUTPUT_PREFIX , '' ) )
51
67
. join ( '\n' ) ;
52
68
}
53
69
Original file line number Diff line number Diff line change @@ -3,16 +3,12 @@ import { type ChildProcessWithoutNullStreams } from 'child_process';
3
3
4
4
import { EventWaiter } from '../util/EventWaiter' ;
5
5
import { CLI } from '../cli/CLI' ;
6
+ import { TerminalColors } from './TerminalColors' ;
6
7
7
8
const NL = '\n' ;
8
9
const CR = '\r' ;
9
10
const nlRegExp = new RegExp ( `${ NL } ([^${ CR } ]|$)` , 'g' ) ;
10
11
11
- class TerminalColors {
12
- public static blue = '\u001b[34m' ;
13
- public static reset = `\u001b[0m` ;
14
- }
15
-
16
12
export class Terminal implements vscode . Pseudoterminal {
17
13
private cmd : ChildProcessWithoutNullStreams | undefined ;
18
14
@@ -43,10 +39,10 @@ export class Terminal implements vscode.Pseudoterminal {
43
39
44
40
const { cmd, output } = this . cli . exec ( cmdArgs , cwd , {
45
41
onStdOut : ( buffer : string ) => {
46
- this . write ( CLI . removePrefixFromStdOut ( buffer ) ) ;
42
+ this . write ( CLI . removePrefixFromStdOut ( CLI . colorizeOutput ( buffer ) ) ) ;
47
43
} ,
48
44
onStdErr : ( buffer : string ) => {
49
- this . write ( CLI . removePrefixFromStdOut ( buffer ) ) ;
45
+ this . write ( CLI . removePrefixFromStdOut ( CLI . colorizeOutput ( buffer ) ) ) ;
50
46
} ,
51
47
} ) ;
52
48
this . cmd = cmd ;
Original file line number Diff line number Diff line change
1
+ export class TerminalColors {
2
+ public static blue = '\u001b[34m' ;
3
+ public static yellow = '\u001b[33m' ;
4
+ public static reset = `\u001b[0m` ;
5
+ }
You can’t perform that action at this time.
0 commit comments