mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-16 05:58:32 -06:00
Stylize gutter.
This commit is contained in:
parent
ea1882d76d
commit
44f3c0ca8a
@ -106,8 +106,9 @@ namespace ts {
|
||||
sys.write(output);
|
||||
}
|
||||
|
||||
const redColorControlChar = "\u001b[91m";
|
||||
const resetColorControlChar = "\u001b[0m";
|
||||
const redForegroundEscapeSequence = "\u001b[91m";
|
||||
const gutterStyleSequence = "\u001b[100;30m";
|
||||
const resetEscapeSequence = "\u001b[0m";
|
||||
|
||||
function reportDiagnosticWithColorAndContext(diagnostic: Diagnostic): void {
|
||||
let output = "";
|
||||
@ -129,7 +130,7 @@ namespace ts {
|
||||
// If the error spans over 5 lines, we'll only show the first 2 and last 2 lines,
|
||||
// so we'll skip ahead to the second-to-last line.
|
||||
if (hasMoreThanFiveLines && firstLine + 1 < i && i < lastLine - 1) {
|
||||
output += padLeft("...", gutterWidth) + " ||" + sys.newLine;
|
||||
output += gutterStyleSequence + padLeft("...", gutterWidth) + resetEscapeSequence + " " + sys.newLine;
|
||||
i = lastLine - 1;
|
||||
}
|
||||
|
||||
@ -140,11 +141,11 @@ namespace ts {
|
||||
lineContent = lineContent.replace("\t", " "); // convert tabs to single spaces
|
||||
|
||||
// Output the actual contents of the line.
|
||||
output += padLeft(i + 1 + "", gutterWidth) + " ||" + lineContent + sys.newLine;
|
||||
output += gutterStyleSequence + padLeft(i + 1 + "", gutterWidth) + resetEscapeSequence + " " + lineContent + sys.newLine;
|
||||
|
||||
// Output the error span for the line using tildes.
|
||||
output += padLeft("", gutterWidth) + " ||";
|
||||
output += redColorControlChar;
|
||||
output += gutterStyleSequence + padLeft("", gutterWidth) + resetEscapeSequence + " ";
|
||||
output += redForegroundEscapeSequence;
|
||||
if (i === firstLine) {
|
||||
// If we're on the last line, then limit it to the last character of the last line.
|
||||
// Otherwise, we'll just squiggle the rest of the line, giving 'slice' no end position.
|
||||
@ -160,7 +161,7 @@ namespace ts {
|
||||
// Squiggle the entire line.
|
||||
output += lineContent.replace(/./g, "~");
|
||||
}
|
||||
output += resetColorControlChar;
|
||||
output += resetEscapeSequence;
|
||||
|
||||
output += sys.newLine;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user