initial commit

This commit is contained in:
2025-08-31 13:48:32 +10:00
parent ea93fdb4f2
commit 0b6d74d3a9
5 changed files with 129 additions and 0 deletions

23
error.py Normal file
View File

@@ -0,0 +1,23 @@
from console import console
def traceback(code: str, error_type: str, error_message: str, line: int | None = None, start_column: int | None = None, end_column: int | None = None):
if line != None:
console.print(f"[bold red]{error_type} on line {line}: [/]{error_message}\n")
lines = code.split("\n")[line-1:line+2]
console.print(f"{line } > " + lines[0], highlight=False)
if start_column != None and end_column != None:
console.print(" " + (" " * start_column) + "[bold red]" + ("^" * (end_column-start_column+1)))
try:
console.print(f"{line+1} " + lines[1], highlight=False)
console.print(f"{line+2} " + lines[2], highlight=False)
console.print(" ...", highlight=False)
except IndexError: # the file is less than 3 lines i guess
pass
else:
console.print(f"[bold red]{error_type}: {error_message}")