@@ -241,22 +241,28 @@ namespace ts {
241
241
return errorMessage ;
242
242
}
243
243
244
- const redForegroundEscapeSequence = "\u001b[91m" ;
245
- const yellowForegroundEscapeSequence = "\u001b[93m" ;
246
- const blueForegroundEscapeSequence = "\u001b[93m" ;
244
+ /** @internal */
245
+ export enum ForegroundColorEscapeSequences {
246
+ Grey = "\u001b[90m" ,
247
+ Red = "\u001b[91m" ,
248
+ Yellow = "\u001b[93m" ,
249
+ Blue = "\u001b[94m" ,
250
+ Cyan = "\u001b[96m"
251
+ }
247
252
const gutterStyleSequence = "\u001b[30;47m" ;
248
253
const gutterSeparator = " " ;
249
254
const resetEscapeSequence = "\u001b[0m" ;
250
255
const ellipsis = "..." ;
251
256
function getCategoryFormat ( category : DiagnosticCategory ) : string {
252
257
switch ( category ) {
253
- case DiagnosticCategory . Warning : return yellowForegroundEscapeSequence ;
254
- case DiagnosticCategory . Error : return redForegroundEscapeSequence ;
255
- case DiagnosticCategory . Message : return blueForegroundEscapeSequence ;
258
+ case DiagnosticCategory . Warning : return ForegroundColorEscapeSequences . Yellow ;
259
+ case DiagnosticCategory . Error : return ForegroundColorEscapeSequences . Red ;
260
+ case DiagnosticCategory . Message : return ForegroundColorEscapeSequences . Blue ;
256
261
}
257
262
}
258
263
259
- function formatAndReset ( text : string , formatStyle : string ) {
264
+ /** @internal */
265
+ export function formatColorAndReset ( text : string , formatStyle : string ) {
260
266
return formatStyle + text + resetEscapeSequence ;
261
267
}
262
268
@@ -289,7 +295,7 @@ namespace ts {
289
295
// If the error spans over 5 lines, we'll only show the first 2 and last 2 lines,
290
296
// so we'll skip ahead to the second-to-last line.
291
297
if ( hasMoreThanFiveLines && firstLine + 1 < i && i < lastLine - 1 ) {
292
- context += formatAndReset ( padLeft ( ellipsis , gutterWidth ) , gutterStyleSequence ) + gutterSeparator + host . getNewLine ( ) ;
298
+ context += formatColorAndReset ( padLeft ( ellipsis , gutterWidth ) , gutterStyleSequence ) + gutterSeparator + host . getNewLine ( ) ;
293
299
i = lastLine - 1 ;
294
300
}
295
301
@@ -300,12 +306,12 @@ namespace ts {
300
306
lineContent = lineContent . replace ( "\t" , " " ) ; // convert tabs to single spaces
301
307
302
308
// Output the gutter and the actual contents of the line.
303
- context += formatAndReset ( padLeft ( i + 1 + "" , gutterWidth ) , gutterStyleSequence ) + gutterSeparator ;
309
+ context += formatColorAndReset ( padLeft ( i + 1 + "" , gutterWidth ) , gutterStyleSequence ) + gutterSeparator ;
304
310
context += lineContent + host . getNewLine ( ) ;
305
311
306
312
// Output the gutter and the error span for the line using tildes.
307
- context += formatAndReset ( padLeft ( "" , gutterWidth ) , gutterStyleSequence ) + gutterSeparator ;
308
- context += redForegroundEscapeSequence ;
313
+ context += formatColorAndReset ( padLeft ( "" , gutterWidth ) , gutterStyleSequence ) + gutterSeparator ;
314
+ context += ForegroundColorEscapeSequences . Red ;
309
315
if ( i === firstLine ) {
310
316
// If we're on the last line, then limit it to the last character of the last line.
311
317
// Otherwise, we'll just squiggle the rest of the line, giving 'slice' no end position.
@@ -324,13 +330,19 @@ namespace ts {
324
330
context += resetEscapeSequence ;
325
331
}
326
332
327
- output += host . getNewLine ( ) ;
328
- output += `${ relativeFileName } (${ firstLine + 1 } ,${ firstLineChar + 1 } ): ` ;
333
+ output += formatColorAndReset ( relativeFileName , ForegroundColorEscapeSequences . Cyan ) ;
334
+ output += "(" ;
335
+ output += formatColorAndReset ( `${ firstLine + 1 } ` , ForegroundColorEscapeSequences . Yellow ) ;
336
+ output += "," ;
337
+ output += formatColorAndReset ( `${ firstLineChar + 1 } ` , ForegroundColorEscapeSequences . Yellow ) ;
338
+ output += "): " ;
329
339
}
330
340
331
341
const categoryColor = getCategoryFormat ( diagnostic . category ) ;
332
342
const category = DiagnosticCategory [ diagnostic . category ] . toLowerCase ( ) ;
333
- output += `${ formatAndReset ( category , categoryColor ) } TS${ diagnostic . code } : ${ flattenDiagnosticMessageText ( diagnostic . messageText , host . getNewLine ( ) ) } ` ;
343
+ output += formatColorAndReset ( category , categoryColor ) ;
344
+ output += formatColorAndReset ( ` TS${ diagnostic . code } : ` , ForegroundColorEscapeSequences . Grey ) ;
345
+ output += flattenDiagnosticMessageText ( diagnostic . messageText , host . getNewLine ( ) ) ;
334
346
335
347
if ( diagnostic . file ) {
336
348
output += host . getNewLine ( ) ;
@@ -339,7 +351,7 @@ namespace ts {
339
351
340
352
output += host . getNewLine ( ) ;
341
353
}
342
- return output ;
354
+ return output + host . getNewLine ( ) ;
343
355
}
344
356
345
357
export function flattenDiagnosticMessageText ( messageText : string | DiagnosticMessageChain , newLine : string ) : string {
0 commit comments