Skip to content

Commit

Permalink
Change error displaying and add colors!
Browse files Browse the repository at this point in the history
- "source_file.c: Error!" becomes "[KO] source_file.c"
- The "[OK]" and "[KO]" is colored (red or green)
- The "Error:" lines are red
- The "Notice:" lines are yellow
  • Loading branch information
mcolonna committed Feb 29, 2024
1 parent a9e1a3d commit 36e42dc
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions norminette/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,24 @@ def __init_subclass__(cls) -> None:

class HumanizedErrorsFormatter(_formatter):
def __str__(self) -> str:

def colorize(status: Literal["OK", "Error", "Notice"], txt: str) -> str:
return "\033[9" + (
"1" if status == "Error" else (
"2" if status == "OK" else "3"
)) + "m" + txt + "\033[0m"

output = ''
for file in self.files:
output += f"{file.basename}: {file.errors.status}!"
status = file.errors.status
output += colorize(status, f"[{'OK' if status == 'OK' else 'KO'}]")
output += f" {file.basename}"
for error in file.errors:
highlight = error.highlights[0]
output += f"\n{error.level}: {error.name:<20} "
output += f"(line: {highlight.lineno:>3}, col: {highlight.column:>3}):\t{error.text}"
error_output = ""
error_output += f"\n{error.level}: {error.name:<20} "
error_output += f"(line: {highlight.lineno:>3}, col: {highlight.column:>3}):\t{error.text}"
output += colorize(error.level, error_output)
output += '\n'
return output

Expand Down

0 comments on commit 36e42dc

Please sign in to comment.