summaryrefslogtreecommitdiffstats
path: root/examples/print-text/ansi-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/ansi-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/ansi-colors.py')
-rwxr-xr-xexamples/print-text/ansi-colors.py100
1 files changed, 100 insertions, 0 deletions
diff --git a/examples/print-text/ansi-colors.py b/examples/print-text/ansi-colors.py
new file mode 100755
index 0000000..7bd3831
--- /dev/null
+++ b/examples/print-text/ansi-colors.py
@@ -0,0 +1,100 @@
+#!/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
+
+print = print_formatted_text
+
+
+def main():
+ wide_space = ("", " ")
+ space = ("", " ")
+
+ print(HTML("\n<u>Foreground colors</u>"))
+ print(
+ FormattedText(
+ [
+ ("ansiblack", "ansiblack"),
+ wide_space,
+ ("ansired", "ansired"),
+ wide_space,
+ ("ansigreen", "ansigreen"),
+ wide_space,
+ ("ansiyellow", "ansiyellow"),
+ wide_space,
+ ("ansiblue", "ansiblue"),
+ wide_space,
+ ("ansimagenta", "ansimagenta"),
+ wide_space,
+ ("ansicyan", "ansicyan"),
+ wide_space,
+ ("ansigray", "ansigray"),
+ wide_space,
+ ("", "\n"),
+ ("ansibrightblack", "ansibrightblack"),
+ space,
+ ("ansibrightred", "ansibrightred"),
+ space,
+ ("ansibrightgreen", "ansibrightgreen"),
+ space,
+ ("ansibrightyellow", "ansibrightyellow"),
+ space,
+ ("ansibrightblue", "ansibrightblue"),
+ space,
+ ("ansibrightmagenta", "ansibrightmagenta"),
+ space,
+ ("ansibrightcyan", "ansibrightcyan"),
+ space,
+ ("ansiwhite", "ansiwhite"),
+ space,
+ ]
+ )
+ )
+
+ print(HTML("\n<u>Background colors</u>"))
+ print(
+ FormattedText(
+ [
+ ("bg:ansiblack ansiwhite", "ansiblack"),
+ wide_space,
+ ("bg:ansired", "ansired"),
+ wide_space,
+ ("bg:ansigreen", "ansigreen"),
+ wide_space,
+ ("bg:ansiyellow", "ansiyellow"),
+ wide_space,
+ ("bg:ansiblue ansiwhite", "ansiblue"),
+ wide_space,
+ ("bg:ansimagenta", "ansimagenta"),
+ wide_space,
+ ("bg:ansicyan", "ansicyan"),
+ wide_space,
+ ("bg:ansigray", "ansigray"),
+ wide_space,
+ ("", "\n"),
+ ("bg:ansibrightblack", "ansibrightblack"),
+ space,
+ ("bg:ansibrightred", "ansibrightred"),
+ space,
+ ("bg:ansibrightgreen", "ansibrightgreen"),
+ space,
+ ("bg:ansibrightyellow", "ansibrightyellow"),
+ space,
+ ("bg:ansibrightblue", "ansibrightblue"),
+ space,
+ ("bg:ansibrightmagenta", "ansibrightmagenta"),
+ space,
+ ("bg:ansibrightcyan", "ansibrightcyan"),
+ space,
+ ("bg:ansiwhite", "ansiwhite"),
+ space,
+ ]
+ )
+ )
+ print()
+
+
+if __name__ == "__main__":
+ main()