diff --git a/slpkg/configs.py b/slpkg/configs.py index 5247841e..e7f6df8e 100644 --- a/slpkg/configs.py +++ b/slpkg/configs.py @@ -9,8 +9,15 @@ from dataclasses import dataclass class LoadConfigs: - @staticmethod - def file(path: str, file: str) -> dict: # type: ignore + + def __init__(self): + bold = '\033[1m' + red = '\x1b[91m' + + self.endc: str = '\x1b[0m' + self.bred: str = f'{bold}{red}' + + def file(self, path: str, file: str) -> dict: # type: ignore try: """ Load the configs from the file. """ config_path_file = Path(path, f'{file}.toml') @@ -18,14 +25,26 @@ class LoadConfigs: with open(config_path_file, 'rb') as conf: return tomli.load(conf) except tomli.TOMLDecodeError as error: - raise SystemExit(f"\nError: {error}: in the configuration file " - "'/etc/slpkg/slpkg.toml'\n") + raise SystemExit(f"\n[{self.bred}Error{self.endc}]: {error}: in the configuration file " + "'/etc/slpkg/slpkg.toml'\n") @dataclass class Configs: """ Default configurations. """ + color = { + 'bold': '\033[1m', + 'red': '\x1b[91m', + 'green': '\x1b[32m', + 'yellow': '\x1b[93m', + 'cyan': '\x1b[96m', + 'blue': '\x1b[94m', + 'grey': '\x1b[38;5;247m', + 'violet': '\x1b[35m', + 'endc': '\x1b[0m' + } + # Programme name. prog_name: str = 'slpkg' @@ -174,7 +193,8 @@ class Configs: file_pattern_conf: str = config['FILE_PATTERN'] except KeyError as error: - raise SystemExit(f"\nError: {error}: in the configuration file '/etc/slpkg/slpkg.toml'.\n" + raise SystemExit(f"\n[{color['bold']}{color['red']}Error{color['endc']}]: " + f"{error}: in the configuration file '/etc/slpkg/slpkg.toml'.\n" f"\nIf you have upgraded the '{prog_name}' probably you need to run:\n" f"mv {etc_path}/{prog_name}.toml.new {etc_path}/{prog_name}.toml\n") @@ -199,29 +219,19 @@ class Configs: @classmethod def colour(cls) -> dict: - color = { - 'bold': '', - 'red': '', - 'green': '', - 'yellow': '', - 'cyan': '', - 'blue': '', - 'grey': '', - 'violet': '', - 'endc': '' - } - if cls.colors: - color = { - 'bold': '\033[1m', - 'red': '\x1b[91m', - 'green': '\x1b[32m', - 'yellow': '\x1b[93m', - 'cyan': '\x1b[96m', - 'blue': '\x1b[94m', - 'grey': '\x1b[38;5;247m', - 'violet': '\x1b[35m', - 'endc': '\x1b[0m' + if not cls.colors: + + cls.color = { + 'bold': '', + 'red': '', + 'green': '', + 'yellow': '', + 'cyan': '', + 'blue': '', + 'grey': '', + 'violet': '', + 'endc': '' } - return color + return cls.color diff --git a/slpkg/main.py b/slpkg/main.py index 98c06338..83b0c219 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -31,6 +31,7 @@ from slpkg.update_repository import UpdateRepository class Argparse(Configs): def __init__(self, args: list): + super(Configs).__init__() self.args: list = args self.flags: list = [] self.directory = self.tmp_slpkg