Expand description
§rusty-rich
Rich text and beautiful formatting in the terminal — a Rust port of the popular Python Rich library.
Bring stunning terminal output to your Rust CLI tools with minimal code. Supports TrueColor/256/16-color terminals, produces ANSI escape sequences, and exports to HTML and SVG.
§Quick Start
use rusty_rich::{Console, Panel, Table, Column, Style, Color};
let mut console = Console::new();
// Inline markup
console.print_str("[bold green]Hello, [red]World![/red][/bold green]");
// Panel with title
let panel = Panel::new("Content inside a box")
.title("My Panel")
.border_style(Style::new().color(Color::parse("cyan").unwrap()));
console.println(&panel);
// Table with columns
let mut table = Table::new();
table.add_column(Column::new("Name"));
table.add_column(Column::new("Age"));
table.add_row_str("Alice", "30");
table.add_row_str("Bob", "25");
console.println(&table);§Feature Overview
§Core Primitives
| Module | Provides |
|---|---|
color | 256 named colors, TrueColor/8-bit/Standard, RGB↔ANSI conversion, blending |
style | 13 text attributes (bold/italic/underline/strike/…), links, style combination |
segment | Smallest output unit: text + style + control codes; 9 utility functions |
text | Text with Span-based styling, markup parsing, truncation, wrapping |
cells | Unicode cell width utilities for CJK and emoji |
measure | Width measurement protocol for layout negotiation |
align | Horizontal (Left/Center/Right/Full) and vertical (Top/Middle/Bottom) alignment |
markup | BBCode-like parser: [bold red]text[/bold red] |
highlighter | Regex-based and repr-style text highlighters |
ratio | Proportional space distribution with minimums and maximums |
§Console & Rendering
| Module | Provides |
|---|---|
console | Central rendering engine: Console, Renderable trait, RenderResult, Group |
theme | 170+ named style maps with stack-based inheritance via Theme and ThemeStack |
screen | Full-screen alt-buffer via Screen, ScreenContext RAII guard, ScreenUpdate |
§Layout & Renderables
| Module | Provides |
|---|---|
panel | Bordered container with title, subtitle, 17 box styles |
table | Tabular data with Column, Cell, colspan/rowspan, sections, 17 border styles |
tree | Hierarchical tree with Unicode/ASCII guides |
rule | Horizontal divider with optional centered title |
columns | Side-by-side column layout with equal/expand options |
layout | Recursive split-pane layout with ratio sizing and named regions |
padding | CSS-style padding (1–4 values) |
box_drawing | 17 box/border styles from ASCII to heavy double-lines |
§Dynamic Components
| Module | Provides |
|---|---|
progress | Multi-task progress bars, TrackIterator for tracking iterables, ProgressFile |
progress_columns | 11 column types: bar, text, spinner, time, file size, transfer speed, etc. |
spinner | 55 animated spinners with case-insensitive name lookup via get_spinner |
status | Animated spinner + status message with in-place refresh |
live | Auto-updating region with alt-screen support and LiveWriter for output capture |
§Content Rendering
| Module | Provides |
|---|---|
syntax | Syntax highlighting via syntect (100+ languages) |
markdown | Markdown rendering via pulldown-cmark: headings, code, lists, blockquotes, tables |
json | Pretty-printed JSON with syntax-highlighted keys/values |
logging | RichHandler for the log crate with colored levels |
traceback | Rich exception tracebacks with locals, source code, frame suppression, panic hook |
§Interactive
§Export
| Module | Provides |
|---|---|
export | HTML, SVG, and text export with 4 preset terminal themes |
§Examples by Use Case
§Markdown with Tables
use rusty_rich::{render_markdown, Console};
let md = render_markdown("# Report\n\n| Item | Qty |\n|------|-----|\n| A | 10 |\n| B | 5 |");
Console::new().println(&md);§Progress Bars
use rusty_rich::Progress;
let mut progress = Progress::new();
let task = progress.add_task("Downloading...", Some(100.0));
// … in a loop: progress.update(task, n as f64);
println!("{}", progress.render(80));§Interactive Prompts
use rusty_rich::{Prompt, Confirm, IntPrompt, Select};
let name = Prompt::ask_with("Enter name").unwrap();
let password = Prompt::new("Password").password(true).ask().unwrap();
let ok = Confirm::ask_with("Continue?", true).unwrap();
let age = IntPrompt::ask_with("Age").unwrap();
let choice = Select::new("Pick").choice("Red", "r").choice("Blue", "b").ask().unwrap();§Live Display with Writer
use rusty_rich::{Live, LiveWriter, Panel};
use std::io::Write;
let mut live = Live::new(Panel::new("Starting...").title("Status"));
let mut writer = live.create_writer();
live.start().unwrap();
writeln!(writer, "Processing items...").unwrap();
live.update(Panel::new("Done!").title("Status")).unwrap();
live.stop().unwrap();§Traceback Panic Hook
use rusty_rich::traceback;
// Install a global panic hook for rich tracebacks
traceback::install();
// Or render manually
// let tb = Traceback::from_exception("MyError", "details", frames)
// .show_locals(true)
// .max_frames(5);§Full-Screen Applications
use rusty_rich::{Console, Screen};
let mut console = Console::new();
let mut screen = console.screen();
screen.enter(); // enters alt screen
// … render content …
screen.exit(); // restores terminal§HTML & SVG Export
use rusty_rich::{export_svg, ExportSvgOptions};
let svg = export_svg(ExportSvgOptions::default());
std::fs::write("output.svg", svg).unwrap();§Color & Style System
256 named colors via Color::parse, plus hex/RGB constructors with automatic downgrade:
use rusty_rich::{Color, Style};
// Named colors — 256 ANSI palette
let c = Color::parse("hot_pink").unwrap();
let c = Color::parse("steel_blue").unwrap();
// Hex / RGB
let c = Color::from_hex("#FF6600").unwrap();
let c = Color::from_rgb(100, 200, 50);
// Style with 13 attributes + links
let s = Style::new()
.color(Color::parse("cyan").unwrap())
.bgcolor(Color::parse("#1E1E2E").unwrap())
.bold(true)
.italic(true)
.underline(true)
.link("https://example.com");§Box Styles (17 built-in)
BOX_ROUNDED ╭─╮ │ │ ╰─╯ BOX_HEAVY ┏━┓ ┃ ┃ ┗━┛
BOX_SQUARE ┌─┐ │ │ └─┘ BOX_DOUBLE ╔═╗ ║ ║ ╚═╝
BOX_ASCII +-+ | | +-+ BOX_MARKDOWN | Table style§Comparison with Python Rich
rusty-rich achieves ~72% feature parity with Python Rich 13.x (197 tests).
Missing features: Pretty (object rendering), Inspect (introspection), emoji support, Jupyter integration,
ANSI decoder, and system pager.
§Feature Flags
No feature flags — all functionality is included by default. Dependencies are carefully chosen for minimal compile times.
§Crate Organization
The crate is organized into 5 module groups:
- Core (
color,style,segment,text,theme,measure,align,markup,ratio,highlighter,cells,console,box_drawing) - Renderables (
panel,table,tree,rule,padding,columns,layout) - Dynamic (
prompt,progress,progress_columns,spinner,status,live,screen) - Content (
syntax,markdown,json,logging,traceback) - Export (
export)
Most commonly-used types are re-exported at the crate root for convenience.
Re-exports§
pub use color::Color;pub use color::ColorSystem;pub use color::ColorType;pub use style::Style;pub use style::StyleStack;pub use segment::Segment;pub use segment::Segments;pub use text::Text;pub use text::Span;pub use theme::Theme;pub use align::AlignMethod;pub use align::VerticalAlignMethod;pub use align::Align;pub use measure::Measurement;pub use console::Console;pub use console::ConsoleOptions;pub use console::ConsoleDimensions;pub use console::OverflowMethod;pub use console::Renderable;pub use console::RenderResult;pub use console::RenderItem;pub use console::DynRenderable;pub use console::Group;pub use console::get_console;pub use console::print_objects as print;pub use console::print_str;pub use console::print_json_val as print_json;pub use box_drawing::BoxStyle;pub use box_drawing::BOX_ROUNDED;pub use box_drawing::BOX_SQUARE;pub use box_drawing::BOX_HEAVY;pub use box_drawing::BOX_HEAVY_EDGE;pub use box_drawing::BOX_HEAVY_HEAD;pub use box_drawing::BOX_DOUBLE;pub use box_drawing::BOX_DOUBLE_EDGE;pub use box_drawing::BOX_SIMPLE;pub use box_drawing::BOX_SIMPLE_HEAVY;pub use box_drawing::BOX_MINIMAL;pub use box_drawing::BOX_MINIMAL_HEAVY;pub use box_drawing::BOX_ASCII;pub use box_drawing::BOX_ASCII2;pub use box_drawing::BOX_SQUARE_DOUBLE_HEAD;pub use box_drawing::BOX_MINIMAL_DOUBLE_HEAD;pub use box_drawing::BOX_SIMPLE_HEAD;pub use box_drawing::BOX_ASCII_DOUBLE_HEAD;pub use panel::Panel;pub use table::Table;pub use table::Column;pub use table::Cell;pub use tree::Tree;pub use rule::Rule;pub use padding::Padding;pub use padding::PaddingDimensions;pub use columns::Columns;pub use layout::Layout;pub use layout::LayoutNode;pub use layout::Direction;pub use layout::Region;pub use progress::Progress;pub use progress::ProgressBar;pub use progress::ProgressFile;pub use progress::Task;pub use progress::TrackIterator;pub use progress_columns::ProgressColumn;pub use progress_columns::BarColumn;pub use progress_columns::DownloadColumn;pub use progress_columns::FileSizeColumn;pub use progress_columns::MofNCompleteColumn;pub use progress_columns::SpinnerColumn;pub use progress_columns::TaskProgressColumn;pub use progress_columns::TextColumn;pub use progress_columns::TimeElapsedColumn;pub use progress_columns::TimeRemainingColumn;pub use progress_columns::TotalFileSizeColumn;pub use progress_columns::TransferSpeedColumn;pub use progress_columns::format_size;pub use progress_columns::format_speed;pub use spinner::Spinner;pub use spinner::SpinnerFrames;pub use spinner::DEFAULT_SPINNER;pub use spinner::get_spinner;pub use spinner::SPINNERS;pub use spinner::SPINNER_ARC;pub use spinner::SPINNER_ARROW;pub use spinner::SPINNER_ARROW2;pub use spinner::SPINNER_ARROW3;pub use spinner::SPINNER_BOUNCING_BAR;pub use spinner::SPINNER_BOUNCING_BALL;pub use spinner::SPINNER_CHRISTMAS;pub use spinner::SPINNER_CIRCLE;pub use spinner::SPINNER_CLOCK;pub use spinner::SPINNER_EARTH;pub use spinner::SPINNER_GRENADE;pub use spinner::SPINNER_GROW_HORIZONTAL;pub use spinner::SPINNER_GROW_VERTICAL;pub use spinner::SPINNER_HAMBURGER;pub use spinner::SPINNER_HEARTS;pub use spinner::SPINNER_MONKEY;pub use spinner::SPINNER_NOISE;pub use spinner::SPINNER_PONG;pub use spinner::SPINNER_RUNNER;pub use spinner::SPINNER_SHARK;pub use spinner::SPINNER_TOGGLE;pub use spinner::SPINNER_TRIANGLE;pub use spinner::SPINNER_VERTICAL_BARS;pub use prompt::Prompt;pub use prompt::PromptBase;pub use prompt::PromptError;pub use prompt::IntPrompt;pub use prompt::FloatPrompt;pub use prompt::Confirm;pub use prompt::Select;pub use status::Status;pub use live::Live;pub use live::LiveWriter;pub use screen::Screen;pub use screen::ScreenContext;pub use screen::ScreenUpdate;pub use syntax::Syntax;pub use markdown::render_markdown;pub use markdown::MarkdownRender;pub use json::render_json;pub use json::JsonRender;pub use logging::RichHandler;pub use traceback::Traceback;pub use traceback::Trace;pub use traceback::Stack;pub use traceback::Frame;pub use traceback::install;pub use highlighter::Highlighter;pub use highlighter::ReprHighlighter;pub use highlighter::NullHighlighter;pub use highlighter::RegexHighlighter;pub use export::export_html;pub use export::save_html;pub use export::ExportHtmlOptions;pub use export::export_svg;pub use export::save_svg;pub use export::ExportSvgOptions;pub use export::export_text;pub use export::save_text;pub use export::ExportTextOptions;pub use export::ExportTheme;pub use export::EXPORT_THEME_MONOKAI;pub use export::EXPORT_THEME_DIMMED_MONOKAI;pub use export::EXPORT_THEME_NIGHT_OWLISH;pub use export::EXPORT_THEME_SVG;pub use export::segments_to_html;pub use export::escape_html;pub use export::strip_ansi_escapes;pub use export::CONSOLE_HTML_FORMAT;pub use export::CONSOLE_SVG_FORMAT;pub use markup::render as render_markup;pub use markup::escape as escape_markup;
Modules§
- align
- Horizontal and vertical alignment wrappers for renderables.
Text alignment — equivalent to Rich’s
align.py. - box_
drawing - 17 box/border drawing styles from ASCII to heavy Unicode double-lines.
Box drawing — equivalent to Rich’s
box.py. - cells
- Unicode cell width utilities for CJK and emoji text measurement.
Unicode cell width handling — equivalent to Rich’s
cells.py. - color
- 256 named ANSI colors, TrueColor/8-bit/Standard, RGB↔ANSI conversion, blending.
Color system — equivalent to Rich’s
color.py. - columns
- Side-by-side column layout with equal-width and expand options.
Columns — render renderables side by side. Equivalent to Rich’s
columns.py. - console
- Central rendering engine — Console, Renderable trait, capture, export.
Console — the central rendering engine. Equivalent to Rich’s
console.py. - export
- HTML, SVG, and plain-text export with 4 preset terminal color themes.
HTML and SVG export — equivalent to Rich’s
_export_format.pyand Console export methods. - highlighter
- Regex-based and repr-style text highlighters.
Highlighter — applies highlighting to strings. Equivalent to Rich’s
highlighter.py. - json
- Pretty-printed JSON with syntax-highlighted keys, strings, numbers, booleans.
JSON pretty printing — equivalent to Rich’s
json.py. - layout
- Recursive split-pane layout engine with ratio sizing and named regions.
Layout — split-pane layout system. Equivalent to Rich’s
layout.py. - live
- Auto-updating display region with stdout/stderr capture via
LiveWriter. Live — auto-updating display. Equivalent to Rich’slive.py. - logging
RichHandlerfor thelogcrate — colored log levels with file/line info. Logging integration — equivalent to Rich’slogging.py.- markdown
- Markdown rendering via pulldown-cmark: headings, code, lists, blockquotes, tables.
Markdown rendering — equivalent to Rich’s
markdown.py. - markup
- BBCode-like markup parser:
[bold red]text[/bold red]. Console markup parser — equivalent to Rich’smarkup.py. - measure
- Width measurement protocol for layout negotiation between renderables.
Measurement system — equivalent to Rich’s
measure.py. - padding
- CSS-style padding (1–4 side values) around any renderable.
Padding — draw space around content. Equivalent to Rich’s
padding.py. - panel
- Bordered container with optional title, subtitle, and padding.
Panel — a bordered container. Equivalent to Rich’s
panel.py. - progress
- Multi-task progress bars with configurable column layouts and iterable tracking.
Progress bars and task tracking. Equivalent to Rich’s
progress.pyandprogress_bar.py. - progress_
columns - 11 progress column types: bar, text, spinner, time, file size, transfer speed. Progress column types — equivalent to Python Rich’s progress column system (SpinnerColumn, BarColumn, TextColumn, etc.).
- prompt
- Interactive prompts: string, int, float, confirm, select with password mode.
Interactive prompts — equivalent to Rich’s
rich/prompt.py. - ratio
- Proportional space distribution algorithms with minimums and maximums.
Ratio-based space distribution — equivalent to Rich’s
_ratio.py. - rule
- Horizontal divider line with optional centered, left-, or right-aligned title.
Rule — horizontal rule / divider. Equivalent to Rich’s
rule.py. - screen
- Full-screen rendering, alternate screen buffer, and screen update helpers. Screen — full-screen renderable and alternate screen buffer.
- segment
- Styled text unit with control codes — the smallest rendering primitive.
Segment — styled text unit. Equivalent to Rich’s
segment.py. - spinner
- 55 animated spinners with case-insensitive name-based lookup.
Spinner — animated spinner. Equivalent to Rich’s
spinner.py. - status
- Animated spinner with status message, in-place refresh via carriage return.
Status — status message with spinner. Equivalent to Rich’s
status.py. - style
- 13 text attributes (bold, italic, underline, …), links, style combination.
Text style — equivalent to Rich’s
style.py. - syntax
- Syntax highlighting via syntect (100+ languages, Sublime Text theme support).
Syntax highlighting — equivalent to Rich’s
syntax.py. - table
- Tabular data with column definitions, colspan/rowspan, sections, and 17 border styles.
Table — tabular data with columns. Equivalent to Rich’s
table.py. - text
- Styled text with
Span-based markup and text manipulation utilities. Text with spans — equivalent to Rich’stext.py. - theme
- Named style maps (170+ defaults) with stack-based inheritance.
Theme system — equivalent to Rich’s
theme.py. - traceback
- Rich exception tracebacks with source code, locals, frame suppression, panic hook.
Traceback – exception traceback rendering. Equivalent to Rich’s
traceback.py. - tree
- Hierarchical tree with Unicode or ASCII branch guides.
Tree — hierarchical tree rendering. Equivalent to Rich’s
tree.py.