@@ -241,22 +241,27 @@ namespace ts {
241241 return errorMessage ;
242242 }
243243
244- const redForegroundEscapeSequence = "\u001b[91m" ;
245- const yellowForegroundEscapeSequence = "\u001b[93m" ;
246- const blueForegroundEscapeSequence = "\u001b[93m" ;
244+ /** @internal */
245+ export const foregroundColorEscapeSequences = {
246+ grey : "\u001b[90m" ,
247+ red : "\u001b[91m" ,
248+ yellow : "\u001b[93m" ,
249+ cyan : "\u001b[96m"
250+ } ;
247251 const gutterStyleSequence = "\u001b[30;47m" ;
248252 const gutterSeparator = " " ;
249253 const resetEscapeSequence = "\u001b[0m" ;
250254 const ellipsis = "..." ;
251255 function getCategoryFormat ( category : DiagnosticCategory ) : string {
252256 switch ( category ) {
253- case DiagnosticCategory . Warning : return yellowForegroundEscapeSequence ;
254- case DiagnosticCategory . Error : return redForegroundEscapeSequence ;
255- case DiagnosticCategory . Message : return blueForegroundEscapeSequence ;
257+ case DiagnosticCategory . Warning : return foregroundColorEscapeSequences . yellow ;
258+ case DiagnosticCategory . Error : return foregroundColorEscapeSequences . red ;
259+ case DiagnosticCategory . Message : return foregroundColorEscapeSequences . yellow ;
256260 }
257261 }
258262
259- function formatAndReset ( text : string , formatStyle : string ) {
263+ /** @internal */
264+ export function formatColorAndReset ( text : string , formatStyle : string ) {
260265 return formatStyle + text + resetEscapeSequence ;
261266 }
262267
@@ -289,7 +294,7 @@ namespace ts {
289294 // If the error spans over 5 lines, we'll only show the first 2 and last 2 lines,
290295 // so we'll skip ahead to the second-to-last line.
291296 if ( hasMoreThanFiveLines && firstLine + 1 < i && i < lastLine - 1 ) {
292- context += formatAndReset ( padLeft ( ellipsis , gutterWidth ) , gutterStyleSequence ) + gutterSeparator + host . getNewLine ( ) ;
297+ context += formatColorAndReset ( padLeft ( ellipsis , gutterWidth ) , gutterStyleSequence ) + gutterSeparator + host . getNewLine ( ) ;
293298 i = lastLine - 1 ;
294299 }
295300
@@ -300,12 +305,12 @@ namespace ts {
300305 lineContent = lineContent . replace ( "\t" , " " ) ; // convert tabs to single spaces
301306
302307 // Output the gutter and the actual contents of the line.
303- context += formatAndReset ( padLeft ( i + 1 + "" , gutterWidth ) , gutterStyleSequence ) + gutterSeparator ;
308+ context += formatColorAndReset ( padLeft ( i + 1 + "" , gutterWidth ) , gutterStyleSequence ) + gutterSeparator ;
304309 context += lineContent + host . getNewLine ( ) ;
305310
306311 // Output the gutter and the error span for the line using tildes.
307- context += formatAndReset ( padLeft ( "" , gutterWidth ) , gutterStyleSequence ) + gutterSeparator ;
308- context += redForegroundEscapeSequence ;
312+ context += formatColorAndReset ( padLeft ( "" , gutterWidth ) , gutterStyleSequence ) + gutterSeparator ;
313+ context += foregroundColorEscapeSequences . red ;
309314 if ( i === firstLine ) {
310315 // If we're on the last line, then limit it to the last character of the last line.
311316 // Otherwise, we'll just squiggle the rest of the line, giving 'slice' no end position.
@@ -324,13 +329,19 @@ namespace ts {
324329 context += resetEscapeSequence ;
325330 }
326331
327- output += host . getNewLine ( ) ;
328- output += `${ relativeFileName } (${ firstLine + 1 } ,${ firstLineChar + 1 } ): ` ;
332+ output += formatColorAndReset ( relativeFileName , foregroundColorEscapeSequences . cyan ) ;
333+ output += "(" ;
334+ output += formatColorAndReset ( `${ firstLine + 1 } ` , foregroundColorEscapeSequences . yellow ) ;
335+ output += "," ;
336+ output += formatColorAndReset ( `${ firstLineChar + 1 } ` , foregroundColorEscapeSequences . yellow ) ;
337+ output += "): " ;
329338 }
330339
331340 const categoryColor = getCategoryFormat ( diagnostic . category ) ;
332341 const category = DiagnosticCategory [ diagnostic . category ] . toLowerCase ( ) ;
333- output += `${ formatAndReset ( category , categoryColor ) } TS${ diagnostic . code } : ${ flattenDiagnosticMessageText ( diagnostic . messageText , host . getNewLine ( ) ) } ` ;
342+ output += formatColorAndReset ( category , categoryColor ) ;
343+ output += formatColorAndReset ( ` TS${ diagnostic . code } : ` , foregroundColorEscapeSequences . grey ) ;
344+ output += flattenDiagnosticMessageText ( diagnostic . messageText , host . getNewLine ( ) ) ;
334345
335346 if ( diagnostic . file ) {
336347 output += host . getNewLine ( ) ;
@@ -339,7 +350,7 @@ namespace ts {
339350
340351 output += host . getNewLine ( ) ;
341352 }
342- return output ;
353+ return output + host . getNewLine ( ) ;
343354 }
344355
345356 export function flattenDiagnosticMessageText ( messageText : string | DiagnosticMessageChain , newLine : string ) : string {
0 commit comments