egui_sgr
egui_sgr converts ANSI/SGR escape sequences into egui text. The main output is
egui::text::LayoutJob, which is the egui representation designed for one text
value with multiple styled sections.
Install
[]
= "0.3"
LayoutJob Usage
use ;
let theme = default;
let job = ansi_to_layout_job;
ui.label;
LayoutJob is used because ANSI commonly changes style inside a single logical
string, and a single egui widget preserves wrapping and layout behavior.
Streaming Usage
use ;
let mut buffer = new;
buffer.push_bytes;
buffer.push_bytes;
buffer.push_bytes;
buffer.finish;
let theme = default;
ui.label;
For lower-level control, use AnsiStreamParser directly:
use AnsiStreamParser;
let mut parser = new;
let spans = parser.push_bytes;
let tail = parser.finish;
The streaming API is synchronous and byte-oriented, so it can be connected to
std::io, process output, PTYs, async runtimes, or network streams by feeding
whatever chunks the caller receives.
API Layers
ansi_to_spans/ansi_bytes_to_spans: parse ANSI into semantic spans.spans_to_layout_job: render already parsed spans with an egui theme.ansi_to_layout_job/ansi_bytes_to_layout_job: one-call parse and render.AnsiStreamParser: incremental parser that preserves state across chunks.AnsiSpanBuffer: accumulates streamed spans and renders the full buffer.
For the full module design and API policy, see ARCHITECTURE.md.
Supported SGR
- Reset:
0, emptyCSI m. - 4-bit colors:
30..37,40..47,90..97,100..107. - Defaults:
39,49,59. - 8-bit colors:
38;5;n,48;5;n,58;5;n. - 24-bit colors:
38;2;r;g;b,48;2;r;g;b,58;2;r;g;b. - Colon forms:
38:2::r:g:b,38:2:r:g:b,38:5:n, and related forms. - Attributes: bold, faint, italic, underline, strikethrough, reverse, hidden.
This crate does not emulate a terminal screen. Cursor movement, clearing, DCS, and OSC sequences are stripped by default.
Themes
EguiAnsiTheme::default() uses a conventional xterm 256-color palette.
EguiAnsiTheme::xterm() is an explicit alias for the same default theme.
Demo
Run the minimal API examples with:
Run the egui demo with:

Benchmarks And Quality Gates
Parser, renderer, and streaming paths have Criterion benchmarks:
The release quality gate used by CI is: