[+] Color text with preset
This commit is contained in:
parent
4ba359a161
commit
8363efe5f4
1 changed files with 11 additions and 0 deletions
|
@ -59,6 +59,17 @@ class ColorProfile:
|
|||
|
||||
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] = {
|
||||
'rainbow': ColorProfile([
|
||||
|
|
Loading…
Reference in a new issue