minimum working requirements

This commit is contained in:
Emile Clark-Boman 2025-06-11 12:43:49 +10:00
parent c743ca0b85
commit a168a728ce
4 changed files with 88 additions and 34 deletions

0
prbraid/__init__.py Normal file
View file

View file

@ -1,36 +1,38 @@
from enum import Enum
from typing import Optional
class Color(Enum):
Black = 0
Red = 1
Green = 2
Yellow = 3
Blue = 4
Magenta = 5
Cyan = 6
White = 7
Reset = 0
Bold = 1
Italics = 2
Underline = 4
Black = 30
Red = 31
Green = 32
Yellow = 33
Blue = 34
Magenta = 35
Cyan = 36
White = 37
# escape sequence format string
__fescseq = '\033[3{0}m'
__fescseq = '\033[{0}'
# 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)
return Color.__fescseq.format(f'{color.value}m')
# move the cursor up n lines
@staticmethod
def mvup_code(n: int):
return Color.__fescseq.format(f'{n}A')
def ansi(self):
code = Color.code(self)
@ -40,9 +42,18 @@ class Color(Enum):
# !! ULTRA PRINT !!
def uprint(text: str,
color: Color = Color.White,
color: Optional[Color] = None,
style: Optional[Color] = None,
moveup: int = 0,
end: str = '\n',
flush: bool = True):
c = color.ansi()
text = f'{c[0]}{text}{c[1]}'
if color is not None:
c = color.ansi()
text = f'{c[0]}{text}{c[1]}'
if style is not None:
s = style.ansi()
tail = '' if (c is not None and c[1] == '') else s[1]
text = f'{s[0]}{text}{tail}'
if moveup > 0:
text = Color.mvup_code(moveup) + text
print(text, end=end, flush=flush)