import os import sys from colorama import Style, Fore def printError(message): print(f'{Fore.RED}[Error] - {message}{Style.RESET_ALL}') def printWarning(message): print(f'{Fore.YELLOW}[Warning] - {message}{Style.RESET_ALL}') def printInfo(message): print(f'{Fore.BLUE}[Info] - {message}{Style.RESET_ALL}') def printSuccess(message): print(f'{Fore.GREEN}[Success] - {message}{Style.RESET_ALL}') class TerminalInterface: schedule = [] @staticmethod def clearTerminal(): if os.name == 'nt': _ = os.system('cls') else: _ = os.system('clear') @staticmethod def setPos(x, y): sys.stdout.write("\x1b[%d;%df%s" % (x, y, "")) sys.stdout.flush() @staticmethod def printPos(x, y, message): terminal_width = os.get_terminal_size().columns whitespace_count = terminal_width - len(message) - y sys.stdout.write("\x1b[%d;%df%s" % (x, y, message + ' ' * whitespace_count)) sys.stdout.flush() @staticmethod def runInterfaceSchedule(): if TerminalInterface.schedule: for x in TerminalInterface.schedule: TerminalInterface.setPos(x[1], 1) if x[0] == "Error": print(Fore.RED + "[Error] ") TerminalInterface.printPos(x[1], 9, x[2]) elif x[0] == "Warning": print(Fore.YELLOW + "[Warning] ") TerminalInterface.printPos(x[1], 11, x[2]) elif x[0] == "Info": print(Fore.BLUE + "[Info] ") TerminalInterface.printPos(x[1], 8, x[2]) elif x[0] == "Success": print(Fore.GREEN + "[Success] ") TerminalInterface.printPos(x[1], 11, x[2]) print(Style.RESET_ALL) sys.stdout.flush() TerminalInterface.setPos(x[1]-1, 1) TerminalInterface.schedule.remove(x) @staticmethod def appendInterface(status, message, line): TerminalInterface.schedule.append([status, line, message])