Does the Python rich module provide scroll bars?

163 views Asked by At

I'm creating a live table that gets updated every 60 seconds. The number of rows returned is variable and the size of the terminal is, of course, variable as well since it depends on what the user resizes it to.

The issue is quite simply that when the number of rows of data exceeds the available window space, data is currently hidden and there does not seem to be any way of viewing it.

As a simple example you can run the following code in a window with less than 30 lines on view:

    import time
    import rich.live
    import rich.table

    table = rich.table.Table()
    table.add_column("Row ID")
    table.add_column("Description")
    table.add_column("Level")

    with rich.live.Live(table):
        for row in range(30):
            # update the renderable internally
            table.add_row(f"{row}", f"description {row}", f"level {row}")
        time.sleep(40000)  # arbitrary delay for this example.

It displays as many lines as your allow for, but no more and you cannot see the last few lines.

Is it possible to add a scroll bar to tables?

I've searched the docs online but there's no mention of scrollbars anywhere, which leads me to think that it's not possible, which surprises me given that scrollbars have been a UI staple for decades.

1

There are 1 answers

0
August1328 On

I have the same problem using a rich table and was looking for a solution.

There is a closed issue with this topic and the creator of rich writes it is not possible, you have to use the module textual for example. Comment see here: support for creating scrolling within a layout #2473

So, I will try out textual.