Expand description
§fast-rich
A Rust port of Python’s Rich library for beautiful terminal formatting.
§Features
- Rich text with colors, styles, and markup
- Tables with Unicode borders and auto-sizing
- Progress bars with multiple tasks, spinners, and customizable columns
- Live Display for flicker-free auto-updating content
- Logging handler for colorful structured logs
- Tree views for hierarchical data
- Panels and Rules for visual organization
- Markdown rendering (optional)
- Syntax highlighting (optional)
- Pretty tracebacks for better error display
§Quick Start
§Drop-in Print Replacement
// Shadow standard print macros with rich versions
use fast_rich::{print, println};
println!("[bold magenta]Hello, World![/]");
println!("Player {} scored [yellow]{}[/] points", "Alice", 100);§Using Console Directly
use fast_rich::prelude::*;
let console = Console::new();
// Simple styled output
console.print("Hello, [bold magenta]World[/]!");
// Tables
let mut table = Table::new();
table.add_column("Name");
table.add_column("Age");
table.add_row_strs(&["Alice", "30"]);
console.print_renderable(&table);§Markup Syntax
The print macros support Rich markup syntax:
[bold]text[/]- Bold text[red]text[/]- Colored text[bold red on blue]text[/]- Combined styles[[and]]- Escaped brackets (literal[and])
§Important: Bracket Handling
The markup parser uses a smart heuristic to distinguish between style tags and data brackets:
- Valid Tags:
[bold],[red],[link=url]-> Parsed as style - Data:
[1, 2, 3],[Unknown]-> Printed literally as text
This means standard debug output usually works out of the box:
use fast_rich::println;
let data = vec![1, 2, 3];
println!("Data: {:?}", data); // Prints: Data: [1, 2, 3]However, there is a Known Limitation: if your data looks exactly like a style tag, the parser will consume it.
// ⚠️ Unintended Tag Collision
let colors = vec!["red", "blue"];
// Parser sees "[red", parses it as color tag!
// println!("Colors: {:?}", colors);For untrusted input or strict correctness, always use the _raw macros:
use fast_rich::println_raw;
let colors = vec!["red", "blue"];
println_raw!("Colors: {:?}", colors); // ✅ Safe: Prints ["red", "blue"]§Macro Summary
| Macro | Markup | Use Case |
|---|---|---|
print! / println! | ✅ Smart | Styled output & most debug data |
print_raw! / println_raw! | ❌ Skipped | Strict raw data output |
rprint! / rprintln! | ✅ Smart | Alias (when you need both std and rich) |
§Macro Summary
| Macro | Markup | Use Case |
|---|---|---|
print! / println! | ✅ Parsed | Styled output you control |
print_raw! / println_raw! | ❌ Skipped | Data output, debug values |
rprint! / rprintln! | ✅ Parsed | Alias (when you need both std and rich) |
Re-exports§
pub use console::Console;pub use layout::Layout;pub use live::Live;pub use panel::BorderStyle;pub use panel::Panel;pub use renderable::Renderable;pub use rule::Rule;pub use style::Color;pub use style::Style;pub use table::Column;pub use table::ColumnAlign;pub use table::Table;pub use text::Alignment;pub use text::Text;pub use tree::Tree;pub use tree::TreeNode;
Modules§
- align
- Alignment wrapper for renderables.
- bar
- Bar charts for visualizing data.
- box_
drawing - Box drawing characters and styles.
- columns
- Multi-column layout for displaying content in columns.
- console
- Console abstraction for terminal output.
- emoji
- Emoji name to Unicode character mapping.
- filesize
- Filesize formatting utilities.
- group
- Render groups for combining multiple renderables.
- highlighter
- Highlighters for pattern-based text styling.
- inspect
- Introspection tools for debugging.
- layout
- live
- log
- Logging utilities similar to Rich’s console.log().
- markup
- Markup parser for Rich-style markup syntax.
- measure
- Measure API for calculating renderable dimensions.
- nested_
progress - Nested progress bars support.
- padding
- Padding wrapper for renderables.
- pager
- Pager for interactive output pagination.
- panel
- Panels for displaying content in a box with optional title.
- prelude
- Prelude module for convenient imports.
- progress
- Progress bars, spinners, and status indicators.
- prompt
- Interactive prompt module.
- renderable
- The Renderable trait defines objects that can be rendered to the console.
- rule
- Horizontal rules for visual separation.
- screen
- Alternate screen support for full-screen terminal applications.
- style
- Style and color types for terminal output.
- table
- Tables for displaying structured data.
- text
- Text and Span types for styled text with wrapping and alignment.
- theme
- Theme system for consistent styling.
- traceback
- Pretty traceback/panic rendering.
- tree
- Tree rendering for hierarchical data.
Macros§
- eprint
- Print formatted text with Rich markup to stderr (no newline).
- eprint_
raw - Print to stderr without markup parsing (no newline).
- eprintln
- Print formatted text with Rich markup to stderr (with newline).
- eprintln_
raw - Print to stderr without markup parsing (with newline).
- log
- Macro for logging with file/line information.
- Print formatted text with Rich markup to stdout (no newline).
- print_
raw - Print to stdout without markup parsing (no newline).
- println
- Print formatted text with Rich markup to stdout (with newline).
- println_
raw - Print to stdout without markup parsing (with newline).
- rprint
- Alias for
print!- use when you need bothstd::print!and rich print. - rprintln
- Alias for
println!- use when you need bothstd::println!and rich println.