colored caret
This commit is contained in:
parent
b805d9b48f
commit
fb565d64ad
9
main.ts
9
main.ts
@ -397,27 +397,28 @@ class Reporter {
|
|||||||
|
|
||||||
public info(msg: string, loc?: ast.Loc) {
|
public info(msg: string, loc?: ast.Loc) {
|
||||||
console.error(
|
console.error(
|
||||||
`%cerror%c: ${msg}%c`,
|
`%cinfo%c: ${msg}%c`,
|
||||||
"color: cyan; font-weight: bold",
|
"color: cyan; font-weight: bold",
|
||||||
"font-weight: bold",
|
"font-weight: bold",
|
||||||
"",
|
"",
|
||||||
);
|
);
|
||||||
if (loc) {
|
if (loc) {
|
||||||
this.printLoc(loc);
|
this.printLoc(loc, "cyan");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private printLoc(loc: ast.Loc) {
|
private printLoc(loc: ast.Loc, caretColor = "red") {
|
||||||
const line = this.text.split("\n")[loc.start.line - 1];
|
const line = this.text.split("\n")[loc.start.line - 1];
|
||||||
const posPad = " ".repeat(loc.start.column - 1);
|
const posPad = " ".repeat(loc.start.column - 1);
|
||||||
const lineNr = loc.start.line.toString().padStart(3, " ");
|
const lineNr = loc.start.line.toString().padStart(3, " ");
|
||||||
const lPad = " ".repeat(lineNr.length + 1);
|
const lPad = " ".repeat(lineNr.length + 1);
|
||||||
const pos = `./${loc.source}:${loc.start.line}:${loc.start.column}`;
|
const pos = `./${loc.source}:${loc.start.line}:${loc.start.column}`;
|
||||||
console.error(
|
console.error(
|
||||||
`%c --> ${pos}\n${lPad}|\n${lineNr} |%c${line}%c\n${lPad}|${posPad}^%c`,
|
`%c --> ${pos}\n${lPad}|\n${lineNr} |%c${line}%c\n${lPad}|${posPad}%c^%c`,
|
||||||
"color: gray",
|
"color: gray",
|
||||||
"color: lightgray",
|
"color: lightgray",
|
||||||
"color: gray",
|
"color: gray",
|
||||||
|
`color: ${caretColor}; font-weight: bold`,
|
||||||
"",
|
"",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user