From f8363b456f1ab31ee56abad579b215af195093d5 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Tue, 14 May 2024 22:18:28 +0200 Subject: Adding upstream version 9.11.0. Signed-off-by: Daniel Baumann --- examples/rainbow.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 examples/rainbow.py (limited to 'examples/rainbow.py') diff --git a/examples/rainbow.py b/examples/rainbow.py new file mode 100644 index 0000000..2121a78 --- /dev/null +++ b/examples/rainbow.py @@ -0,0 +1,20 @@ +""" + +This example demonstrates how to write a custom highlighter. + +""" + +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)): + text.stylize(f"color({randint(16, 255)})", index, index + 1) + + +rainbow = RainbowHighlighter() +print(rainbow("I must not fear. Fear is the mind-killer.")) -- cgit v1.2.3