ansi-to-tui

January 4, 2026 · View on GitHub

Crate Badge Repo Badge
Docs Badge License Badge
CI Badge Codecov Badge

Convert ANSI color and style codes into Ratatui Text.

This crate parses bytes containing ANSI SGR escape sequences (like \x1b[31m). It produces a Ratatui Text with equivalent foreground/background Color and Modifier settings via Style.

Unknown or malformed escape sequences are ignored so you can feed it real terminal output without having to pre-clean it.

Color ModeSupportedSGR ExampleRatatui Color Example
Named (3/4-bit, 8/16-color)\x1b[30..37;40..47mColor::Blue
Indexed (8-bit, 256-color)\x1b[38;5;<N>mColor::Indexed(1)
Truecolor (24-bit RGB)\x1b[38;2;<R>;<G>;<B>mColor::Rgb(255, 0, 0)

Example

use ansi_to_tui::IntoText as _;
let buffer = std::fs::read("ascii/text.ascii")?;
let output = buffer.into_text()?;

Contributing and CI details are in CONTRIBUTING.md.