From a88f7fb5a97ec46ed80ed394c135faa787a748f1 Mon Sep 17 00:00:00 2001 From: yroussea <113770386+yroussea@users.noreply.github.com> Date: Thu, 20 Jun 2024 17:32:31 +0200 Subject: [PATCH] add colors to the norminette (#492) colors can be change/customize form the norinette/colors file, only few colors can be use, and not all the line is painted to avoid using invisible line trick --- norminette/colors.py | 44 ++++++++++++++++++++++++++++++++++++++++ norminette/norm_error.py | 21 ++++++++++++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 norminette/colors.py diff --git a/norminette/colors.py b/norminette/colors.py new file mode 100644 index 0000000..3820e33 --- /dev/null +++ b/norminette/colors.py @@ -0,0 +1,44 @@ +red = { + "TOO_MANY_ARGS", + "TOO_MANY_VARS_FUNC", +} +yellow = { + "MIXED_SPACE_TAB", + "BRACE_NEWLINE" +} +green = { + "TOO_MANY_FUNCS", +} +blue = { + "SPC_INSTEAD_TAB", + "TAB_INSTEAD_SPC", + "CONSECUTIVE_SPC", + "CONSECUTIVE_WS", + "SPC_BFR_OPERATOR", + "SPC_AFTER_OPERATOR", + "NO_SPC_BFR_OPR", + "NO_SPC_AFR_OPR", + "SPC_AFTER_PAR", + "SPC_BFR_PAR", + "NO_SPC_AFR_PAR", + "NO_SPC_BFR_PAR", + "SPC_AFTER_POINTER", + "SPC_LINE_START", + "SPC_BFR_POINTER", + "SPACE_BEFORE_FUNC", + "TOO_MANY_TABS_FUNC", + "TOO_MANY_TABS_TD", + "MISSING_TAB_FUNC", + "MISSING_TAB_VAR", + "TOO_MANY_TAB_VAR", + "LINE_TOO_LONG", + "EXP_PARENTHESIS", +} +pink = { + "WRONG_SCOPE_COMMENT", + "COMMENT_ON_INSTR", +} +grey = { + "INVALID_HEADER", + "WRONG_SCOPE_COMMENT", +} diff --git a/norminette/norm_error.py b/norminette/norm_error.py index e62211a..25b8666 100644 --- a/norminette/norm_error.py +++ b/norminette/norm_error.py @@ -1,4 +1,6 @@ -errors = { +from norminette.colors import red, blue, yellow, pink, grey, green + +errors = { "SPC_INSTEAD_TAB": "Spaces at beginning of line", "TAB_INSTEAD_SPC": "Found tab when expecting space", "CONSECUTIVE_SPC": "Two or more consecutives spaces", @@ -150,11 +152,28 @@ def __init__(self, errno, line, col): self.error_pos = f"(line: {(str(self.line)).rjust(3)}, col: {(str(self.col)).rjust(3)}):\t" self.prefix = f"Error: {self.errno:<20} {self.error_pos:>21}" self.error_msg = f"{errors.get(self.errno, 'ERROR NOT FOUND')}" + self.no_color = "\033[0m" + self.color = self.no_color + color = { + "\033[91m":red, + "\033[92m":green, + "\033[93m":yellow, + "\033[94m":blue, + "\033[95m":pink, + "\033[97m":grey, + } + for key,value in color.items(): + if errno in value: + self.color = key + break + self.prefix = self.prefix + self.error_msg = self.color + self.error_msg + self.no_color def __str__(self): return self.prefix + self.error_msg + class NormWarning: def __init__(self, errno, line, col): self.errno = errno