Expand description
§rich_rust
A Rust port of Python’s Rich library for beautiful terminal output.
This library provides an abstraction over ANSI escape codes to render styled text, tables, panels, progress bars, trees, and more in the terminal.
§Quick Start
ⓘ
use rich_rust::prelude::*;
let console = Console::new();
console.print("[bold red]Hello[/] [green]World[/]!");§Core Concepts
Console: The central entry point for printing styled output. Handles color detection, terminal dimensions, and ANSI code generation.Style: Visual attributes including foreground/background colors, text decorations (bold, italic, underline, etc.), and hyperlinks.Text: Rich text with overlapping style spans that can be justified, wrapped, and rendered to the terminal.Segment: The atomic rendering unit combining text content with a style.Color: Terminal colors supporting 4-bit ANSI, 8-bit (256), and 24-bit true color with automatic downgrading.
§Renderables
The library provides several high-level renderables for structured output:
renderables::Table: Display data in rows and columns with bordersrenderables::Panel: Frame content with a title and borderrenderables::Tree: Hierarchical data with guide linesrenderables::ProgressBar: Visual progress indicatorsrenderables::Rule: Horizontal divider linesrenderables::Columns: Multi-column text layout
§Markup Syntax
The Console supports a simple markup syntax for inline styling:
ⓘ
// Basic styling
console.print("[bold]Bold text[/bold]");
console.print("[italic red]Red italic[/]"); // [/] closes any open tag
// Colors
console.print("[green]Green[/] [#ff8800]Orange[/] [rgb(100,150,200)]Blue[/]");
// Combinations
console.print("[bold underline magenta on white]Styled text[/]");
// Hyperlinks
console.print("[link=https://example.com]Click here[/link]");§Features
Optional features can be enabled in Cargo.toml:
syntax: Syntax highlighting for source code via syntectmarkdown: Markdown rendering via pulldown-cmarkjson: JSON formatting with syntax highlightingtracing: Tracing integration viaRichTracingLayer
[dependencies]
rich_rust = { version = "0.1", features = ["syntax", "markdown", "json"] }§Examples
§Styled Text
ⓘ
use rich_rust::prelude::*;
// Build text programmatically
let mut text = Text::new("Hello, ");
text.append("World", Style::new().bold().color(Color::parse("red").unwrap()));
text.append("!", Style::new().italic());
let console = Console::new();
console.print_text(&text);§Tables
ⓘ
use rich_rust::prelude::*;
let table = Table::new()
.add_column(Column::new("Name").style(Style::new().bold()))
.add_column(Column::new("Age").justify(JustifyMethod::Right))
.add_row(Row::new().cell("Alice").cell("30"))
.add_row(Row::new().cell("Bob").cell("25"));
console.print_renderable(&table);§Panels
ⓘ
use rich_rust::prelude::*;
let panel = Panel::new("Content inside a box")
.title("My Panel")
.border_style(Style::new().color(Color::parse("blue").unwrap()));
console.print_renderable(&panel);§Trees
ⓘ
use rich_rust::prelude::*;
let tree = Tree::new(
TreeNode::new("Project")
.child(TreeNode::new("src")
.child(TreeNode::new("main.rs"))
.child(TreeNode::new("lib.rs")))
.child(TreeNode::new("Cargo.toml")),
);
console.print_renderable(&tree);Re-exports§
pub use color::Color;pub use color::ColorSystem;pub use color::ColorTriplet;pub use color::ColorType;pub use console::Console;pub use live::Live;pub use live::LiveOptions;pub use live::VerticalOverflowMethod;pub use logging::RichLogger;pub use renderables::Layout;pub use renderables::LayoutSplitter;pub use renderables::Region;pub use segment::Segment;pub use style::Attributes;pub use style::Style;pub use text::Span;pub use text::Text;
Modules§
- box
- Box drawing characters for tables and panels.
- cells
- Unicode character cell width calculations.
- color
- Color system for terminal rendering.
- console
- Console - the central entry point for styled terminal output.
- live
- Live display system for dynamic terminal updates.
- logging
- Logging integration similar to Python Rich’s
RichHandler. - markup
- Markup parsing for Rich-style text.
- measure
- Measurement protocol for determining renderable dimensions.
- prelude
- Re-exports for convenient usage
- renderables
- Renderable components for rich terminal output.
- segment
- Segment - the atomic rendering unit.
- style
- Style system for terminal text attributes.
- terminal
- Terminal detection and manipulation.
- text
- Rich text with styled spans.