Updated for auto alignment

This commit is contained in:
Dimitris Zlatanidis 2023-05-12 13:08:55 +03:00
parent 78389ed5d2
commit a0324a11a6

View file

@ -11,7 +11,13 @@ class Ascii(Configs):
def __init__(self):
super(Configs, self).__init__()
self.columns, self.rows = shutil.get_terminal_size()
self.auto_alignment: int = (self.columns - 80) + 30
self.package_alignment: int = (self.columns - 80) + 25
self.version_alignment: int = 27
self.size_alignment: int = 14
self.repo_alignment: int = 10
if self.package_alignment < 1:
self.package_alignment = 1
self.vertical_line: str = '|'
self.horizontal_line: str = '='
@ -41,31 +47,28 @@ class Ascii(Configs):
def draw_package_title_box(self, message: str, title: str) -> None:
""" Drawing package title box. """
title = title.title()
print(f'{self.bgreen}{self.upper_left_corner}' + f'{self.horizontal_line}' * (self.columns - 2) + f'{self.upper_right_corner}')
print(f'{self.bgreen}{self.upper_left_corner}' + f'{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}')
self.draw_middle_line()
print(f'{self.vertical_line} {self.endc}{message.ljust(self.columns - 3, " ")}{self.bgreen}{self.vertical_line}')
self.draw_middle_line()
print(f"{self.bgreen}{self.vertical_line}{self.endc} {'Package:':<{self.auto_alignment}}{'Version:':<22}{'Size:':<14}{'Repo:':>10} {self.bgreen}{self.vertical_line}{self.endc}")
exit()
print(f"{self.bgreen}{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}")
def draw_package_line(self, package: str, version: str, size: str, color: str, repo: str) -> None:
""" Draw nad print the packages. """
if len(version) >= 11 and self.columns <= 80:
version: str = f'{version[:10]}...'
if len(package) >= 25:
package: str = f'{package[:24]}...'
print(f'{self.bgreen}{self.vertical_line} {self.bold}{color}{package}{self.endc}' + ' ' * (30 - len(package)) +
f'{self.bgreen}{version}' + ' ' * ((self.columns - 53) - len(version) - len(size)) +
f'{self.endc}{size}' + ' ' * (19 - len(repo)) +
f'{self.blue}{repo} {self.bgreen}{self.vertical_line}{self.endc}')
if len(package) >= 10 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}")
def draw_log_package(self, package: str) -> None:
""" Drawing and print logs packages. """