diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:18:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:18:28 +0000 |
commit | f8363b456f1ab31ee56abad579b215af195093d5 (patch) | |
tree | b1500c675c2e0a55fb75721a854e1510acf7c862 /examples/rainbow.py | |
parent | Initial commit. (diff) | |
download | rich-upstream.tar.xz rich-upstream.zip |
Adding upstream version 9.11.0.upstream/9.11.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'examples/rainbow.py')
-rw-r--r-- | examples/rainbow.py | 20 |
1 files changed, 20 insertions, 0 deletions
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.")) |