A terminal user interface (TUI) is a text-based interface that runs inside the terminal while offering a more structured, almost graphical display. TUIs are responsive, quick to compile, and useful for small applications such as a stopwatch and clock. section 23.4
In Rust, ratatui builds the interface on a crossterm backend. A Terminal provides a draw method that runs in a loop; its closure creates widgets and renders them into screen areas. Layout uses directions and constraints to divide the available terminal space. section 23.4.1
let layout = Layout::default()
.direction(Direction::Horizontal)
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)])
.split(f.size()); #1
let stopwatch_area = layout[0];
let utc_time_area = layout[1];
This layout divides the terminal horizontally into two equal areas, suitable for placing a stopwatch beside a clock. section 23.4.1
A simple TUI commonly combines these pieces:
- Create a terminal with a crossterm backend. section 23.4.1
- Split the screen with Layout, Direction, and Constraint. section 23.4.1
- Put text inside widgets such as Paragraph and Block, then call render_widget with a widget and an area. section 23.4.1
- Avoid wasteful redraws by sleeping briefly, monitoring user events, or redrawing only when the visual state changes. section 23.5
