summaryrefslogtreecommitdiffstats
path: root/examples/print-text/ansi-colors.py
blob: 7bd3831d85e93b563e89c0aab6f77ff0f4eaec43 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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()