summaryrefslogtreecommitdiffstats
path: root/examples/full-screen/simple-demos/vertical-align.py
blob: 13b85048e50e89d3bfaa4076cb84bcf0f2261eee (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env python
"""
Vertical align demo with VSplit.
"""

from prompt_toolkit.application import Application
from prompt_toolkit.formatted_text import HTML
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.layout.containers import (
    HSplit,
    VerticalAlign,
    VSplit,
    Window,
    WindowAlign,
)
from prompt_toolkit.layout.controls import FormattedTextControl
from prompt_toolkit.layout.layout import Layout
from prompt_toolkit.widgets import Frame

TITLE = HTML(
    """ <u>VSplit VerticalAlign</u> example.
 Press <b>'q'</b> to quit."""
)

LIPSUM = """
Lorem ipsum dolor sit amet, consectetur adipiscing elit.  Maecenas
quis interdum enim. Nam viverra, mauris et blandit malesuada, ante est bibendum
mauris, ac dignissim dui tellus quis ligula. Aenean condimentum leo at
dignissim placerat."""

# 1. The layout
body = HSplit(
    [
        Frame(
            Window(FormattedTextControl(TITLE), height=2), style="bg:#88ff88 #000000"
        ),
        VSplit(
            [
                Window(
                    FormattedTextControl(HTML("  <u>VerticalAlign.TOP</u>")),
                    height=4,
                    ignore_content_width=True,
                    style="bg:#ff3333 #000000 bold",
                    align=WindowAlign.CENTER,
                ),
                Window(
                    FormattedTextControl(HTML("  <u>VerticalAlign.CENTER</u>")),
                    height=4,
                    ignore_content_width=True,
                    style="bg:#ff3333 #000000 bold",
                    align=WindowAlign.CENTER,
                ),
                Window(
                    FormattedTextControl(HTML("  <u>VerticalAlign.BOTTOM</u>")),
                    height=4,
                    ignore_content_width=True,
                    style="bg:#ff3333 #000000 bold",
                    align=WindowAlign.CENTER,
                ),
                Window(
                    FormattedTextControl(HTML("  <u>VerticalAlign.JUSTIFY</u>")),
                    height=4,
                    ignore_content_width=True,
                    style="bg:#ff3333 #000000 bold",
                    align=WindowAlign.CENTER,
                ),
            ],
            height=1,
            padding=1,
            padding_style="bg:#ff3333",
        ),
        VSplit(
            [
                # Top alignment.
                HSplit(
                    [
                        Window(
                            FormattedTextControl(LIPSUM), height=4, style="bg:#444488"
                        ),
                        Window(
                            FormattedTextControl(LIPSUM), height=4, style="bg:#444488"
                        ),
                        Window(
                            FormattedTextControl(LIPSUM), height=4, style="bg:#444488"
                        ),
                    ],
                    padding=1,
                    padding_style="bg:#888888",
                    align=VerticalAlign.TOP,
                    padding_char="~",
                ),
                # Center alignment.
                HSplit(
                    [
                        Window(
                            FormattedTextControl(LIPSUM), height=4, style="bg:#444488"
                        ),
                        Window(
                            FormattedTextControl(LIPSUM), height=4, style="bg:#444488"
                        ),
                        Window(
                            FormattedTextControl(LIPSUM), height=4, style="bg:#444488"
                        ),
                    ],
                    padding=1,
                    padding_style="bg:#888888",
                    align=VerticalAlign.CENTER,
                    padding_char="~",
                ),
                # Bottom alignment.
                HSplit(
                    [
                        Window(
                            FormattedTextControl(LIPSUM), height=4, style="bg:#444488"
                        ),
                        Window(
                            FormattedTextControl(LIPSUM), height=4, style="bg:#444488"
                        ),
                        Window(
                            FormattedTextControl(LIPSUM), height=4, style="bg:#444488"
                        ),
                    ],
                    padding=1,
                    padding_style="bg:#888888",
                    align=VerticalAlign.BOTTOM,
                    padding_char="~",
                ),
                # Justify
                HSplit(
                    [
                        Window(FormattedTextControl(LIPSUM), style="bg:#444488"),
                        Window(FormattedTextControl(LIPSUM), style="bg:#444488"),
                        Window(FormattedTextControl(LIPSUM), style="bg:#444488"),
                    ],
                    padding=1,
                    padding_style="bg:#888888",
                    align=VerticalAlign.JUSTIFY,
                    padding_char="~",
                ),
            ],
            padding=1,
            padding_style="bg:#ff3333 #ffffff",
            padding_char=".",
        ),
    ]
)


# 2. Key bindings
kb = KeyBindings()


@kb.add("q")
def _(event):
    "Quit application."
    event.app.exit()


# 3. The `Application`
application = Application(layout=Layout(body), key_bindings=kb, full_screen=True)


def run():
    application.run()


if __name__ == "__main__":
    run()