diff --git a/main.py b/main.py index 15b1165..7ceff18 100644 --- a/main.py +++ b/main.py @@ -25,12 +25,30 @@ def get_usage() -> list[tuple]: return cmd_list -def display_usage(): +def clear_screen(): if os.name == 'nt': + # Windows system + try: + # try to reset the text attributes + kernel32 = ctypes.windll.kernel32 + handle = kernel32.GetStdHandle(-11) # STD_OUTPUT_HANDLE + kernel32.SetConsoleTextAttribute(handle, 7) + except Exception: + pass + os.system('cls') else: - os.system('clear') + # Unix-like system + clear_cmd = shutil.which('clear') + if clear_cmd: + os.system(clear_cmd) + else: + # backup plan: Use ANSI escape codes (to clear and reset the screen). + print('\033c', end='') + +def display_usage(): + clear_screen() for cmd, msg in get_usage(): print(f"{cmd}: {msg}")