File size: 3,616 Bytes
065fee7 |
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 |
# encoding=utf-8
import io
from rich import box
from rich.columns import Columns
from rich.console import Console
from rich.panel import Panel
def render():
console = Console(file=io.StringIO(), width=100, legacy_windows=False)
panel = Panel.fit("foo", box=box.SQUARE, padding=0)
columns = Columns([panel] * 4)
columns.expand = True
console.rule("no align")
console.print(columns)
columns.align = "left"
console.rule("left align")
console.print(columns)
columns.align = "center"
console.rule("center align")
console.print(columns)
columns.align = "right"
console.rule("right align")
console.print(columns)
return console.file.getvalue()
def test_align():
result = render()
expected = "βββββββββββββββββββββββββββββββββββββββββββββ no align βββββββββββββββββββββββββββββββββββββββββββββ\nβββββ βββββ βββββ βββββ \nβfooβ βfooβ βfooβ βfooβ \nβββββ βββββ βββββ βββββ \nββββββββββββββββββββββββββββββββββββββββββββ left align ββββββββββββββββββββββββββββββββββββββββββββ\nβββββ βββββ βββββ βββββ \nβfooβ βfooβ βfooβ βfooβ \nβββββ βββββ βββββ βββββ \nβββββββββββββββββββββββββββββββββββββββββββ center align βββββββββββββββββββββββββββββββββββββββββββ\n βββββ βββββ βββββ βββββ \n βfooβ βfooβ βfooβ βfooβ \n βββββ βββββ βββββ βββββ \nβββββββββββββββββββββββββββββββββββββββββββ right align ββββββββββββββββββββββββββββββββββββββββββββ\n βββββ βββββ βββββ βββββ\n βfooβ βfooβ βfooβ βfooβ\n βββββ βββββ βββββ βββββ\n"
assert result == expected
if __name__ == "__main__":
rendered = render()
print(rendered)
print(repr(rendered))
|