summaryrefslogtreecommitdiffstats
path: root/examples/print-text/html.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/print-text/html.py')
-rwxr-xr-xexamples/print-text/html.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/examples/print-text/html.py b/examples/print-text/html.py
new file mode 100755
index 0000000..5276fe3
--- /dev/null
+++ b/examples/print-text/html.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+"""
+Demonstration of how to print using the HTML class.
+"""
+from prompt_toolkit import HTML, print_formatted_text
+
+print = print_formatted_text
+
+
+def title(text):
+ print(HTML("\n<u><b>{}</b></u>").format(text))
+
+
+def main():
+ title("Special formatting")
+ print(HTML(" <b>Bold</b>"))
+ print(HTML(" <blink>Blink</blink>"))
+ print(HTML(" <i>Italic</i>"))
+ print(HTML(" <reverse>Reverse</reverse>"))
+ print(HTML(" <u>Underline</u>"))
+ print(HTML(" <s>Strike</s>"))
+ print(HTML(" <hidden>Hidden</hidden> (hidden)"))
+
+ # Ansi colors.
+ title("ANSI colors")
+
+ print(HTML(" <ansired>ANSI Red</ansired>"))
+ print(HTML(" <ansiblue>ANSI Blue</ansiblue>"))
+
+ # Other named colors.
+ title("Named colors")
+
+ print(HTML(" <orange>orange</orange>"))
+ print(HTML(" <purple>purple</purple>"))
+
+ # Background colors.
+ title("Background colors")
+
+ print(HTML(' <style fg="ansiwhite" bg="ansired">ANSI Red</style>'))
+ print(HTML(' <style fg="ansiwhite" bg="ansiblue">ANSI Blue</style>'))
+
+ # Interpolation.
+ title("HTML interpolation (see source)")
+
+ print(HTML(" <i>{}</i>").format("<test>"))
+ print(HTML(" <b>{text}</b>").format(text="<test>"))
+ print(HTML(" <u>%s</u>") % ("<text>",))
+
+ print()
+
+
+if __name__ == "__main__":
+ main()