rich-rs
Rich text and beautiful formatting for the terminal: a Rust port of Python's Rich library.
rich-rs focuses on expressive terminal output with a small, composable API. It supports tables, progress bars, Markdown, syntax highlighting, tracebacks, and more without extra setup.
Compatibility
rich-rs works on Linux, macOS, and Windows. True color / emoji works with modern terminals; legacy Windows console is limited to 16 colors.
Minimum Supported Rust Version: 1.85+ (Rust 2024 edition)
Installing
Add to your Cargo.toml:
[]
= "1.1.0"
Run the demo to see rich-rs in action:
Console Printing
To add rich output to your application, create a Console and use its print methods:
use ;
let mut console = new;
let text = from_markup.unwrap;
console.print.unwrap;
rich-rs will automatically word-wrap text to fit the terminal width and detect color support.
Markup
rich-rs uses a BBCode-like markup syntax for inline styling:
use ;
let mut console = new;
console.print.unwrap;
console.print.unwrap;
console.print.unwrap;
rich-rs Library
rich-rs ships with a set of built-in renderables you can combine to produce clean, beautiful CLI output.
Click the headings below for details:
rich-rs can render flexible tables with unicode box characters, borders, styles, and cell alignment.
use ;
let mut console = new;
let mut table = new;
table.add_column;
table.add_column;
table.add_column;
table.add_row_strs;
table.add_row_strs;
table.add_row_strs;
console.print.unwrap;
Tables automatically resize columns to fit the terminal width, wrapping text as needed.
rich-rs can render multiple flicker-free progress bars to track long-running tasks.
use sleep;
use Duration;
use ;
let mut progress = new_default;
progress.start.unwrap;
let config = TrackConfig ;
for _ in progress.track_sequence
progress.stop.unwrap;
For lower-level control, use add_task(...), update(...), and custom columns via Progress::new(...).
The progress API also supports print(...) and log(...) while the display is active.
For a full runnable example: cargo run --example progress.
rich-rs can update content in-place for real-time displays.
use ;
use Duration;
let mut live = new;
live.start.unwrap;
for i in 0..10
live.stop.unwrap;
Live display supports transient mode (clears on exit), alt-screen mode, and vertical overflow handling.
rich-rs provides logging adapters in a companion crate:
rich-tracing::RichTracingLayerfortracing_subscriberrich-tracing::RichLoggerfor thelogcrate ecosystem
See crates/rich-tracing/README.md and crates/rich-tracing/examples/tracing_basic.rs for usage.
rich-rs uses syntect to implement syntax highlighting with multiple themes.
use ;
let mut console = new;
let code = r#"fn main() {
let greeting = "Hello, World!";
println!("{}", greeting);
}
"#;
let syntax = new
.with_line_numbers
.with_theme;
console.print.unwrap;
Available themes include base16-ocean.dark, Solarized (dark), InspiredGitHub, and more.
rich-rs can render markdown with syntax-highlighted code blocks.
use ;
let mut console = new;
let md = r#"# Hello World
This is **bold** and *italic*.
- Item one
- Item two
```rust
fn main() {
println!("Hello!");
}
```
"#;
let markdown = new;
console.print.unwrap;
Supports CommonMark + GitHub Flavored Markdown including tables, task lists, and fenced code blocks.
rich-rs can render hierarchical data with guide lines.
use ;
let mut console = new;
let mut tree = new;
let src = tree.add_with_options;
src.add;
src.add;
tree.add;
console.print.unwrap;
rich-rs can render content in bordered boxes with titles.
use ;
use r#boxROUNDED;
let mut console = new;
let content = from_markup.unwrap;
let panel = new
.with_title
.with_box
.with_border_style;
console.print.unwrap;
rich-rs can render beautiful panic backtraces with syntax-highlighted source context.
use traceback;
// Install as the default panic handler
install;
// Now panics will show beautiful backtraces
Backtraces show the call stack with source code snippets and local variable values.
rich-rs can pretty-print data structures with syntax highlighting.
use ;
let mut console = new;
let data = r#"{"name": "rich-rs", "version": "1.0.0", "features": ["tables", "syntax"]}"#;
let pretty = from_str.with_indent_guides;
console.print.unwrap;
rich-rs provides interactive prompts with validation and choices.
use ;
// Text prompt with choices
let color = new
.with_choices
.run?;
// Numeric input
let age: i64 = ask?;
// Yes/No confirmation
if ask?
Supports password input, default values, and custom validation.
rich-rs can render content in neat columns with equal or optimal width.
use ;
let mut console = new;
let items: =
.map
.collect;
let columns = new.with_equal;
console.print.unwrap;
Acknowledgments
- Textualize for creating the original Python Rich library
- syntect for syntax highlighting
- crossterm for cross-platform terminal support
- pulldown-cmark for Markdown parsing
License
MIT License — see LICENSE for details.