0

是否可以配置rich.Layout() 来指示布局中的项目数何时超过了当前布局的显示大小?

我希望能够以编程方式告诉代码何时尝试显示太多项目以供当前表格/布局显示以显示省略号或消息,例如“......和 ​​200 个其他项目”。这将允许程序提醒用户某些项目没有被显示。

Layout 中有一个size属性,但该值似乎是将布局限制为固定大小的输入,而不是当前布局大小的指示符。在我当前的应用程序中,我宁愿不限制布局的大小以使用完整的可用布局大小,无论该值是多少。

#!/usr/bin/env python3

from rich.console import Console
from rich.layout import Layout
from rich.table import Table
from rich.pretty import Pretty

# Make too many lines for the Layout/Table to display on the current screen size
MAX_LINES = 1000

def fill_table():
    table = Table()
    for li in range(MAX_LINES):
        table.add_row(Pretty(li))
    return table


console = Console()
layout = Layout(name="root")
layout["root"].update(fill_table())
console.print(layout)
4

0 回答 0