Skip to content

Instantly share code, notes, and snippets.

@KXTOD
Created May 2, 2022 17:28
Show Gist options
  • Save KXTOD/2269fa69b7cc25006842d2011ef894b4 to your computer and use it in GitHub Desktop.
Save KXTOD/2269fa69b7cc25006842d2011ef894b4 to your computer and use it in GitHub Desktop.
test for windows
import sys
from rich.console import Console
from rich import print
from time import sleep
console = Console()
class BetterPrint:
def __init__(self, logLevel):
self.logLevel = logLevel
self.prep = "[*]"
self.color = None
def checkColors(self):
if self.logLevel == "BASIC":
self.colorStart = "[bold green1]"
self.colorEnd = "[/bold green1]"
self.prep = f"{self.colorStart}[:bulb:]{self.colorEnd}"
elif self.logLevel == "WARNING":
self.colorStart = "[bold orange1]"
self.colorEnd = "[/bold orange1]"
self.prep = f"{self.colorStart}[:warning:]{self.colorEnd}"
elif self.logLevel == "ERROR":
self.colorStart = "[bold red1]"
self.colorEnd = "[/bold red1]"
self.prep = f"{self.colorStart}[:cross_mark:]{self.colorEnd}"
else:
self.colorStart = "[white]"
self.colorEnd = "[/white]"
self.prep = f"{self.colorStart}[:information:]{self.colorEnd}"
def bprint(self, message):
self.checkColors()
console.print(f"\r{self.prep} [bold bright_white]{message}[/bold bright_white]")
def printAndClear(self, message):
console.clear()
self.checkColors()
console.print(f"\r{self.prep} [bold bright_white]{message}[/bold bright_white]")
warn = BetterPrint(logLevel="BASIC")
warn.printAndClear("sdfsdf")
sleep(5)
warn.logLevel = "ERROR"
warn.printAndClear("fEROROR")
sleep(5)
warn.logLevel = "WARNING"
warn.printAndClear("WARNING AAAAH")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment