liveBook · Manning

Terminal user interface

As explained in Learn Rust in a Month of Lunches

A terminal user interface is an interactive text-based interface rendered in a terminal rather than a graphical window.

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

How Learn Rust in a Month of Lunches covers it

How deep it goes
Explains setup, layout, widgets, rendering, and redraw concerns, but stops short of a complete interaction design.
Examples
Demonstrates a stopwatch-and-clock display divided into two panels with bordered text widgets.
What you can do after
Build it from scratch with ratatui by configuring a backend, splitting screen space, creating widgets, and rendering them.
How it connects
Connects terminal interfaces with Rust, ratatui, crossterm, widgets, layouts, builder patterns, and event monitoring.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Rust in a Month of Lunches. The section links point to the parts of the book it draws on.