Created
May 11, 2022 14:09
-
-
Save lafftar/32266d2ac6f2a6213901ed8752f306f9 to your computer and use it in GitHub Desktop.
terminal.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from datetime import datetime | |
from os import system | |
from typing import Any | |
from colorama import Back, Style, Fore | |
def update_title(terminal_title, force: bool = False): | |
if not force: | |
return | |
bot_name = 'hCapBP' | |
t = datetime.now().strftime('%H:%M:%S') | |
if sys.platform == 'linux': | |
print(f'\33]0;[{bot_name}] [{t}]| {terminal_title}\a', end='', flush=True) | |
if sys.platform == 'win32': | |
import ctypes | |
ctypes.windll.kernel32.SetConsoleTitleW(f'[{bot_name}] [{t}]| {terminal_title}') | |
def clear(): | |
if sys.platform == 'linux': | |
system("clear") | |
if sys.platform == 'win32': | |
system("cls") | |
def color_wrap(text: [str, int, float, Any], fore_color: str = Fore.WHITE, back_color: str = Back.LIGHTBLACK_EX) -> str: | |
""" | |
:param fore_color: really a AnsiCodes/AnsiBack | |
:param back_color: really a AnsiCodes/AnsiBack | |
:param text: stuff that can be transformed to string | |
:return: your wrapped string | |
""" | |
return f'{Style.RESET_ALL}{Style.BRIGHT}{back_color}{fore_color}{text}{Style.BRIGHT}{Style.RESET_ALL}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment