rich_rust
Beautiful terminal output for Rust, inspired by Python's Rich.
Run the Demo
See rich_rust in action with the Nebula Deploy demo — a complete showcase of terminal UI capabilities wrapped in a fictional deployment narrative.
# Full demo with all features (recommended)
# Quick mode for faster run
# CI-safe mode (non-blocking, deterministic output)
# List available scenes
# Run a specific scene
What the demo showcases:
- Typography — styled text, colors, bold/italic/underline, themes
- Tables — alignment, borders, headers, badges, ASCII fallback
- Panels — box styles, titles, padding, nested layouts
- Trees — hierarchical data, custom guides, icons
- Progress — bars, spinners, live updates
- Syntax — code highlighting for 100+ languages (Rust, YAML, TOML, etc.)
- Markdown — CommonMark + GFM rendering
- JSON — pretty-printed, theme-aware output
- Tracing — structured logging integration
- Export — HTML/SVG capture of terminal output
TL;DR
The Problem
Building beautiful terminal UIs in Rust is tedious. You either:
- Write raw ANSI escape codes (error-prone, unreadable)
- Use low-level crates that require boilerplate for simple things
- Miss features like automatic terminal capability detection, tables, progress bars
The Solution
rich_rust brings Python Rich's ergonomic API to Rust: styled text, tables, panels, progress bars, syntax highlighting, and more. Zero unsafe code, automatic terminal detection.
Why Use rich_rust?
| Feature | rich_rust | Raw ANSI | colored | termion |
|---|---|---|---|---|
Markup syntax ([bold red]text[/]) |
Yes | No | No | No |
| Tables with auto-sizing | Yes | No | No | No |
| Panels and boxes | Yes | No | No | No |
| Progress bars & spinners | Yes | No | No | No |
| Syntax highlighting | Yes | No | No | No |
| Markdown rendering | Yes | No | No | No |
| Auto color downgrade | Yes | No | Partial | No |
| Unicode width handling | Yes | No | No | Partial |
Quick Example
use *;
Output:
Success! Operation completed.
Error: File not found
─────────────────── Configuration ───────────────────
┌─────────────────────── Users ───────────────────────┐
│ Name │ Role │
├────────┼────────┤
│ Alice │ Admin │
│ Bob │ User │
└────────────────────────────────────────────────────┘
┌─────────── Greeting ───────────┐
│ Hello, World! │
└────────────────────────────────┘
Design Philosophy
1. Zero Unsafe Code
The entire codebase uses safe Rust. No segfaults, no data races, no undefined behavior.
2. Python Rich Compatibility
API and behavior closely follow Python Rich. If you know Rich, you know rich_rust. The RICH_SPEC.md documents every behavioral detail.
3. Renderable Extensibility
Instead of Python's duck typing, rich_rust uses explicit render methods and an optional measurement trait:
use ;
use ;
use Segment;
;
Renderables expose render(...) -> Vec<Segment>. Implement RichMeasure to
participate in layout width calculations.
4. Automatic Terminal Detection
rich_rust detects terminal capabilities at runtime:
- Color support (4-bit, 8-bit, 24-bit truecolor)
- Terminal dimensions
- Unicode support
- Legacy Windows console
Colors automatically downgrade to what the terminal supports.
5. Minimal Dependencies
Core functionality has few dependencies. Optional features (syntax highlighting, markdown, JSON, tracing) are behind feature flags to keep compile times fast.
Comparison vs Alternatives
| Feature | rich_rust | Python Rich | colored | termcolor | owo-colors |
|---|---|---|---|---|---|
| Language | Rust | Python | Rust | Rust | Rust |
| Markup parsing | [bold]text[/] |
[bold]text[/] |
No | No | No |
| Tables | Yes | Yes | No | No | No |
| Panels/Boxes | Yes | Yes | No | No | No |
| Progress bars | Yes | Yes | No | No | No |
| Trees | Yes | Yes | No | No | No |
| Syntax highlighting | Yes (syntect) | Yes (Pygments) | No | No | No |
| Markdown | Yes | Yes | Yes | No | No |
| JSON pretty-print | Yes | Yes | No | No | No |
| Color downgrade | Auto | Auto | Partial | Yes | No |
| Zero unsafe | Yes | N/A | Yes | Yes | Yes |
| No runtime | Yes | No (Python) | Yes | Yes | Yes |
| Single binary | Yes | No | Yes | Yes | Yes |
When to use rich_rust:
- You want Python Rich's features in Rust
- You need tables, panels, or progress bars
- You want markup syntax for styling
- You're building CLI tools that need beautiful output
When to use alternatives:
colored: Simple color-only needs, minimal dependenciestermcolor: Cross-platform color with Windows supportowo-colors: Zero-allocation, const colors- Python Rich: You're writing Python
Installation
From crates.io
With Optional Features
# Syntax highlighting
# Markdown rendering
# JSON pretty-printing
# Tracing integration
# All features
From Source
Cargo.toml
[]
= "0.1"
# Or with features:
= { = "0.1", = ["full"] }
Quick Start
1. Create a Console
use *;
let console = new;
2. Print Styled Text
// Using markup syntax
console.print;
// Using explicit style
console.print_styled;
// Plain text (no markup parsing)
console.print_plain;
3. Create a Table
let mut table = new
.title
.with_column
.with_column;
table.add_row_cells;
table.add_row_cells;
console.print_renderable;
4. Create a Panel
let panel = from_text
.title
.subtitle
.width;
console.print_renderable;
5. Print a Rule
// Simple rule
console.rule;
// Rule with title
console.rule;
// Styled rule
let rule = with_title
.style
.align_left;
console.print_renderable;
Feature Reference
Markup Syntax
| Markup | Effect |
|---|---|
[bold]text[/] |
Bold text |
[italic]text[/] |
Italic text |
[underline]text[/] |
Underlined text |
[red]text[/] |
Red foreground |
[on blue]text[/] |
Blue background |
[bold red on white]text[/] |
Combined styles |
[#ff0000]text[/] |
Hex color |
[rgb(255,0,0)]text[/] |
RGB color |
[color(196)]text[/] |
256-color palette |
Themes (Named Styles)
Python Rich defines many named styles (e.g. rule.line, table.header). rich_rust
ports this theme system and lets you add custom names:
use *;
let theme = from_style_definitions.unwrap;
let console = builder.theme.build;
console.print;
Style Attributes
new
.bold
.italic
.underline
.strikethrough
.dim
.reverse
.foreground
.background
Color Systems
| System | Colors | Detection |
|---|---|---|
| Standard | 16 | Basic terminals |
| 256-color | 256 | Most modern terminals |
| Truecolor | 16M | iTerm2, Windows Terminal, etc. |
Box Styles
from_text.rounded // ╭─╮ (default)
from_text.square // ┌─┐
from_text.heavy // ┏━┓
from_text.double // ╔═╗
from_text.ascii // +-+
Progress Bars
let bar = new
.completed
.total
.width;
console.print_renderable;
Trees
let mut root = new;
root.add_child;
root.add_child;
let tree = new;
console.print_renderable;
Live Updates
use *;
For external writers, use live.stdout_proxy() / live.stderr_proxy() to route output
through the Live display.
Layouts
use *;
let mut layout = new.name;
layout.split_column;
if let Some = layout.get_mut
console.print_renderable;
Logging
use *;
use LevelFilter;
Note: log macros come from the log crate; add log = "0.4" to your Cargo.toml.
Tracing: enable rich_rust feature tracing and install RichTracingLayer if you use
the tracing ecosystem.
HTML/SVG Export
Export terminal output to shareable files:
use *;
let mut console = new;
console.begin_capture;
console.print;
let html = console.export_html; // false = don't clear buffer
let svg = console.export_svg; // true = clear buffer after
Note: The HTML/SVG exports follow Python Rich's export templates (including optional
terminal-window chrome). SVG is rendered with SVG primitives (<text>, <rect>, clip paths),
so it works in browsers and in many SVG-capable viewers (no <foreignObject> required).
For a quick demo of export capabilities, run:
Syntax Highlighting (requires syntax feature)
use *;
let code = r#"fn main() { println!("Hello"); }"#;
let syntax = new
.line_numbers
.theme;
console.print_renderable;
Markdown Rendering (requires markdown feature)
use *;
let md = new;
console.print_renderable;
Pretty / Inspect
Rust doesn't have Python-style runtime reflection, so rich_rust's equivalents are
Debug-based and deterministic.
use *;
let console = new;
let cfg = Config ;
console.print_renderable;
inspect;
Tracebacks
Traceback is a renderable inspired by Python Rich's rich.traceback.
You can construct it from explicit frames (deterministic, great for tests/fixtures),
or capture a real runtime backtrace when the backtrace feature is enabled.
use *;
let console = new;
let traceback = new;
console.print_exception;
Automatic capture (requires backtrace feature):
use *;
let console = new;
let traceback = capture;
console.print_exception;
Architecture
┌─────────────────────────────────────────────────────────────┐
│ Console │
│ (Central coordinator: options, rendering, I/O) │
└─────────────────────────┬───────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Renderables │
│ (Text, Table, Panel, Rule, Tree, Progress, Syntax, etc.) │
│ Expose render() + optional RichMeasure for sizing │
└─────────────────────────┬───────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Segments │
│ (Atomic unit: text + optional style + control codes) │
└─────────────────────────┬───────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ ANSI Codes + Output │
│ (Style diffing, escape sequences, terminal write) │
└─────────────────────────────────────────────────────────────┘
Render Pipeline (Step-by-Step)
- Input — A string (optionally with markup) or a renderable (Table, Panel, Tree, etc.).
- Markup parsing —
[bold red]text[/]is parsed intoText+ styled spans. - Renderable layout — Each renderable converts itself into
Vec<Segment>. - Segment stream — Segments carry plain text + optional
Style+ control codes. - ANSI generation — Styles are diffed and rendered to ANSI SGR (or skipped if disabled).
- Output —
Consolewrites the final stream to the configuredWrite.
Module Structure
src/
├── lib.rs # Crate root, prelude
├── color.rs # Color system (4/8/24-bit)
├── style.rs # Style attributes (bold, italic, etc.)
├── segment.rs # Atomic rendering unit
├── text.rs # Rich text with spans
├── markup/ # Markup parser ([bold]...[/])
├── measure.rs # Width measurement protocol
├── console.rs # Console I/O coordinator
├── terminal.rs # Terminal detection
├── cells.rs # Unicode cell width
├── box.rs # Box drawing characters
└── renderables/
├── align.rs # Alignment
├── columns.rs # Multi-column layout
├── padding.rs # Padding
├── panel.rs # Boxed panels
├── progress.rs # Progress bars, spinners
├── rule.rs # Horizontal rules
├── table.rs # Tables with auto-sizing
├── tree.rs # Hierarchical trees
├── syntax.rs # Syntax highlighting (optional)
├── markdown.rs # Markdown rendering (optional)
└── json.rs # JSON pretty-print (optional)
Feature Parity (Python Rich)
See FEATURE_PARITY.md for the authoritative matrix and RICH_SPEC.md for detailed behavior notes.
Implemented
- Markup (
[bold red]text[/]), styles, colors, hyperlinks - Tables, panels, rules, trees, columns, padding, alignment
- Terminal control renderable (
Control) + control-code helpers - Progress bars & spinners
- Live updating / dynamic refresh (
Live) - Layout engine (
Layout) - Logging handler integration (
RichLogger) - HTML/SVG export (
Console::export_html/Console::export_svg) - Syntax highlighting (feature
syntax) (seeFEATURE_PARITY.mdfor remaining parity gaps) - Markdown rendering (feature
markdown) (seeFEATURE_PARITY.mdfor remaining parity gaps) - JSON pretty-print (feature
json) (seeFEATURE_PARITY.mdfor remaining parity gaps) - Traceback rendering (
Traceback,Console::print_exception) (explicit frames for deterministic tests; optionalTraceback::capturevia featurebacktrace) - Unicode width handling + auto color downgrade
Notes
- rich_rust is output-focused, but it also includes small, pragmatic interactive helpers (prompts, pager, status) for common CLI workflows.
Demo Showcase: demo_showcase
We’re building a standalone demo_showcase binary that shows off rich_rust end-to-end in a single cohesive narrative (product-grade visuals, not just a grab bag of examples).
Narrative
Nebula Deploy — a fictional deployment/release assistant. It naturally justifies a live dashboard, progress, structured data views, and a deliberate failure for traceback/debug tooling.
Scene Flow
--list-scenes must output stable names (used by --scene <name>), in this order (with a one-line purpose + any feature-gate notes):
| Scene | Purpose | Exercises |
|---|---|---|
hero |
Introduce Nebula Deploy and the visual "brand". | markup, Style/Theme, Emoji, Rule/Panel |
dashboard |
Show the live split-screen dashboard (services + pipeline + logs). | Layout, Live, Progress, logging |
markdown |
Show a runbook / release notes view. | Markdown (feature markdown) |
syntax |
Show a config/code snippet view. | Syntax (feature syntax) |
json |
Show an API payload view. | Json (feature json) |
table |
Show data tables with various styles. | Table with sorting, alignment |
panels |
Show boxed content with titles. | Panel with borders, padding |
tree |
Show hierarchical data structures. | Tree with nested nodes |
layout |
Show split-screen layouts. | Layout with columns/rows |
emoji_links |
Show emoji and hyperlink support. | Emoji, OSC8 links |
debug_tools |
Walk through a failure and recovery workflow. | Pretty/Inspect, Traceback |
tracing |
Show tracing integration. | RichTracingLayer (feature tracing) |
traceback |
Show error tracebacks. | Traceback rendering |
export |
Export the run to artifacts for sharing. | Console::export_html, Console::export_svg |
outro |
Wrap up with a crisp summary and next steps. | Table, Tree, Rule |
Feature-gated scenes must self-report clearly when disabled (and how to enable the required --features ...).
CLI Contract (Explicit + Stable)
The goal is (a) safe in CI/pipes and (b) tunable for maximum “wow” in a real terminal.
demo_showcase --help should read like a real CLI:
demo_showcase — Nebula Deploy (rich_rust showcase)
USAGE:
demo_showcase [OPTIONS]
OPTIONS:
--list-scenes List available scenes and exit
--scene <name> Run a single scene (see --list-scenes)
--seed <u64> Seed deterministic demo data (default: 0)
--quick Reduce sleeps/runtime (CI-friendly)
--speed <multiplier> Animation speed multiplier (default: 1.0)
--interactive Force interactive mode
--no-interactive Disable prompts/pager/etc
--live Force live refresh
--no-live Disable live refresh; print snapshots
--screen Use alternate screen (requires live)
--no-screen Disable alternate screen
--force-terminal Treat stdout as a TTY (even when piped)
--width <cols> Override console width
--height <rows> Override console height
--color-system <mode> auto|none|standard|eight_bit|truecolor
--emoji Enable emoji (default)
--no-emoji Disable emoji
--safe-box Use ASCII-safe box characters
--no-safe-box Use Unicode box characters (default)
--links Enable OSC8 hyperlinks
--no-links Disable OSC8 hyperlinks
--export Write an HTML/SVG bundle to a temp dir
--export-dir <path> Write an HTML/SVG bundle to a directory
-h, --help Print help and exit
Export Usage
Export captures the full demo output and writes two files:
demo_showcase.html— Standalone HTML with inline CSS. Opens in any browser.demo_showcase.svg— Scalable vector graphic rendered with SVG text and shapes.
# Quick export to temp directory (prints path)
# Export to specific directory
# Recommended flags for clean export
Viewing exported files:
- HTML: Open directly in any browser. Colors and styles are preserved.
- SVG: Open in any modern browser (Chrome, Firefox, Safari). The SVG uses only standard SVG primitives (text, rects, clip paths), so it is broadly compatible.
Defaults ("auto")
interactive=automeans: interactive only when stdout is a TTY andTERMis notdumb/unknown.live=automeans:live = interactive.screen=automeans:screen = live && interactive(TTY-only).links=automeans: hyperlinks only wheninteractive; override with--links/--no-links.FORCE_COLORmay force color output, but must not enable interactive/live behavior; use--force-terminalto intentionally override TTY checks.
Safety requirements
- If stdout is not a TTY and
--force-terminalis not set:- disable live refresh and alternate screen
- disable prompt/pager helpers
- print static snapshots only
- No scene may require user input to terminate.
- No infinite loops; any animation must be time-bounded and/or gated on TTY.
- Unknown flags must yield a concise error plus a
--helphint. --scenemust validate known names and print an “available scenes” list on error.
Implementation note: keep CLI parsing dependency-light (hand-rolled; no large CLI frameworks).
Troubleshooting
Colors not showing
Symptom: Text prints without colors in terminal.
Causes & Fixes:
- Piped output: Colors disabled when stdout isn't a TTY. Use
FORCE_COLOR=1env var. - Terminal doesn't support colors: Try a modern terminal (iTerm2, Windows Terminal).
- TERM variable: Ensure
TERMis set correctly (xterm-256color, etc.).
Unicode characters garbled
Symptom: Box characters display as ? or mojibake.
Fixes:
- Use
.ascii()variant:Panel::from_text("...").ascii() - Set terminal encoding to UTF-8
- Use a font with box-drawing characters (most monospace fonts have them)
Table columns too wide/narrow
Symptom: Table layout doesn't fit terminal.
Fixes:
- Get terminal width:
console.width() - Set explicit column widths:
Column::new("...").width(20) - Set min/max widths:
Column::new("...").min_width(10).max_width(40)
Markup not parsing
Symptom: [bold]text[/] prints literally.
Fixes:
- Use
console.print()notconsole.print_plain() - Check for unbalanced brackets
- Escape literal brackets:
\[not markup\]
Windows console issues
Symptom: Escape codes visible or wrong colors on Windows.
Fixes:
- Use Windows Terminal (modern) instead of cmd.exe
- Enable virtual terminal processing:
SetConsoleModewithENABLE_VIRTUAL_TERMINAL_PROCESSING - rich_rust auto-detects this, but old cmd.exe may not support it
Limitations
- No input: This is an output library; use
crosstermordialoguerfor input - Limited input: rich_rust includes prompts/pager/status helpers, but it is not a full TUI/input widget framework. For complex input, use crates like
dialoguer,rustyline, orinquire. - No async: Rendering is synchronous; wrap in
spawn_blockingif needed - Live redirection:
Livecan redirect process-wide stdout/stderr in interactive terminals (TTY-only). In piped/non-interactive contexts it stays disabled; uselive.stdout_proxy()/live.stderr_proxy()for external writers. - HTML/SVG export: Export is intended to match Python Rich's HTML/SVG export behavior and templates.
FAQ
Q: How does this compare to Python Rich?
A: rich_rust targets feature-for-feature parity with Python Rich. When behavior differs, treat it as a bug (or an explicitly documented, test-covered deviation) and track it until resolved.
Q: Is this production-ready?
A: It's in active development (v0.1.x). Core features work well, but the API may change. Pin your version in Cargo.toml.
Q: Can I use this in a TUI application?
A: rich_rust is for styled output, not interactive TUIs. For interactive apps, use ratatui, cursive, or tui-rs (which can potentially use rich_rust for styled text rendering).
Q: Why not just use Python Rich via PyO3?
A: Native Rust has no Python runtime dependency, compiles to a single binary, and avoids FFI overhead. If you're already in Rust, stay in Rust.
Q: How do I contribute?
A: See the "About Contributions" section below.
Q: What's the minimum Rust version?
A: Rust 2024 edition (nightly required currently). Check rust-toolchain.toml for specifics.
About Contributions
Please don't take this the wrong way, but I do not accept outside contributions for any of my projects. I simply don't have the mental bandwidth to review anything, and it's my name on the thing, so I'm responsible for any problems it causes; thus, the risk-reward is highly asymmetric from my perspective. I'd also have to worry about other "stakeholders," which seems unwise for tools I mostly make for myself for free. Feel free to submit issues, and even PRs if you want to illustrate a proposed fix, but know I won't merge them directly. Instead, I'll have Claude or Codex review submissions via gh and independently decide whether and how to address them. Bug reports in particular are welcome. Sorry if this offends, but I want to avoid wasted time and hurt feelings. I understand this isn't in sync with the prevailing open-source ethos that seeks community contributions, but it's the only way I can move at this velocity and keep my sanity.
License
MIT License (with OpenAI/Anthropic Rider). See LICENSE for details.