SIGN IN SIGN UP
Textualize / rich UNCLAIMED

Rich is a Python library for rich text and beautiful formatting in the terminal.

55891 0 0 Python
2020-06-01 16:08:06 +01:00
"""
This example demonstrates how to write a custom highlighter.
"""
2020-05-08 13:36:12 +01:00
from random import randint
from rich import print
from rich.highlighter import Highlighter
class RainbowHighlighter(Highlighter):
def highlight(self, text):
for index in range(len(text)):
2020-08-08 17:38:57 +01:00
text.stylize(f"color({randint(16, 255)})", index, index + 1)
2020-05-08 13:36:12 +01:00
rainbow = RainbowHighlighter()
print(rainbow("I must not fear. Fear is the mind-killer."))