microcore.ui
1from colorama import Fore, init 2from .utils import is_notebook 3 4if not is_notebook(): 5 init(autoreset=True) 6 7 8def info(*args, color=Fore.LIGHTYELLOW_EX, **kwargs): 9 print(*[color + i for i in args], **kwargs) 10 11 12def debug(msg): 13 info(msg, color=Fore.BLUE) 14 15 16def error(*args, **kwargs): 17 print(*[Fore.RED + i for i in args], **kwargs) 18 19 20def ask_yn(msg): 21 return "y" in input(msg + " (y/n)").lower().strip() 22 23 24def ask_choose(msg, variants: list): 25 i = 0 26 if isinstance(variants, list): 27 for item in variants: 28 i += 1 29 print(f"\t{Fore.MAGENTA}{i}:{Fore.RESET}\t{item}") 30 while True: 31 i = input(f"{msg} {Fore.MAGENTA}[1-{len(variants)}]{Fore.RESET}: ") 32 if not i.isdigit(): 33 error("Not a number") 34 continue 35 i = int(i) - 1 36 if i >= len(variants) or i < 0: 37 error("Incorrect number") 38 continue 39 break 40 41 item = variants[int(i)] 42 return item 43 44 45def magenta(msg): 46 return f"{Fore.MAGENTA}{msg}{Fore.RESET}" 47 48 49def yellow(msg): 50 return f"{Fore.YELLOW}{msg}{Fore.RESET}" 51 52 53def red(msg): 54 return f"{Fore.RED}{msg}{Fore.RESET}" 55 56 57def blue(msg): 58 return f"{Fore.BLUE}{msg}{Fore.RESET}" 59 60 61def green(msg): 62 return f"{Fore.GREEN}{msg}{Fore.RESET}" 63 64 65def cyan(msg): 66 return f"{Fore.CYAN}{msg}{Fore.RESET}" 67 68 69def white(msg): 70 return f"{Fore.WHITE}{msg}{Fore.RESET}" 71 72 73def gray(msg): 74 return f"\033[90m{msg}{Fore.RESET}" 75 76 77def black(msg): 78 return f"{Fore.BLACK}{msg}{Fore.RESET}"
def
info(*args, color='\x1b[93m', **kwargs):
def
debug(msg):
def
error(*args, **kwargs):
def
ask_yn(msg):
def
ask_choose(msg, variants: list):
25def ask_choose(msg, variants: list): 26 i = 0 27 if isinstance(variants, list): 28 for item in variants: 29 i += 1 30 print(f"\t{Fore.MAGENTA}{i}:{Fore.RESET}\t{item}") 31 while True: 32 i = input(f"{msg} {Fore.MAGENTA}[1-{len(variants)}]{Fore.RESET}: ") 33 if not i.isdigit(): 34 error("Not a number") 35 continue 36 i = int(i) - 1 37 if i >= len(variants) or i < 0: 38 error("Incorrect number") 39 continue 40 break 41 42 item = variants[int(i)] 43 return item
def
magenta(msg):
def
yellow(msg):
def
red(msg):
def
blue(msg):
def
green(msg):
def
cyan(msg):
def
white(msg):
def
gray(msg):
def
black(msg):