From 1fd54768457a61dc064600372940f757b98d1453 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 29 Jan 2023 22:25:29 +0200 Subject: [PATCH] Added config for ascii --- ChangeLog.txt | 1 + configs/slpkg.toml | 7 ++++++- slpkg/configs.py | 9 +++++++++ slpkg/form_configs.py | 4 ++-- slpkg/views/ascii.py | 35 ++++++++++++++++++++++++----------- 5 files changed, 42 insertions(+), 14 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 0133952f..0c9a93cd 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,6 +1,7 @@ 4.5.3 - 27/01/2023 Added: - Short options +- New configuration for ascii characters 4.5.2 - 21/01/2023 BugFixed: diff --git a/configs/slpkg.toml b/configs/slpkg.toml index 80db039b..f5e57f84 100644 --- a/configs/slpkg.toml +++ b/configs/slpkg.toml @@ -70,4 +70,9 @@ # If silent mode is true, # do not print the commands as they are executed. # Default is true. [true/false] - silent_mode = true \ No newline at end of file + silent_mode = true + + # Choose ascii printable characters. + # If true use the extended characters otherwise the basic ones. + # Default is true. [true/false] + ascii_characters = true \ No newline at end of file diff --git a/slpkg/configs.py b/slpkg/configs.py index 9d50423e..6856d953 100644 --- a/slpkg/configs.py +++ b/slpkg/configs.py @@ -77,6 +77,11 @@ class Configs: # Choose the view mode silent_mode: str = True + # Choose ascii characters. + # If True use extended else basic. + ascii_characters = True + + # Load configurations from the file. load = LoadConfigs() configs = load.file(etc_path, prog_name) config = configs['configs'] @@ -124,6 +129,10 @@ class Configs: # Choose the view mode silent_mode: str = config['silent_mode'] + + # Choose ascii characters. Extended or basic. + ascii_characters: str = config['ascii_characters'] + except KeyError as error: raise SystemExit(f"\nKeyError: {error}: in the configuration file '/etc/slpkg/slpkg.toml'.\n" f"\nIf you have upgraded the '{prog_name}' probably you need to run:\n" diff --git a/slpkg/form_configs.py b/slpkg/form_configs.py index d9400155..52a830c8 100644 --- a/slpkg/form_configs.py +++ b/slpkg/form_configs.py @@ -63,7 +63,7 @@ class FormConfigs(Configs): def check_configs(self, configs: dict, tags: list) -> bool: """ Check for true of false values. """ for key, value in zip(configs['configs'].keys(), tags): - if key in ['colors', 'dialog', 'silent_mode'] and value not in ['true', 'false']: + if key in ['colors', 'dialog', 'silent_mode', 'ascii_characters'] and value not in ['true', 'false']: self.dialogbox.msgbox(f"\nError value for {key}. It must be 'true' or 'false'\n", height=7, width=60) return False return True @@ -81,6 +81,6 @@ class FormConfigs(Configs): for key, value in zip(configs['configs'].keys(), tags): if line.lstrip().startswith(key): line = f' {key} = "{value}"\n' - if line.lstrip().startswith(('colors =', 'dialog =', 'silent_mode =')): + if line.lstrip().startswith(('colors =', 'dialog =', 'silent_mode =', 'ascii_characters =')): line = line.replace('"', '') patch_toml.write(line) diff --git a/slpkg/views/ascii.py b/slpkg/views/ascii.py index fb9a45b3..b1895f6b 100644 --- a/slpkg/views/ascii.py +++ b/slpkg/views/ascii.py @@ -10,17 +10,30 @@ class Ascii(Configs): """ ascii characters. """ def __init__(self): super(Configs, self).__init__() - self.vertical_line = '│' - self.horizontal_line = '─' - self.horizontal_vertical = '┼' - self.upper_right_corner = '┐' - self.lower_left_corner = '└' - self.lower_right_corner = '┘' - self.upper_left_corner = '┌' - self.horizontal_and_up = '┴' - self.horizontal_and_down = '┬' - self.vertical_and_right = '├' - self.vertical_and_left = '┤' + self.vertical_line = '|' + self.horizontal_line = '=' + self.horizontal_vertical = '+' + self.upper_right_corner = '+' + self.lower_left_corner = '+' + self.lower_right_corner = '+' + self.upper_left_corner = '+' + self.horizontal_and_up = '+' + self.horizontal_and_down = '+' + self.vertical_and_right = '+' + self.vertical_and_left = '+' + + if self.ascii_characters: + self.vertical_line = '│' + self.horizontal_line = '─' + self.horizontal_vertical = '┼' + self.upper_right_corner = '┐' + self.lower_left_corner = '└' + self.lower_right_corner = '┘' + self.upper_left_corner = '┌' + self.horizontal_and_up = '┴' + self.horizontal_and_down = '┬' + self.vertical_and_right = '├' + self.vertical_and_left = '┤' self.color = self.colour() self.bold = self.color['bold']