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';
22import { spawn } from 'child_process' ;
33
44import { getEnvConfig } from '../config/config' ;
5+ import { TerminalColors } from '../terminal/TerminalColors' ;
56import type { Logger } from '../util/Logger' ;
67
78const NEWLINE_SEPARATOR = / \r \n | \r | \n / ;
8- const STDOUT_PREFIX = / ^ [ a - z ] + : / ;
9+ const OUTPUT_PREFIX = / ^ ( [ a - z ] + : ) / ;
910
1011export class CLI {
1112 constructor ( private readonly logger : Logger ) { }
@@ -44,10 +45,25 @@ export class CLI {
4445 . join ( '\n' ) ;
4546 }
4647
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+
4763 public static removePrefixFromStdOut ( output : string ) : string {
4864 return output
4965 . split ( NEWLINE_SEPARATOR )
50- . map ( line => line . replace ( STDOUT_PREFIX , '' ) )
66+ . map ( line => line . replace ( OUTPUT_PREFIX , '' ) )
5167 . join ( '\n' ) ;
5268 }
5369
Original file line number Diff line number Diff line change @@ -3,16 +3,12 @@ import { type ChildProcessWithoutNullStreams } from 'child_process';
33
44import { EventWaiter } from '../util/EventWaiter' ;
55import { CLI } from '../cli/CLI' ;
6+ import { TerminalColors } from './TerminalColors' ;
67
78const NL = '\n' ;
89const CR = '\r' ;
910const nlRegExp = new RegExp ( `${ NL } ([^${ CR } ]|$)` , 'g' ) ;
1011
11- class TerminalColors {
12- public static blue = '\u001b[34m' ;
13- public static reset = `\u001b[0m` ;
14- }
15-
1612export class Terminal implements vscode . Pseudoterminal {
1713 private cmd : ChildProcessWithoutNullStreams | undefined ;
1814
@@ -43,10 +39,10 @@ export class Terminal implements vscode.Pseudoterminal {
4339
4440 const { cmd, output } = this . cli . exec ( cmdArgs , cwd , {
4541 onStdOut : ( buffer : string ) => {
46- this . write ( CLI . removePrefixFromStdOut ( buffer ) ) ;
42+ this . write ( CLI . removePrefixFromStdOut ( CLI . colorizeOutput ( buffer ) ) ) ;
4743 } ,
4844 onStdErr : ( buffer : string ) => {
49- this . write ( CLI . removePrefixFromStdOut ( buffer ) ) ;
45+ this . write ( CLI . removePrefixFromStdOut ( CLI . colorizeOutput ( buffer ) ) ) ;
5046 } ,
5147 } ) ;
5248 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