summaryrefslogtreecommitdiffstats
path: root/examples/print-text/html.py
blob: 5276fe3b770f0dfe41b350561504df90e6f23c92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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()