refactor(printing): Improve handling of list printing

This commit is contained in:
2026-04-16 16:00:58 +02:00
parent 35c976fcac
commit 414c065df4
2 changed files with 64 additions and 0 deletions
+64
View File
@@ -0,0 +1,64 @@
from typing import List
import colorama as cl
from commands.util.printing.list import print_list
def print_diff(add: List[str], remove: List[str]):
if len(add) == 0 and len(remove) == 0:
print(
cl.Fore.BLUE
+ "-->"
+ cl.Style.DIM
+ cl.Fore.GREEN
+ " No packages changes"
+ cl.Style.RESET_ALL,
)
# Packages to be installed
if len(add) == 0:
print(
cl.Fore.BLUE
+ "-->"
+ cl.Style.DIM
+ cl.Fore.GREEN
+ " No packages to be installed"
+ cl.Style.RESET_ALL,
)
else:
print(
cl.Fore.GREEN + "==>",
cl.Style.RESET_ALL + "Packages that will be",
cl.Fore.GREEN + "installed" + cl.Style.RESET_ALL,
)
print_list(add)
print()
# Packages to be removed
if len(remove) == 0:
print(
cl.Fore.BLUE
+ "-->"
+ cl.Style.DIM
+ cl.Fore.GREEN
+ " No packages to be uninstalled"
+ cl.Style.RESET_ALL,
)
else:
print(
cl.Fore.GREEN + "==>",
cl.Style.RESET_ALL + "Packages that will be",
cl.Fore.RED + "uninstalled" + cl.Style.RESET_ALL,
)
print_list(remove)
print()
# Ask user to confirm
print(
cl.Fore.GREEN + "==>",
cl.Style.RESET_ALL
+ f"Transaction (packages): {cl.Fore.BLUE + str(len(add)) + cl.Style.RESET_ALL}",
cl.Fore.GREEN + "installed",
cl.Style.RESET_ALL
+ f"and {cl.Fore.BLUE + str(len(remove)) + cl.Style.RESET_ALL}",
cl.Fore.RED + "uninstalled" + cl.Style.RESET_ALL,
)
+20
View File
@@ -0,0 +1,20 @@
from typing import Any, List
import colorama as cl
def count_digits(number: int):
return len(str(number))
def print_list(list: List[Any]):
digit_count = count_digits(len(list))
for i, pkg in enumerate(list):
print(
" "
+ cl.Fore.BLUE
+ cl.Style.DIM
+ (" " * (digit_count - count_digits(i + 1)))
+ str(1 + i)
+ cl.Style.RESET_ALL + " ",
pkg,
)