49 lines
1.1 KiB
Python
49 lines
1.1 KiB
Python
|
|
from enum import Enum
|
||
|
|
|
||
|
|
class Color(Enum):
|
||
|
|
Black = 0
|
||
|
|
Red = 1
|
||
|
|
Green = 2
|
||
|
|
Yellow = 3
|
||
|
|
Blue = 4
|
||
|
|
Magenta = 5
|
||
|
|
Cyan = 6
|
||
|
|
White = 7
|
||
|
|
|
||
|
|
# escape sequence format string
|
||
|
|
__fescseq = '\033[3{0}m'
|
||
|
|
# ansi reset code
|
||
|
|
__ansi_rst = '\033[0m'
|
||
|
|
|
||
|
|
__ansi_black = '\033[30m'
|
||
|
|
__ansi_red = '\033[31m'
|
||
|
|
__ansi_green = '\033[32m'
|
||
|
|
__ansi_yellow = '\033[33m'
|
||
|
|
__ansi_blue = '\033[34m'
|
||
|
|
__ansi_magenta = '\033[35m'
|
||
|
|
__ansi_cyan= '\033[36m'
|
||
|
|
__ansi_white = '\033[37m'
|
||
|
|
|
||
|
|
@staticmethod
|
||
|
|
def _ansi_ret(ansi):
|
||
|
|
return ansi, Color.__ansi_white
|
||
|
|
|
||
|
|
@staticmethod
|
||
|
|
def code(color: 'Color'):
|
||
|
|
return Color.__fescseq.format(color.value)
|
||
|
|
|
||
|
|
def ansi(self):
|
||
|
|
code = Color.code(self)
|
||
|
|
if self == Color.White:
|
||
|
|
return code, ''
|
||
|
|
return code, Color.__ansi_rst
|
||
|
|
|
||
|
|
# !! ULTRA PRINT !!
|
||
|
|
def uprint(text: str,
|
||
|
|
color: Color = Color.White,
|
||
|
|
end: str = '\n',
|
||
|
|
flush: bool = True):
|
||
|
|
c = color.ansi()
|
||
|
|
text = f'{c[0]}{text}{c[1]}'
|
||
|
|
print(text, end=end, flush=flush)
|