From 34e503314f2e889961de7a5f5ae74e73583ab49e Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Tue, 16 May 2023 22:39:05 +0300 Subject: [PATCH] Added border color --- ChangeLog.txt | 1 + configs/slpkg.toml | 6 ++++++ slpkg/configs.py | 8 +++++++- slpkg/views/asciibox.py | 45 +++++++++++++++++++++++++++++++---------- 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index d4686088..9f3e1852 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,6 +1,7 @@ 4.8.4 - 14/05/2023 Added: - Case-insensitive pattern matching, --no-case option +- Choose border color via configuration file 4.8.3 - 29/04/2023 Updated: diff --git a/configs/slpkg.toml b/configs/slpkg.toml index 8b5fd75b..037ed964 100644 --- a/configs/slpkg.toml +++ b/configs/slpkg.toml @@ -55,6 +55,12 @@ PROGRESS_SPINNER = "pixel" # Default is green. [green/violet/yellow/blue/cyan/grey/red] SPINNER_COLOR = "green" +# Choose color for the border box. +# Bold colors: [bold_green/bold_cyan/bold_yellow/bold_red/bold_blue] +# Colors: [green/cyan/yellow/red/blue] +# Default is bold_green. +BORDER_COLOR = "bold_green" + # Enable or disable case-sensitive pattern matching. # Default is true. [true/false] CASE_SENSITIVE = true diff --git a/slpkg/configs.py b/slpkg/configs.py index 5cb82f7e..9b82c9b6 100644 --- a/slpkg/configs.py +++ b/slpkg/configs.py @@ -46,6 +46,7 @@ class Configs: spinning_bar: str = True progress_spinner: str = 'pixel' spinner_color: str = 'green' + border_color: str = 'bgreen' case_sensitive: bool = True proxy_address: str = str() @@ -83,6 +84,7 @@ class Configs: spinning_bar: str = config['SPINNING_BAR'] progress_spinner: str = config['PROGRESS_SPINNER'] spinner_color: str = config['SPINNER_COLOR'] + border_color: str = config['BORDER_COLOR'] case_sensitive: bool = config['CASE_SENSITIVE'] proxy_address: str = config['PROXY_ADDRESS'] proxy_username: str = config['PROXY_USERNAME'] @@ -100,7 +102,9 @@ class Configs: yellow: str = str() byellow: str = str() cyan: str = str() + bcyan: str = str() blue: str = str() + bblue: str = str() grey: str = str() violet: str = str() endc: str = str() @@ -115,7 +119,9 @@ class Configs: yellow: str = '\x1b[93m' byellow: str = f'{bold}{yellow}' cyan: str = '\x1b[96m' - blue: str = '\x1b[94m' + bcyan: str = f'{bold}{cyan}' + blue: str = f'\x1b[94m' + bblue: str = f'{bold}{blue}' grey: str = '\x1b[38;5;247m' violet: str = '\x1b[35m' endc: str = '\x1b[0m' diff --git a/slpkg/views/asciibox.py b/slpkg/views/asciibox.py index 650a4815..7e7e2640 100644 --- a/slpkg/views/asciibox.py +++ b/slpkg/views/asciibox.py @@ -19,6 +19,10 @@ class AsciiBox(Configs): if self.package_alignment < 1: self.package_alignment = 1 + self.bd_color: str = self.endc + self.border_colors: dict = {} + self.assign_border_color() + self.bullet: str = '-' self.done: str = 'Done' self.vertical_line: str = '|' @@ -48,38 +52,57 @@ class AsciiBox(Configs): self.vertical_and_right: str = '├' self.vertical_and_left: str = '┤' + def assign_border_color(self): + self.border_colors: dict[str] = { + 'bold_yellow': self.byellow, + 'bold_green': self.bgreen, + 'bold_cyan': self.bcyan, + 'bold_blue': self.bblue, + 'bold_red': self.bred, + 'yellow': self.yellow, + 'green': self.green, + 'cyan': self.cyan, + 'blue': self.blue, + 'red': self.red, + '': self.endc + } + try: + self.bd_color: str = self.border_colors[self.border_color] + except KeyError: + self.bd_color: str = self.endc + def draw_package_title(self, message: str, title: str) -> None: title = title.title() - print(f"{self.bgreen}{self.upper_left_corner}{self.horizontal_line * (self.columns - 2)}" + print(f"{self.bd_color}{self.upper_left_corner}{self.horizontal_line * (self.columns - 2)}" f"{self.upper_right_corner}") print(f"{self.vertical_line}{title.center(self.columns - 2, ' ')}{self.vertical_line}") self.draw_middle_line() print(f"{self.vertical_line} {self.endc}{message.ljust(self.columns - 3, ' ')}" - f"{self.bgreen}{self.vertical_line}") + f"{self.bd_color}{self.vertical_line}") self.draw_middle_line() - print(f"{self.bgreen}{self.vertical_line}{self.endc} {'Package:':<{self.package_alignment}}" + print(f"{self.bd_color}{self.vertical_line}{self.endc} {'Package:':<{self.package_alignment}}" f"{'Version:':<{self.version_alignment}}{'Size:':<{self.size_alignment}}{'Repo:':>{self.repo_alignment}} " - f"{self.bgreen}{self.vertical_line}{self.endc}") + f"{self.bd_color}{self.vertical_line}{self.endc}") def draw_package_line(self, package: str, version: str, size: str, color: str, repo: str) -> None: if len(version) >= 20 and self.columns <= 80: version: str = f'{version[:self.version_alignment - 5]}...' if len(package) >= 15 and self.columns <= 80: package: str = f'{package[:self.package_alignment - 5]}...' - print(f"{self.bgreen}{self.vertical_line} {self.bold}{color}{package:<{self.package_alignment}}{self.endc}" - f"{self.bgreen}{version:<{self.version_alignment}}{self.endc}{size:<{self.size_alignment}}{self.blue}" - f"{repo:>{self.repo_alignment}}{self.bgreen} {self.vertical_line}{self.endc}") + print(f"{self.bd_color}{self.vertical_line} {self.bold}{color}{package:<{self.package_alignment}}{self.endc}" + f"{self.bd_color}{version:<{self.version_alignment}}{self.endc}{size:<{self.size_alignment}}{self.blue}" + f"{repo:>{self.repo_alignment}}{self.bd_color} {self.vertical_line}{self.endc}") def draw_middle_line(self) -> None: - print(f"{self.bgreen}{self.vertical_and_right}{self.horizontal_line * (self.columns - 2)}" + print(f"{self.bd_color}{self.vertical_and_right}{self.horizontal_line * (self.columns - 2)}" f"{self.vertical_and_left}") def draw_dependency_line(self) -> None: - print(f"{self.bgreen}{self.vertical_line}{self.endc} Dependencies:{' ' * (self.columns - 16)}" - f"{self.bgreen}{self.vertical_line}{self.endc}") + print(f"{self.bd_color}{self.vertical_line}{self.endc} Dependencies:{' ' * (self.columns - 16)}" + f"{self.bd_color}{self.vertical_line}{self.endc}") def draw_bottom_line(self) -> None: - print(f"{self.bgreen}{self.lower_left_corner}{self.horizontal_line * (self.columns - 2)}" + print(f"{self.bd_color}{self.lower_left_corner}{self.horizontal_line * (self.columns - 2)}" f"{self.lower_right_corner}{self.endc}") def draw_checksum_error_box(self, name: str, checksum: str, file_check: str) -> None: