From fb565d64ada6d2ee319e1ebc226474e1cd60fe4e Mon Sep 17 00:00:00 2001 From: SimonFJ20 Date: Tue, 18 Mar 2025 15:59:46 +0100 Subject: [PATCH] colored caret --- main.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/main.ts b/main.ts index 287d225..ea7b878 100644 --- a/main.ts +++ b/main.ts @@ -397,27 +397,28 @@ class Reporter { public info(msg: string, loc?: ast.Loc) { console.error( - `%cerror%c: ${msg}%c`, + `%cinfo%c: ${msg}%c`, "color: cyan; font-weight: bold", "font-weight: bold", "", ); 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 posPad = " ".repeat(loc.start.column - 1); const lineNr = loc.start.line.toString().padStart(3, " "); const lPad = " ".repeat(lineNr.length + 1); const pos = `./${loc.source}:${loc.start.line}:${loc.start.column}`; 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: lightgray", "color: gray", + `color: ${caretColor}; font-weight: bold`, "", ); }