[O] Remove HyPyUtils Dependency
This commit is contained in:
parent
7bb049ea20
commit
b0bc4e64a9
6 changed files with 97 additions and 9 deletions
|
|
@ -7,6 +7,48 @@ from typing_extensions import Literal
|
|||
AnsiMode = Literal['default', 'ansi', '8bit', 'rgb']
|
||||
|
||||
|
||||
MINECRAFT_COLORS = ["&0/\033[0;30m", "&1/\033[0;34m", "&2/\033[0;32m", "&3/\033[0;36m", "&4/\033[0;31m",
|
||||
"&5/\033[0;35m", "&6/\033[0;33m", "&7/\033[0;37m", "&8/\033[1;30m", "&9/\033[1;34m",
|
||||
"&a/\033[1;32m", "&b/\033[1;36m", "&c/\033[1;31m", "&d/\033[1;35m", "&e/\033[1;33m",
|
||||
"&f/\033[1;37m",
|
||||
"&r/\033[0m", "&l/\033[1m", "&o/\033[3m", "&n/\033[4m", "&-/\n"]
|
||||
MINECRAFT_COLORS = [(r[:2], r[3:]) for r in MINECRAFT_COLORS]
|
||||
|
||||
|
||||
def color(msg: str) -> str:
|
||||
"""
|
||||
Replace extended minecraft color codes in string
|
||||
:param msg: Message with minecraft color codes
|
||||
:return: Message with escape codes
|
||||
"""
|
||||
for code, esc in MINECRAFT_COLORS:
|
||||
msg = msg.replace(code, esc)
|
||||
|
||||
while '&gf(' in msg or '&gb(' in msg:
|
||||
i = msg.index('&gf(') if '&gf(' in msg else msg.index('&gb(')
|
||||
end = msg.index(')', i)
|
||||
code = msg[i + 4:end]
|
||||
fore = msg[i + 2] == 'f'
|
||||
|
||||
if code.startswith('#'):
|
||||
rgb = tuple(int(code.lstrip('#')[i:i+2], 16) for i in (0, 2, 4))
|
||||
else:
|
||||
code = code.replace(',', ' ').replace(';', ' ').replace(' ', ' ')
|
||||
rgb = tuple(int(c) for c in code.split(' '))
|
||||
|
||||
msg = msg[:i] + RGB(*rgb).to_ansi_rgb(foreground=fore) + msg[end + 1:]
|
||||
|
||||
return msg
|
||||
|
||||
|
||||
def printc(msg: str):
|
||||
"""
|
||||
Print with color
|
||||
:param msg: Message with minecraft color codes
|
||||
"""
|
||||
print(color(msg + '&r'))
|
||||
|
||||
|
||||
def redistribute_rgb(r: int, g: int, b: int) -> tuple[int, int, int]:
|
||||
"""
|
||||
Redistribute RGB after lightening
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue