mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2025-01-03 06:56:44 +01:00
Updated for colors
This commit is contained in:
parent
40831542e9
commit
095cfb0942
2 changed files with 39 additions and 28 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue