mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2025-01-05 11:02:14 +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:
|
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:
|
try:
|
||||||
""" Load the configs from the file. """
|
""" Load the configs from the file. """
|
||||||
config_path_file = Path(path, f'{file}.toml')
|
config_path_file = Path(path, f'{file}.toml')
|
||||||
|
@ -18,14 +25,26 @@ class LoadConfigs:
|
||||||
with open(config_path_file, 'rb') as conf:
|
with open(config_path_file, 'rb') as conf:
|
||||||
return tomli.load(conf)
|
return tomli.load(conf)
|
||||||
except tomli.TOMLDecodeError as error:
|
except tomli.TOMLDecodeError as error:
|
||||||
raise SystemExit(f"\nError: {error}: in the configuration file "
|
raise SystemExit(f"\n[{self.bred}Error{self.endc}]: {error}: in the configuration file "
|
||||||
"'/etc/slpkg/slpkg.toml'\n")
|
"'/etc/slpkg/slpkg.toml'\n")
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Configs:
|
class Configs:
|
||||||
""" Default configurations. """
|
""" 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.
|
# Programme name.
|
||||||
prog_name: str = 'slpkg'
|
prog_name: str = 'slpkg'
|
||||||
|
|
||||||
|
@ -174,7 +193,8 @@ class Configs:
|
||||||
file_pattern_conf: str = config['FILE_PATTERN']
|
file_pattern_conf: str = config['FILE_PATTERN']
|
||||||
|
|
||||||
except KeyError as error:
|
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"\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")
|
f"mv {etc_path}/{prog_name}.toml.new {etc_path}/{prog_name}.toml\n")
|
||||||
|
|
||||||
|
@ -199,29 +219,19 @@ class Configs:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def colour(cls) -> dict:
|
def colour(cls) -> dict:
|
||||||
color = {
|
|
||||||
'bold': '',
|
|
||||||
'red': '',
|
|
||||||
'green': '',
|
|
||||||
'yellow': '',
|
|
||||||
'cyan': '',
|
|
||||||
'blue': '',
|
|
||||||
'grey': '',
|
|
||||||
'violet': '',
|
|
||||||
'endc': ''
|
|
||||||
}
|
|
||||||
|
|
||||||
if cls.colors:
|
if not cls.colors:
|
||||||
color = {
|
|
||||||
'bold': '\033[1m',
|
cls.color = {
|
||||||
'red': '\x1b[91m',
|
'bold': '',
|
||||||
'green': '\x1b[32m',
|
'red': '',
|
||||||
'yellow': '\x1b[93m',
|
'green': '',
|
||||||
'cyan': '\x1b[96m',
|
'yellow': '',
|
||||||
'blue': '\x1b[94m',
|
'cyan': '',
|
||||||
'grey': '\x1b[38;5;247m',
|
'blue': '',
|
||||||
'violet': '\x1b[35m',
|
'grey': '',
|
||||||
'endc': '\x1b[0m'
|
'violet': '',
|
||||||
|
'endc': ''
|
||||||
}
|
}
|
||||||
|
|
||||||
return color
|
return cls.color
|
||||||
|
|
|
@ -31,6 +31,7 @@ from slpkg.update_repository import UpdateRepository
|
||||||
class Argparse(Configs):
|
class Argparse(Configs):
|
||||||
|
|
||||||
def __init__(self, args: list):
|
def __init__(self, args: list):
|
||||||
|
super(Configs).__init__()
|
||||||
self.args: list = args
|
self.args: list = args
|
||||||
self.flags: list = []
|
self.flags: list = []
|
||||||
self.directory = self.tmp_slpkg
|
self.directory = self.tmp_slpkg
|
||||||
|
|
Loading…
Reference in a new issue