Ratatui and Crossterm: Building Interactive Terminal Interfaces
Understand the split between rendering and input, read keys and mouse events safely on every platform, and keep crossterm versions aligned.
Diagnose the compiler errors, runtime glitches and terminal issues developers hit most often, with concrete fixes and prevention tips.

Most Ratatui problems fall into a handful of patterns: a toolchain that is too old, an API that was renamed, two versions of crossterm in one build, input that fires twice, a screen that flickers or a terminal left broken after a crash. Each has a clear cause and a reliable fix. This guide collects the errors developers hit most often, explains why they happen and shows how to resolve and prevent them. Commands and code were verified with Ratatui 0.30.2 and Rust 1.97.
For a quick reference, the troubleshooting section on our homepage summarizes ten common issues. This article goes deeper on each, with more context and additional cases.
Cargo refuses to build and prints a message saying the ratatui package (or one of its dependencies) requires a newer version of rustc than the one you have. Ratatui 0.30.2 declares a minimum supported Rust version of 1.88.0 through the rust-version field in its manifest, and Cargo enforces it.
Fix: update your toolchain with rustup update stable. If you are stuck on an old compiler, for example in a locked-down CI image, pin an older Ratatui release whose MSRV fits, but plan to upgrade because older versions do not receive fixes.
rustup update stable
rustc --version
cargo buildPrevent it: declare your own rust-version in Cargo.toml and use the same toolchain locally and in CI, for example with a rust-toolchain.toml file.
After bumping Ratatui you may see "no method named size found for Frame", deprecation warnings about highlight_style on tables, or errors about Spans. Ratatui is still in the 0.x series, where minor releases may change the API. The project documents every breaking change.
| Old usage | Current replacement |
|---|---|
frame.size() | frame.area() |
Spans | Line |
Table::highlight_style() | Table::row_highlight_style() |
| Manual raw mode + alternate screen setup | ratatui::run() or init() / restore() |
Layout::default().direction(..).constraints(..) | Layout::vertical([..]) / Layout::horizontal([..]) (old form still works) |
Fix: read the compiler output carefully; deprecation messages usually name the replacement. Then skim the project's BREAKING-CHANGES document for the versions between your old and new release. Prevent it: upgrade one minor version at a time on large projects, and keep cargo clippy clean so deprecations surface early.
Passing your own struct to frame.render_widget fails with "the trait bound App: Widget is not satisfied", or you implemented Widget for &App but passed app instead of &app. The types must match exactly: if the implementation is for a reference, pass a reference. Stateful widgets add another trap: List and Table must be rendered with render_stateful_widget if you want selection, and passing them to render_widget silently ignores any state.
Fix: implement Widget for &App and call frame.render_widget(&app, area), or render the pieces of your app individually. See how to create custom widgets for complete patterns.
A classic error appears when the draw closure needs your app mutably (for stateful widgets) while something else also borrows it, producing "cannot borrow app as mutable because it is also borrowed as immutable". The usual cause is building widgets from &app.items and then passing &mut app as a whole. Rust allows borrowing different fields separately, so borrow app.items immutably and app.list_state mutably, as in this compiling example:
use ratatui::layout::{Constraint, Layout};
use ratatui::widgets::{Block, List, ListState, Paragraph};
use ratatui::{DefaultTerminal, Frame};
struct App {
items: Vec<String>,
list_state: ListState,
status: String,
}
// Rendering takes &mut App only because stateful widgets need &mut state.
fn render(frame: &mut Frame, app: &mut App) {
let [list_area, status_area] =
Layout::vertical([Constraint::Fill(1), Constraint::Length(1)]).areas(frame.area());
let list = List::new(app.items.iter().map(String::as_str))
.block(Block::bordered().title(" Items "))
.highlight_symbol("> ");
// Borrow two different fields: allowed by the borrow checker.
frame.render_stateful_widget(list, list_area, &mut app.list_state);
frame.render_widget(Paragraph::new(app.status.as_str()), status_area);
}
fn run(terminal: &mut DefaultTerminal, app: &mut App) -> std::io::Result<()> {
terminal.draw(|frame| render(frame, app))?;
ratatui::crossterm::event::read()?;
Ok(())
}
fn main() -> std::io::Result<()> {
let mut app = App {
items: vec!["alpha".into(), "beta".into()],
list_state: ListState::default().with_selected(Some(0)),
status: "ready".into(),
};
ratatui::run(|terminal| run(terminal, &mut app))
}Another approach is to move rendering into a method on a view type that holds only references to the data it needs. Either way, keep state mutation out of rendering; the only mutation should be widget state such as selection offsets.
Errors like "expected crossterm::event::Event, found crossterm::event::Event" look absurd until you realize there are two different crossterm crates in your build. It happens when you add crossterm directly at a version different from the one Ratatui uses (0.29 for Ratatui 0.30.2), or when a third-party crate pulls in another version.
Fix: import from ratatui::crossterm and remove your direct dependency, or align its version. Use cargo tree -i crossterm to see who depends on which version. Ratatui's crossterm_0_28 and crossterm_0_29 features let you choose the version that matches the rest of your tree.
On Windows, crossterm reports both key presses and key releases. If your handler ignores key.kind, each action runs twice: lists skip items and counters jump by two. The same can happen on other platforms when enhanced keyboard reporting is enabled and repeat events arrive.
use ratatui::crossterm::event::{self, Event, KeyEventKind};
fn read_key() -> std::io::Result<Option<ratatui::crossterm::event::KeyEvent>> {
match event::read()? {
Event::Key(key) if key.kind == KeyEventKind::Press => Ok(Some(key)),
_ => Ok(None),
}
}Flicker almost always comes from fighting Ratatui's diffing. Calling terminal.clear() every frame forces a full repaint; calling draw several times per loop shows intermediate states; and writing to stdout with println! or a logger interleaves raw text with escape sequences. Ratatui only redraws what changed, so a single draw per iteration is all you need.
Fix: render everything inside one draw call, remove per-frame clear() calls, and send logs to a file. If you use the tracing ecosystem, configure a file appender, or render recent log lines in a widget inside the interface.
If a program panics or exits without restoring the terminal, the shell is left in raw mode: typed characters do not appear, Enter does not move to a new line and the alternate screen may still be visible. ratatui::run() and ratatui::init() install a panic hook that restores the terminal before the panic message prints, so the most robust fix is to use them. Avoid std::process::exit() inside the app, because it skips cleanup; return from your loop instead.
reset # restores a broken terminal on Linux and macOS
stty sane # alternative if reset is unavailableA panic mentioning an index outside the buffer means some code wrote to a cell beyond the area being drawn. Built-in widgets clip correctly, so the culprit is usually a custom widget or a hand-built Rect that ignores the terminal size. Clip areas with area.intersection(buf.area), iterate only between area.left() and area.right(), and derive rectangles from layouts rather than constants. Test with tiny terminal sizes to catch these bugs early.
Question marks or boxes in place of borders mean the terminal font lacks box-drawing or Braille glyphs; choose a font with good coverage and make sure your locale is UTF-8. Misaligned columns around emoji or CJK text come from wide characters that occupy two cells; Ratatui measures them with Unicode width rules, but some terminals and fonts disagree, so test your target terminals. Colors that look wrong usually mean the terminal or tmux does not support 24-bit color. Enable true color in the multiplexer, or fall back to named and indexed colors.
# ~/.tmux.conf
set -g default-terminal "tmux-256color"
set -as terminal-features ",*:RGB"An app that uses a full CPU core while idle is usually redrawing in a tight loop. Block on event::read() when the screen only changes on input, or use event::poll(timeout) with a sensible timeout for timers. Move file and network I/O out of the draw closure onto threads or async tasks, avoid rebuilding large collections every frame, and measure in release mode. Our real-time dashboard tutorial demonstrates a loop that redraws at a fixed rate and sleeps otherwise.
When users shrink the window, fixed-size areas may no longer fit and widgets get clipped or disappear. Check frame.area() at the start of rendering and, below a minimum width or height, draw a short message asking the user to enlarge the terminal instead of the full interface. Prefer Fill and Min constraints over large fixed lengths so the layout degrades gracefully before that point.
TestBackend test that renders the failing state and asserts on the buffer.cargo tree -i crossterm and cargo tree -p ratatui.Ratatui 0.30.2 requires Rust 1.88.0 or newer. Run rustup update stable, or pin an older Ratatui version if you cannot upgrade the compiler.
Type reset and press Enter (or stty sane). To prevent it, use ratatui::run() or init(), which restore the terminal even on panic.
Not to stdout. Write logs to a file, use a logging crate with a file appender, or display messages in a widget inside your interface.
Your project or a dependency requests a crossterm version different from Ratatui's. Use ratatui::crossterm, align versions and check with cargo tree -i crossterm.
Your Ratatui version, Rust version, operating system, terminal emulator, a minimal reproducible example and the exact error output.
Ratatui errors are rarely mysterious once you know the patterns: keep your toolchain at or above the MSRV, follow compiler hints for renamed APIs, import crossterm through Ratatui, filter key events by kind, draw once per frame, restore the terminal with the provided helpers and clip custom rendering to its area. When something new appears, the release notes on GitHub and the API documentation are the most reliable references. For working code to compare against, browse our tested examples.