errors: Fix caret when tabs are present

Replace all tabs with two spaces and account for that when positioning
the caret under the error location.
This commit is contained in:
James Westman 2024-07-26 22:13:51 -05:00
parent 9570dceaa8
commit 2dcf0c154b

View file

@ -98,10 +98,13 @@ class CompileError(PrintableError):
# Display 1-based line numbers
line_num += 1
removed_tabs = line.count("\t", 0, col_num - 1)
line = line.replace("\t", " ")
stream.write(
f"""{self.color}{Colors.BOLD}{self.category}: {self.message}{Colors.CLEAR}
at {filename} line {line_num} column {col_num}:
{Colors.FAINT}{line_num :>4} |{Colors.CLEAR}{line.rstrip()}\n {Colors.FAINT}|{" "*(col_num-1)}^{Colors.CLEAR}\n"""
{Colors.FAINT}{line_num :>4} |{Colors.CLEAR}{line.rstrip()}\n {Colors.FAINT}|{" "*(col_num-1+removed_tabs)}^{Colors.CLEAR}\n"""
)
for hint in self.hints: