Related: TUI
A Rust package for creating terminal user applications (TUIs).
Terminal Setup
When a TUI is spun up, a few things have to happen:
- An alternate screen is spun up—so that the output of your original terminal isn’t affected
- Raw mode is enabled—this turns off input and output processing by the terminal, allowing the TUI control over when to print characters to the screen
At teardown, the opposite happens.
Basic Setup
- Implement your own
Widget
trait (this assumes you need state)- Implement
.render
required by the trait - Define a
.run
method for the widget that- call
terminal.draw
- handle key events (powered by
crossterm
)
- call
- Implement
- In the
main
fn,- initialize a ratatui terminal
- upon completion, restore the original terminal
Thoughts
Was surprised that I have to manage spacing as part of a text (e.g. the ' '
prefix and suffix in " My Title "
).