Exemplo n.º 1
0
def render_tables():
    console = Console(
        width=60,
        force_terminal=True,
        file=io.StringIO(),
        legacy_windows=False,
        color_system=None,
    )

    table = Table(title="test table", caption="table caption", expand=True)
    table.add_column("foo",
                     footer=Text("total"),
                     no_wrap=True,
                     overflow="ellipsis")
    table.add_column("bar", justify="center")
    table.add_column("baz", justify="right")

    table.add_row("Averlongwordgoeshere", "banana pancakes", None)

    assert Measurement.get(console, table, 80) == Measurement(41, 48)

    for width in range(10, 60, 5):
        console.print(table, width=width)

    table.expand = False
    console.print(table, justify="left")
    console.print(table, justify="center")
    console.print(table, justify="right")

    assert table.row_count == 1

    table.row_styles = ["red", "yellow"]
    table.add_row("Coffee")
    table.add_row("Coffee", "Chocolate", None, "cinnamon")

    assert table.row_count == 3

    console.print(table)

    table.show_lines = True
    console.print(table)

    table.show_footer = True
    console.print(table)

    table.show_edge = False

    console.print(table)

    table.padding = 1
    console.print(table)

    table.width = 20
    assert Measurement.get(console, table, 80) == Measurement(20, 20)
    console.print(table)

    return console.file.getvalue()
Exemplo n.º 2
0
        "Dec 16, 2016",
        "Rogue One: A Star Wars Story",
        "$1,332,439,889",
    )

    def header(text: str) -> None:
        console.print()
        console.rule(highlight(text))
        console.print()

    console = Console()
    highlight = ReprHighlighter()
    header("Example Table")
    console.print(table, justify="center")

    table.expand = True
    header("expand=True")
    console.print(table, justify="center")

    table.width = 50
    header("width=50")

    console.print(table, justify="center")

    table.width = None
    table.expand = False
    table.row_styles = ["dim", "none"]
    header("row_styles=['dim', 'none']")

    console.print(table, justify="center")