[+] Color text with preset

This commit is contained in:
Azalea (on HyDEV-Daisy) 2022-04-10 03:49:27 -04:00
parent 4ba359a161
commit 8363efe5f4

View file

@ -59,6 +59,17 @@ class ColorProfile:
return self.with_weights(weights) return self.with_weights(weights)
def color_text(self, txt: str, foreground: bool = True) -> str:
"""
Color a text
:param txt: Text
:param foreground: Whether the foreground text show the color or the background block
:return: Colored text
"""
colors = self.with_length(len(txt))
return ''.join([colors[i].to_ansi_rgb(foreground) + c for i, c in enumerate(txt)]) + '\033[0m'
PRESETS: dict[str, ColorProfile] = { PRESETS: dict[str, ColorProfile] = {
'rainbow': ColorProfile([ 'rainbow': ColorProfile([