@@ -108,9 +108,11 @@ namespace ts {
108108 sys . write ( output ) ;
109109 }
110110
111- const redForegroundEscapeSequence = "\u001b[91m" ;
112- const gutterStyleSequence = "\u001b[100;30m" ;
113- const resetEscapeSequence = "\u001b[0m" ;
111+ const shouldUseColors = sys . writesToTty && sys . writesToTty ( ) ;
112+ const redForegroundEscapeSequence = shouldUseColors ? "\u001b[91m" : "" ;
113+ const gutterStyleSequence = shouldUseColors ? "\u001b[100;30m" : "" ;
114+ const gutterSeparator = shouldUseColors ? " " : " | "
115+ const resetEscapeSequence = shouldUseColors ? "\u001b[0m" : "" ;
114116
115117 function reportDiagnosticWithColorAndContext ( diagnostic : Diagnostic ) : void {
116118 let output = "" ;
@@ -132,7 +134,7 @@ namespace ts {
132134 // If the error spans over 5 lines, we'll only show the first 2 and last 2 lines,
133135 // so we'll skip ahead to the second-to-last line.
134136 if ( hasMoreThanFiveLines && firstLine + 1 < i && i < lastLine - 1 ) {
135- output += gutterStyleSequence + padLeft ( "..." , gutterWidth ) + resetEscapeSequence + " " + sys . newLine ;
137+ output += gutterStyleSequence + padLeft ( "..." , gutterWidth ) + resetEscapeSequence + gutterSeparator + sys . newLine ;
136138 i = lastLine - 1 ;
137139 }
138140
@@ -142,11 +144,12 @@ namespace ts {
142144 lineContent = lineContent . replace ( / \s + $ / g, "" ) ; // trim from end
143145 lineContent = lineContent . replace ( "\t" , " " ) ; // convert tabs to single spaces
144146
145- // Output the actual contents of the line.
146- output += gutterStyleSequence + padLeft ( i + 1 + "" , gutterWidth ) + resetEscapeSequence + " " + lineContent + sys . newLine ;
147+ // Output the gutter and the actual contents of the line.
148+ output += gutterStyleSequence + padLeft ( i + 1 + "" , gutterWidth ) + resetEscapeSequence + gutterSeparator ;
149+ output += lineContent + sys . newLine ;
147150
148- // Output the error span for the line using tildes.
149- output += gutterStyleSequence + padLeft ( "" , gutterWidth ) + resetEscapeSequence + " " ;
151+ // Output the gutter and the error span for the line using tildes.
152+ output += gutterStyleSequence + padLeft ( "" , gutterWidth ) + resetEscapeSequence + gutterSeparator ;
150153 output += redForegroundEscapeSequence ;
151154 if ( i === firstLine ) {
152155 // If we're on the last line, then limit it to the last character of the last line.
0 commit comments