summaryrefslogtreecommitdiffstats
path: root/examples/print-text/named-colors.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 16:35:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 16:35:31 +0000
commit4f1a3b5f9ad05aa7b08715d48909a2b06ee2fcb1 (patch)
treee5dee7be2f0d963da4faad6517278d03783e3adc /examples/print-text/named-colors.py
parentInitial commit. (diff)
downloadprompt-toolkit-4f1a3b5f9ad05aa7b08715d48909a2b06ee2fcb1.tar.xz
prompt-toolkit-4f1a3b5f9ad05aa7b08715d48909a2b06ee2fcb1.zip
Adding upstream version 3.0.43.upstream/3.0.43upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'examples/print-text/named-colors.py')
-rwxr-xr-xexamples/print-text/named-colors.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/examples/print-text/named-colors.py b/examples/print-text/named-colors.py
new file mode 100755
index 0000000..ea3f0ba
--- /dev/null
+++ b/examples/print-text/named-colors.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+"""
+Demonstration of all the ANSI colors.
+"""
+from prompt_toolkit import HTML, print_formatted_text
+from prompt_toolkit.formatted_text import FormattedText
+from prompt_toolkit.output import ColorDepth
+from prompt_toolkit.styles.named_colors import NAMED_COLORS
+
+print = print_formatted_text
+
+
+def main():
+ tokens = FormattedText([("fg:" + name, name + " ") for name in NAMED_COLORS])
+
+ print(HTML("\n<u>Named colors, using 16 color output.</u>"))
+ print("(Note that it doesn't really make sense to use named colors ")
+ print("with only 16 color output.)")
+ print(tokens, color_depth=ColorDepth.DEPTH_4_BIT)
+
+ print(HTML("\n<u>Named colors, use 256 colors.</u>"))
+ print(tokens)
+
+ print(HTML("\n<u>Named colors, using True color output.</u>"))
+ print(tokens, color_depth=ColorDepth.TRUE_COLOR)
+
+
+if __name__ == "__main__":
+ main()