diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 17:35:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 17:35:20 +0000 |
commit | e106bf94eff07d9a59771d9ccc4406421e18ab64 (patch) | |
tree | edb6545500e39df9c67aa918a6125bffc8ec1aee /examples/print-text/html.py | |
parent | Initial commit. (diff) | |
download | prompt-toolkit-upstream.tar.xz prompt-toolkit-upstream.zip |
Adding upstream version 3.0.36.upstream/3.0.36upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'examples/print-text/html.py')
-rwxr-xr-x | examples/print-text/html.py | 53 |
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() |