Is there something similar to tview's Pages in crossterm?

Hi,

In Golang, using Pages, I can switch between different widgets.

For e.g., I have a main page, when user press p, show another "paused" page. After he press c to continue, I want to switch back to the main page, instead of re-rendering the whole main page.

Thanks,

For UI rendering purposes, crossterm is very low level; it just works with characters on the screen and has no notion of UI abstractions like widgets. If you want something for switching between these "Pages" things, you'll need to find or write something that builds on top of crossterm.

I'm not aware of any Rust TUI libraries that give you "Pages" out of the box, but it wouldn't be hard to achieve the desired effect using ratatui, one of the most popular (or the most popular?) higher-level TUI rendering libraries. With ratatui, your code would have some flag or enum indicating which was the current page; whenever the user inputs something to change the page, you update the flag/enum, and then when it comes time to update the screen, you assemble the collection of widgets specific to the current page and pass them to ratatui for drawing.

1 Like

tview describes itself as “Rich Interactive Widgets for Terminal UIs” so, yes, for Rust you need a library like ratatui to do the same job.

Note that terminals themselves do have one built-in “page” sort of thing, called the “alternate screen”. However, there's only one of those (or, two screen buffers: regular and alternate) and it is normally used to allow full-screen applications to restore what was on screen (your shell session) before they started, which they can't themselves redraw. For your application's own content, just redraw it as needed (whether using your own code or a widget library).

2 Likes