Skip to content
Back to skills

Ratatui Knowledge Patch

ASecurity

Ratatui

  • 25 stars
  • 0 votes
  • 0 copies
  • 5 views
  • Added May 27, 2026
developmentrustgoawstestingapibackend

Works with

  • cursor
  • terminal
  • cli
  • api

Security analysis

A100/100

Pro scans all 6 files and shows the line behind each finding

Scanned December 1, 2026

npx -y skills add Nevaberry/nevaberry-plugins --skill ratatui-knowledge-patch --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Ratatui Knowledge Patch?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Ratatui Knowledge Patch
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/nevaberry-ratatui-knowledge-patch/badge)](https://www.skillsdirectory.com/skills/nevaberry-ratatui-knowledge-patch)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: ratatui-knowledge-patch
description: Ratatui
version: "0.31.0"
license: MIT
metadata:
  author: Nevaberry
---


# Ratatui knowledge patch

Load this skill when migrating Ratatui APIs, selecting Cargo features, implementing
widgets or backends, or working on terminal rendering, layout, styling, and state.
The references contain detailed behavior, migration conditions, and examples.

## Reference index

| Reference | Topics |
| --- | --- |
| [Migration and configuration](references/migration-and-configuration.md) | Crate dependencies, Rust requirements, imports, features, embedded builds, serialization |
| [Terminal, backends, and events](references/terminal-backends-and-events.md) | Setup and cleanup, backend contracts, viewport resizing, buffer presentation, input streams |
| [Layout, text, and style](references/layout-text-and-style.md) | Constraints, flex, geometry, cache, text alignment, widths, style and color conversions |
| [Widgets and selection](references/widgets-and-selection.md) | Blocks, tables, lists, tabs, paragraphs, scrollbars, calendar, fill and clear |
| [Charts, canvas, and symbols](references/charts-canvas-and-symbols.md) | Bars, sparklines, area plots, canvas markers, gauges, border symbols and merging |
| [Architecture, state, and testing](references/architecture-state-and-testing.md) | Borrowed widgets, components, state, template events, bounded writes, diffs and snapshots |

## Breaking changes and deprecations

### Custom backends and imports

A custom `Backend` must define `type Error` and implement `clear_region`.
Generic terminal code can return `Result<(), B::Error>` for `B: Backend`;
`TestBackend::Error` is `core::convert::Infallible`.

With `scrolling-regions`, custom backends need `scroll_region_up` and
`scroll_region_down`. Each should restore the default scrolling region afterward.
`Backend::size` returns `Size`; cursor position methods use `Position`.

Import `Styled` from `ratatui::style` and `Marker` from `ratatui::symbols`.
Import `CompletedFrame`, `TerminalOptions`, and `Viewport` from the crate root.
Use the backend conversion traits for Crossterm, Termion, or Termwiz conversions.

### Borrowed widgets and state

Migrate an `impl WidgetRef for MyWidget` that relied on the old blanket
implementation to `impl Widget for &MyWidget`, moving drawing into
`render(self, area, buf)`.

To retain frame calls to `render_widget_ref` or `render_stateful_widget_ref`,
enable `unstable-widget-ref` and import `ratatui::widgets::FrameExt`.
`StatefulWidget::State` and `StatefulWidgetRef::State` are `?Sized`.

### Block, list, table, and gauge setters

The `widgets::block` module and its `Title` type are no longer public.
Use `widgets::TitlePosition` for the former `block::Position` and
`widgets::BlockExt` for the extension trait. Pass strings or `Line` values to
`Block::title`; use `title_top` or `title_bottom` for placement.

Replace deprecated `Table::highlight_style` with `Table::row_highlight_style`.
Serialized `TableState` includes `selected_column`; update manual consumers.

`List::highlight_symbol` accepts `Into<Line>` and is no longer callable in a
const context. Use the original string or an explicit `Line` if conversion
inference becomes ambiguous. A styled line can style the symbol independently.

Replace deprecated `LineGauge::line_set` with `filled_symbol` and
`unfilled_symbol`. Replace deprecated `LineGauge::gauge_style` with
`filled_style` and `unfilled_style`.

### Type inference, ownership, and styles

`Tabs::select` accepts `Into<Option<usize>>`; `select(None)` clears selection.
If `select(index.into())` is ambiguous, convert explicitly to `usize`.
Pass strings directly when `.into()` becomes ambiguous for `Bar::label`,
`BarGroup::label`, or `Bar::text_value`.

`Line::from` accepts `Cow<str>`; give ambiguous inputs a concrete type.
For ambiguous `AsRef`-bounded calls in 0.30.1, specify the widget type and check
downstream blanket implementations whose bounds now match built-in widgets.

Replace `some_style.reset()` with `Style::reset()`.
Style shorthand methods are directly available on `Style` in const contexts;
review generic `Styled` bounds that previously accepted `Style` itself.

`patch_style` and `reset_style` on `Text`, `Line`, and `Span` consume and return
the updated value. Styling an owned `String` consumes it and produces a
`Span<'static>`; use `value.as_str().red()` when a span can borrow the string.
Use `ToText` without a lifetime argument.

### Geometry, spacing, and markers

Use `ratatui::layout::HorizontalAlignment` in place of `Alignment`;
`VerticalAlignment` is also available.
Switch previous `Flex::SpaceAround` layouts to `Flex::SpaceEvenly` to retain
equal edge and interior gaps. `SpaceAround` now doubles interior gaps relative
to edge spacing.

`Rect::area()` returns `u32`; independently clamped dimensions can yield an
area exceeding `u16::MAX`. Rectangle iterator fields are private: use
`rect.positions()` and the public row and column iterator constructors.

Add a wildcard arm when matching the non-exhaustive `ratatui::symbols::Marker`.
`Sparkline::data` is no longer `const`; configure its data at runtime.

## Dependencies and feature selection

Third-party widget crates can depend on `ratatui-core` for `Widget`,
`StatefulWidget`, `Buffer`, and `Rect`; use `ratatui-widgets` for built-in widgets.
Ratatui 0.30 requires Rust 1.86.0; Ratatui 0.30.1 requires Rust 1.88.0.

For `no_std`, disable default features and select compatible features.
Use `portable-atomic` on targets without native atomics; targets with native
atomics can leave it disabled, and `std` builds use standard-library atomics.

The `palette` and `serde` features require `std` in 0.30.0. The later feature
guidance in [Migration and configuration](references/migration-and-configuration.md)
allows `layout-cache`, `serde`, and `palette` with `std` disabled; for the layout
cache, link an appropriate `critical-section` implementation.

On `std` builds with defaults disabled, enable `layout-cache` to use
`Layout::init_cache` or `Layout::DEFAULT_CACHE_SIZE`. The cache is opt-in in
`ratatui-core`; its initializer takes a nonzero capacity and returns `()`.

With defaults disabled, enable `macros` for `span!`, `line!`, and `text!`.
Use `widget-calendar` for the calendar or `all-widgets` for the full widget group.
In `no_std`, supply calendar dates from the application because
`CalendarEventStore::today()` requires `std`.

Select Crossterm with `crossterm_0_28` or `crossterm_0_29`; the latest is the
default and takes precedence if both are enabled. Import matching backend APIs
through `ratatui::crossterm`, `ratatui::termion`, or `ratatui::termwiz` with the
corresponding feature enabled. The `termina` feature enables `ratatui-termina`.

## Terminal execution and presentation

`ratatui::run` initializes the default terminal, passes the callback a
`&mut DefaultTerminal`, restores the terminal when it completes, and returns
the callback's result.

`ratatui::init()` installs a panic hook that restores the terminal.
`ratatui::restore()` returns `()` and reports restoration errors to stderr.
With `crossterm`, use `ratatui::try_init` or `try_init_with_options` and
`try_restore` to handle errors. Save the drawing result before restoring so
draw errors still reach cleanup.

`Terminal::try_draw` accepts a callback returning `Result<(), E>`, where `E`
converts into the backend error type. A callback error returns before presenting
the frame, after any required autoresize.

Use `Terminal::apply_buffer()` to apply and flush writes to the current buffer
outside a `Terminal::draw` callback. The terminal reference also gives the
manual presentation sequence for ratatui-core 0.1.0.

`Terminal::insert_before(height, draw_fn)` affects only `Viewport::Inline`.
The callback receives a writable buffer with the requested rows; inserted lines
push the viewport down, then scroll content above it into scrollback.
Enable `scrolling-regions` to avoid flicker during insertion.

Enable Crossterm's `event-stream` on the version selected by Ratatui to use
`ratatui::crossterm::event::EventStream`. Create it once and await
`StreamExt::next()` in the input loop.

## Layout, text, and styling

Constraint precedence is `Min`, `Max`, `Length`, `Percentage`, `Ratio`, then
`Fill`. `Constraint::Ratio` takes `u32` operands.
With a two-constraint layout, `let [top, main] = area.layout(&layout);` infers
the output array length. `area.try_layout(&layout)` and `layout.try_areas(area)`
handle count mismatches; `area.layout_vec(&layout)` handles runtime counts.

Use `area.centered(Constraint::Ratio(1, 2), Constraint::Length(3))` to center
with independent constraints. `Layout::spacing(-1)` overlaps neighboring
segments by one cell; the last drawn border overwrites a shared cell.
`Layout::split_with_spacers(area)` exposes the gaps as rectangles.

An overlong `Line` without its own alignment clips using its parent `Text`
alignment. Explicit line alignment takes precedence. A `Paragraph` inherits
the supplied text's alignment. Enable `unstable-rendered-line-info` for the
experimental `Paragraph::line_count` and `Paragraph::line_width` methods.

`left += right` appends text lines, preserving line and span styling and line
alignment; the result uses the left-hand text's top-level style and alignment.
With `UnicodeWidthStr` in scope, use `width_cjk()` for wide ambiguous characters.

With `palette`, pass one `ratatui::palette::Hsl` to `Color::from_hsl` or an
`Hsluv` value to `Color::from_hsluv`. The `anstyle` feature enables its color
conversions; RGB and RGBA arrays and tuples also convert with `Color::from`.

## Selection, scrolling, and plots

Use `TableState::select_column` or `select_cell` with a `(row, column)` pair.
Table highlights apply in row, column, then cell order; later settings win for
the same property. The row highlight also styles the selection symbol.
`HighlightSpacing::Always` keeps columns stationary as selection changes.

Use `state.get_position()` to read a `ScrollbarState`; `position(index)` is
the builder setter. Zero content length draws nothing; set
`viewport_content_length` when visible item count differs from track length.
Apply custom scrollbar glyphs after `Scrollbar::orientation(...)`.

`Sparkline::data` accepts `Option<u64>` to distinguish gaps from zeroes and
`SparklineBar` values for per-bar styling. `BarChart::grouped` accepts labeled
groups. For filled chart areas, use `GraphType::Area` and dataset `fill_to_y`.
Canvas quadrant, sextant, and octant markers provide 2×2, 2×3, and 2×4 pixels
per terminal cell, respectively.

## Components and verification

Implement `Widget` for `&mut MyWidget` to mutate the same widget during draws.
Keep parent state across draws when nesting stateful widgets so child lists
can reuse computed scroll offsets. Apply chained TEA follow-up messages before
the next draw.

The component template's tick and render events are independent of input;
defaults are four ticks and 60 render events per second. It forwards only
`KeyEventKind::Press`; include `KeyEventKind::Repeat` if held keys should work
when the terminal reports repeats separately.

Intersect custom widget areas with `buf.area` before direct buffer writes,
and bound each `Buffer::set_line` call by the clipped row width.
Fixed-size `TestBackend` snapshots through `insta::assert_snapshot!` capture
glyphs and spacing; changes limited to colors or modifiers leave them unchanged.

Files in this skill

  • SKILL.md6.5 KB
  • references/backend-and-platform.md1 KB
  • references/layout.md1.2 KB
  • references/migration-guide.md1.6 KB
  • references/styling-and-borders.md1.1 KB
  • references/widgets.md1.9 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.