diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 16:35:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 16:35:31 +0000 |
commit | 4f1a3b5f9ad05aa7b08715d48909a2b06ee2fcb1 (patch) | |
tree | e5dee7be2f0d963da4faad6517278d03783e3adc /examples/print-text/true-color-demo.py | |
parent | Initial commit. (diff) | |
download | prompt-toolkit-4f1a3b5f9ad05aa7b08715d48909a2b06ee2fcb1.tar.xz prompt-toolkit-4f1a3b5f9ad05aa7b08715d48909a2b06ee2fcb1.zip |
Adding upstream version 3.0.43.upstream/3.0.43
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'examples/print-text/true-color-demo.py')
-rwxr-xr-x | examples/print-text/true-color-demo.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/print-text/true-color-demo.py b/examples/print-text/true-color-demo.py new file mode 100755 index 0000000..a241006 --- /dev/null +++ b/examples/print-text/true-color-demo.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +""" +Demonstration of all the ANSI colors. +""" +from prompt_toolkit import print_formatted_text +from prompt_toolkit.formatted_text import HTML, FormattedText +from prompt_toolkit.output import ColorDepth + +print = print_formatted_text + + +def main(): + print(HTML("\n<u>True color test.</u>")) + + for template in [ + "bg:#{0:02x}0000", # Red. + "bg:#00{0:02x}00", # Green. + "bg:#0000{0:02x}", # Blue. + "bg:#{0:02x}{0:02x}00", # Yellow. + "bg:#{0:02x}00{0:02x}", # Magenta. + "bg:#00{0:02x}{0:02x}", # Cyan. + "bg:#{0:02x}{0:02x}{0:02x}", # Gray. + ]: + fragments = [] + for i in range(0, 256, 4): + fragments.append((template.format(i), " ")) + + print(FormattedText(fragments), color_depth=ColorDepth.DEPTH_4_BIT) + print(FormattedText(fragments), color_depth=ColorDepth.DEPTH_8_BIT) + print(FormattedText(fragments), color_depth=ColorDepth.DEPTH_24_BIT) + print() + + +if __name__ == "__main__": + main() |