rusty-rich 0.2.0

Rich text and beautiful formatting in the terminal โ€” a Rust port of Python's Rich library
Documentation
<p align="center">
  <img src="assets/logo.svg" alt="rusty-rich logo" width="600"/>
</p>

<p align="center">
  <strong>Rich text and beautiful formatting for the terminal โ€” a Rust port of Python's <a href="https://github.com/Textualize/rich">Rich</a> library.</strong>
</p>

<p align="center">
  <a href="https://crates.io/crates/rusty-rich"><img src="https://img.shields.io/crates/v/rusty-rich?color=F74C00" alt="crates.io"></a>
  <a href="https://docs.rs/rusty-rich"><img src="https://img.shields.io/docsrs/rusty-rich?color=F74C00" alt="docs.rs"></a>
  <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License: MIT"></a>
  <a href="#"><img src="https://img.shields.io/badge/tests-171%20passed-brightgreen" alt="tests"></a>
</p>

---

## โœจ Features

- ๐ŸŽจ **Style** โ€” foreground/background colors, bold, italic, underline, dim, blink, reverse, strikethrough
- ๐Ÿ“ **Console markup** โ€” `[bold red]text[/bold red]` BBCode-like inline styling
- ๐Ÿ“Š **Table** โ€” tabular data with headers, footers, colspan/rowspan, column alignment, sections
- ๐ŸŒฒ **Tree** โ€” hierarchical tree rendering with Unicode guides
- ๐Ÿ“ฆ **Panel** โ€” bordered containers with titles, subtitles, 17 box styles
- โž– **Rule** โ€” horizontal dividers with optional titles
- ๐Ÿ“ **Padding & Align** โ€” CSS-style spacing and alignment helpers
- ๐Ÿ“‹ **Columns** โ€” side-by-side layout
- ๐Ÿ—‚๏ธ **Layout** โ€” recursive split-pane layout system with ratio sizing
- โณ **Progress** โ€” multi-task progress bars with 7 column types, file tracking
- ๐Ÿ”„ **Spinner** โ€” 36+ animated spinners with name-based lookup
- ๐Ÿ“Œ **Status** โ€” spinner + message with in-place update
- ๐Ÿ”„ **Live** โ€” auto-updating live displays with alt-screen support
- ๐ŸŒˆ **Syntax highlighting** โ€” powered by syntect (100+ languages)
- ๐Ÿ“ **Markdown** โ€” headings, code blocks, lists, blockquotes, links
- ๐Ÿ“‹ **JSON** โ€” pretty-printed, syntax-highlighted output
- ๐Ÿ” **Logging** โ€” Rich-formatted log records via the `log` crate
- ๐Ÿ–ผ๏ธ **Box drawing** โ€” 17 box styles (rounded, square, heavy, double, ASCII, etc.)
- ๐ŸŽฏ **TrueColor / 256 / Standard** color with automatic detection and downgrade
- ๐Ÿ–ฅ๏ธ **Screen / Alt-screen** โ€” full-screen terminal applications
- โŒจ๏ธ **Prompts** โ€” `Prompt`, `IntPrompt`, `FloatPrompt`, `Confirm`, `Select<T>`, password mode
- ๐Ÿ”ด **Traceback** โ€” rich exception rendering with locals, source code, frame suppression
- ๐Ÿ“ค **HTML & SVG export** โ€” capture console output for the web
- ๐ŸŽญ **Themes** โ€” named style maps with stack-based inheritance

## ๐Ÿ“ฆ Installation

```toml
[dependencies]
rusty-rich = "0.1"
```

## ๐Ÿš€ Quick Start

```rust
use rusty_rich::{
    Console, Panel, Table, Column, Rule, Tree,
    Style, Color, AlignMethod, Padding,
};

fn main() {
    let mut console = Console::new();

    // Print with markup
    console.print_str("[bold green]Hello, [red]World![/red][/bold green]");

    // Create a panel with a title
    let panel = Panel::new("Hello inside a rounded box!")
        .title("My Panel")
        .border_style(Style::new().color(Color::parse("cyan").unwrap()));
    console.println(&panel);

    // Create a table
    let mut table = Table::new();
    table.add_column(Column::new("Name").justify(AlignMethod::Left));
    table.add_column(Column::new("Age").justify(AlignMethod::Right));
    table.add_row_str(vec!["Alice".into(), "30".into()]);
    table.add_row_str(vec!["Bob".into(), "25".into()]);
    console.println(&table);

    // Create a tree
    let mut tree = Tree::new("Root");
    tree.add("Child 1").add("Grandchild");
    tree.add("Child 2");
    console.println(&tree);

    // Draw a rule
    console.rule("Section Break", None, None, None);
}
```

## ๐Ÿ“Š Table with Colspan & Rowspan

```rust
use rusty_rich::Table;

let mut table = Table::new().title("User Report");
table.add_column(Column::new("Name"));
table.add_column(Column::new("Details").colspan(2));  // spans 2 columns
table.add_column(Column::new("Role"));                  // skipped by colspan above

// Cell-based rows with colspan/rowspan
let row = vec![
    Cell::new("Alice"),
    Cell::new("Engineer").colspan(2),
];
table.add_row(row);
```

## โณ Progress Bars

```rust
use rusty_rich::Progress;
use std::thread;
use std::time::Duration;

let mut progress = Progress::new();
let task_id = progress.add_task("Downloading...", Some(100.0));

for i in 0..=100 {
    progress.update(task_id, i as f64);
    print!("\r{}", progress.render(80));
    thread::sleep(Duration::from_millis(20));
}
println!();

// Or use the `track()` convenience
let items: Vec<_> = (0..100).collect();
let tracker = progress.track(items, "Processing", None);
for item in tracker {
    // process item
}
```

## โŒจ๏ธ Interactive Prompts

```rust
use rusty_rich::{Prompt, Confirm, IntPrompt, Select};

// String input
let name = Prompt::ask_with("Enter your name").unwrap();

// Password input (masked)
let password = Prompt::new("Password").password(true).ask().unwrap();

// Confirmation
let ok = Confirm::ask_with("Continue?", true).unwrap();

// Integer with validation
let age = IntPrompt::ask_with("Enter age").unwrap();

// Pick from choices
let choice = Select::new("Pick a color")
    .add("Red", "red")
    .add("Green", "green")
    .add("Blue", "blue")
    .ask()
    .unwrap();
```

## ๐Ÿ”ด Rich Tracebacks

```rust
use rusty_rich::traceback;

// Install a global panic hook for rich tracebacks
traceback::install();

// Or render manually
let tb = Traceback::from_exception("MyError", "something went wrong", frames)
    .show_locals(true)
    .max_frames(5)
    .suppress(vec!["std::".into(), "core::".into()]);
```

## ๐Ÿ–ฅ๏ธ Full-Screen Apps

```rust
use rusty_rich::{Console, Screen, Live};
use std::thread;
use std::time::Duration;

let mut console = Console::new();
let mut screen = console.screen();  // enters alternate screen
screen.enter();

// Use Live for auto-updating regions
let mut live = Live::new(Panel::new("Loading...").title("Status"));
live.start();

for i in 0..=100 {
    let panel = Panel::new(format!("Progress: {}%", i))
        .title("Status");
    live.update(panel);
    thread::sleep(Duration::from_millis(50));
}

live.stop();
screen.exit();  // restores terminal
```

## ๐ŸŽจ Box Styles (17 built-in)

| Style | Preview |
|---|---|
| `BOX_ROUNDED` | โ•ญโ”€โ•ฎ โ”‚ โ”‚ โ•ฐโ”€โ•ฏ |
| `BOX_SQUARE` | โ”Œโ”€โ” โ”‚ โ”‚ โ””โ”€โ”˜ |
| `BOX_HEAVY` | โ”โ”โ”“ โ”ƒ โ”ƒ โ”—โ”โ”› |
| `BOX_DOUBLE` | โ•”โ•โ•— โ•‘ โ•‘ โ•šโ•โ• |
| `BOX_DOUBLE_EDGE` | โ•”โ•โ•— โ•‘ โ”‚ โ•šโ•โ• |
| `BOX_HEAVY_EDGE` | โ”โ”โ”“ โ”ƒ โ”‚ โ”—โ”โ”› |
| `BOX_HEAVY_HEAD` | โ”โ”โ”“ โ”ƒ โ”ƒ โ””โ”€โ”˜ |
| `BOX_SIMPLE` | borderless with separators |
| `BOX_MINIMAL` | minimal horizontal rules |
| `BOX_ASCII` | `+--+` ASCII-safe |
| โ€ฆ and 7 more |

## ๐ŸŽฏ Color System

```rust
use rusty_rich::{Color, Style};

// Named colors
let red = Color::parse("red").unwrap();
let hot_pink = Color::parse("#FF69B4").unwrap();

// TrueColor โ†’ 8-bit โ†’ Standard auto-downgrade
let style = Style::new()
    .color(Color::parse("#FF6600").unwrap())
    .bgcolor(Color::parse("#1E1E2E").unwrap())
    .bold(true)
    .italic(true);
```

## ๐Ÿ“‚ Module Map

```
src/
โ”œโ”€โ”€ lib.rs              # Crate root + re-exports
โ”œโ”€โ”€ console.rs          # Central rendering engine
โ”œโ”€โ”€ screen.rs           # Full-screen / alt-screen
โ”œโ”€โ”€ color.rs            # TrueColor / 256 / Standard
โ”œโ”€โ”€ style.rs            # 13 attributes + hyperlinks
โ”œโ”€โ”€ theme.rs            # Named style maps + stack
โ”œโ”€โ”€ segment.rs          # Styled text segment + control codes
โ”œโ”€โ”€ text.rs             # Text with Span styling
โ”œโ”€โ”€ cells.rs            # Unicode cell width utilities
โ”œโ”€โ”€ measure.rs          # Width measurement protocol
โ”œโ”€โ”€ align.rs            # Horizontal + vertical alignment
โ”œโ”€โ”€ ratio.rs            # Proportional space distribution
โ”œโ”€โ”€ markup.rs           # BBCode-like markup parser
โ”œโ”€โ”€ highlighter.rs      # Regex/Repr highlighters
โ”‚
โ”œโ”€โ”€ panel.rs            # Bordered container
โ”œโ”€โ”€ table.rs            # Tabular data + colspan/rowspan
โ”œโ”€โ”€ tree.rs             # Hierarchical tree
โ”œโ”€โ”€ rule.rs             # Horizontal divider
โ”œโ”€โ”€ padding.rs          # CSS-style padding
โ”œโ”€โ”€ columns.rs          # Side-by-side layout
โ”œโ”€โ”€ layout.rs           # Split-pane layout
โ”œโ”€โ”€ box_drawing.rs      # 17 box/border styles
โ”‚
โ”œโ”€โ”€ progress.rs         # Multi-task progress + track()
โ”œโ”€โ”€ progress_columns.rs # 7 progress column types
โ”œโ”€โ”€ spinner.rs          # 36+ animated spinners
โ”œโ”€โ”€ status.rs           # Spinner + message
โ”œโ”€โ”€ live.rs             # Auto-updating display
โ”‚
โ”œโ”€โ”€ syntax.rs           # Syntax highlighting (syntect)
โ”œโ”€โ”€ markdown.rs         # Markdown rendering (pulldown-cmark)
โ”œโ”€โ”€ json.rs             # Pretty-printed JSON
โ”œโ”€โ”€ logging.rs          # log crate integration
โ”œโ”€โ”€ prompt.rs           # Interactive prompts
โ””โ”€โ”€ traceback.rs        # Rich exception tracebacks
```

## ๐Ÿ”ฌ Compared to Python Rich

| Feature | Python Rich | rusty-rich |
|---|---|---|
| Console + markup | โœ… | โœ… |
| Text / Span / Style | โœ… | โœ… |
| Table (colspan/rowspan) | โœ… | โœ… |
| Panel / Rule / Tree | โœ… | โœ… |
| Layout / Columns | โœ… | โœ… |
| Progress (7 column types) | โœ… | โœ… |
| Live / Status | โœ… | โœ… |
| Syntax highlighting | โœ… | โœ… |
| Markdown / JSON | โœ… | โœ… |
| Traceback (locals, suppress) | โœ… | โœ… |
| Screen / Alt-screen | โœ… | โœ… |
| Prompts (5 types) | โœ… | โœ… |
| 36+ Spinners | โœ… | โœ… |
| 17 Box styles | โœ… | โœ… |
| HTML / SVG export | โœ… | โœ… |
| Logging handler | โœ… | โœ… |
| Jupyter integration | โœ… | โ€” |
| File watching | โœ… | โ€” |
| **Overall parity** | | **~90%** |

## ๐Ÿงช Testing

```bash
cargo test                    # 171 unit tests + 7 doctests
cargo test --test battle_test # Integration / battle tests
```

## ๐Ÿ“„ License

MIT โ€” See [LICENSE](LICENSE) for details.

---

<p align="center">
  <sub>Inspired by <a href="https://github.com/Textualize/rich">Textualize/rich</a> โ€” the Python library that makes terminal output beautiful.</sub>
</p>