feat: printing utils
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from typing import Optional
|
||||
import getpass
|
||||
import time
|
||||
import colorama
|
||||
|
||||
|
||||
def choice(default: str, options: str, msg: str) -> str:
|
||||
@@ -42,5 +43,8 @@ def password(msg: str = ""):
|
||||
return pw
|
||||
else:
|
||||
time.sleep(1)
|
||||
print("Error: Password cannot be empty")
|
||||
print(
|
||||
colorama.Fore.RED + "Error:",
|
||||
colorama.Style.RESET_ALL + "Password cannot be empty",
|
||||
)
|
||||
return password(msg)
|
||||
|
||||
@@ -13,6 +13,15 @@ def list_explicitly_installed() -> List[str]:
|
||||
return run_pkg_manager_cmd(["-Qeq"]).stdout.split()
|
||||
|
||||
|
||||
def remove_orphans() -> bool:
|
||||
"""Removes all orphan packages
|
||||
|
||||
Returns:
|
||||
True if successful, False otherwise
|
||||
"""
|
||||
return sp.run("pacman -Qdtq | pacman -Rnsy -", capture_output=True).returncode == 0
|
||||
|
||||
|
||||
def uninstall_package_list(pkgs: List[str]) -> bool:
|
||||
"""Uninstall all packages in the list
|
||||
|
||||
|
||||
@@ -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)))
|
||||
+ str(i)
|
||||
+ cl.Style.RESET_ALL + " ",
|
||||
pkg,
|
||||
)
|
||||
Reference in New Issue
Block a user