refactor: cambio estructura de proyecto siguiendo guidelines de python
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import sys
|
||||
|
||||
|
||||
COLOR_BLACK = '\033[30m'
|
||||
COLOR_RED = '\033[31m'
|
||||
COLOR_GREEN = '\033[32m'
|
||||
COLOR_YELLOW = '\033[33m'
|
||||
COLOR_BLUE = '\033[34m'
|
||||
COLOR_BLACK_BOLD = '\033[1;30m'
|
||||
COLOR_RESET = '\033[0m'
|
||||
|
||||
|
||||
def confirm(prompt, default: bool = True):
|
||||
user_input = input(prompt + (" [Y/n]: " if default else " [y/N]: "))
|
||||
|
||||
return default if len(user_input) == 0 else user_input.startswith("y")
|
||||
|
||||
|
||||
def choose(prompt: str, options: list[str]):
|
||||
print(prompt)
|
||||
|
||||
for i, option in enumerate(options):
|
||||
print(f"\t{i+1}. {option}")
|
||||
|
||||
selection = None
|
||||
|
||||
while selection is None:
|
||||
user_input = input(f"Seleccione una opción [1-{len(options)}] o escribala: ")
|
||||
|
||||
if user_input.isdigit():
|
||||
user_input = int(user_input)
|
||||
|
||||
if 1 <= user_input and user_input <= len(options):
|
||||
selection = options[user_input - 1]
|
||||
|
||||
if not confirm(
|
||||
f"Seleccionó la opción {user_input} ({selection}), ¿es correcto?"
|
||||
):
|
||||
selection = None
|
||||
else:
|
||||
print_error(f"La opción {user_input} está fuera del rango permitido.")
|
||||
elif user_input in options:
|
||||
selection = user_input
|
||||
else:
|
||||
print_error(f"La opción '{user_input}' es inválida.")
|
||||
|
||||
return selection
|
||||
|
||||
|
||||
def print_error(message: str):
|
||||
print(f"{COLOR_RED}[err] {message}{COLOR_RESET}", file=sys.stderr)
|
||||
|
||||
|
||||
def print_warning(message: str):
|
||||
print(f"{COLOR_YELLOW}[wrn] {message}{COLOR_RESET}")
|
||||
|
||||
def print_success(message: str):
|
||||
print(f"{COLOR_GREEN}[ok!] {message}{COLOR_RESET}")
|
||||
|
||||
def print_info(message: str):
|
||||
print(f"{COLOR_BLUE}[inf] {message}{COLOR_RESET}")
|
||||
|
||||
def print_debug(message: str):
|
||||
print(f"{COLOR_BLACK_BOLD}[dbg] {message}{COLOR_RESET}")
|
||||
Reference in New Issue
Block a user