rusty-rich 0.4.1

Rich text and beautiful formatting in the terminal โ€” a Rust port of Python's Rich library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
<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-778%20passed-brightgreen" alt="tests"></a>
</p>

---

## โœจ Features

- ๐ŸŽจ **Style** โ€” 13 text attributes (bold, italic, underline, dim, blink, reverse, strikethrough, overline, conceal, frame, encircle, blink2, underline2), links, metadata, style chaining & combination
- ๐Ÿ“ **Console markup** โ€” `[bold red]text[/bold red]` BBCode-like inline styling
- ๐ŸŽฏ **256 named colors** โ€” full ANSI 256-color palette with aliases, hex, RGB, auto-downgrade, color blending
- ๐ŸŽญ **170+ theme styles** โ€” repr, json, markdown, logging, traceback, rule, bar, progress, table, tree, syntax, prompt categories with stack-based inheritance

- ๐Ÿ“Š **Table** โ€” tabular data with headers, footers, row/column styling, colspan/rowspan, sections, 17 box styles, `.grid()` classmethod
- ๐ŸŒฒ **Tree** โ€” hierarchical tree rendering with Unicode/ASCII guides
- ๐Ÿ“ฆ **Panel** โ€” bordered containers with titles, subtitles, padding, `.fit()` for auto-sizing
- โž– **Rule** โ€” horizontal dividers with optional centered, left-, or right-aligned titles
- ๐Ÿ“ **Padding & Align** โ€” CSS-style padding (1โ€“4 sides) and horizontal/vertical alignment wrappers
- ๐Ÿ“‹ **Columns** โ€” side-by-side column layout with equal-width and expand options
- ๐Ÿ—‚๏ธ **Layout** โ€” recursive split-pane layout engine with ratio sizing, named regions, and pluggable splitters

- โณ **Progress** โ€” multi-task progress bars with 11 column types, `track()`/`wrap_file()`/`open()` wrappers, file tracking
- ๐Ÿ”„ **Spinner** โ€” 55 animated spinners with case-insensitive name lookup
- ๐Ÿ“Œ **Status** โ€” spinner + message with in-place refresh
- ๐Ÿ”„ **Live** โ€” auto-updating displays with `LiveWriter` for stdout/stderr capture

- ๐ŸŒˆ **Syntax highlighting** โ€” powered by syntect (100+ languages), `.from_path()`, `.guess_lexer()`, `.stylize_range()`
- ๐Ÿ“ **Markdown** โ€” headings, code blocks, lists, blockquotes, links, tables, image placeholders
- ๐Ÿ“‹ **JSON** โ€” pretty-printed, syntax-highlighted JSON
- ๐Ÿ” **Logging** โ€” `RichHandler` for the `log` crate + standalone `LogRender` formatter with table output

- ๐Ÿ–ผ๏ธ **Box drawing** โ€” 17 box styles (rounded, square, heavy, double, ASCII, markdown, etc.)
- ๐Ÿ–ฅ๏ธ **Screen / Alt-screen** โ€” full-screen terminal applications with `ScreenContext` RAII guard
- โŒจ๏ธ **Prompts** โ€” `Prompt`, `IntPrompt`, `FloatPrompt`, `Confirm`, `Select`, password mode
- ๐Ÿ”ด **Traceback** โ€” rich exception rendering with locals, source code, frame suppression, panic hook
- ๐Ÿ” **Inspect** โ€” structured object introspection with attribute and method tables
- ๐ŸŽ›๏ธ **Control** โ€” composable terminal escape sequences (cursor, screen, title, bell, erase)
- ๐Ÿ“ค **HTML & SVG export** โ€” capture console output for the web with 4 preset themes
- ๐Ÿ˜Š **Emoji** โ€” 100+ `:shortcode:` โ†’ Unicode emoji replacement
- ๐ŸŒˆ **Palette** โ€” gradient, rainbow, and monochrome color palette generation
- ๐Ÿ“Š **Bar chart** โ€” horizontal bar chart renderable with labels and auto-scaling
- ๐Ÿ–จ๏ธ **Pretty printing** โ€” `Pretty`, `pprint()`, `pretty_repr()`, `traverse()` with `Node` tree
- ๐Ÿ“Ÿ **Pager** โ€” system pager integration (`$PAGER` / `less`) with `PagerContext` RAII
- ๐Ÿ”ค **ANSI decoder** โ€” parse existing ANSI escape sequences back to styled `Text`
- ๐Ÿงฉ **Segment utilities** โ€” simplify, split_lines, strip_styles, strip_links, align, divide, set_shape, filter_control

## ๐Ÿ“ฆ Installation

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

## ๐Ÿš€ 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("Alice", "30");
    table.add_row_str("Bob", "25");
    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);
}
```

## ๐ŸŽฏ Colors (256 names)

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

// Named colors โ€” 256 ANSI palette
let red = Color::parse("red").unwrap();
let hot_pink = Color::parse("hot_pink").unwrap();
let steel_blue = Color::parse("steel_blue").unwrap();
let grey53 = Color::parse("grey53").unwrap();

// Hex / RGB
let orange = Color::from_hex("#FF6600").unwrap();
let custom = Color::from_rgb(100, 200, 50);

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

## ๐Ÿ“Š Table with Colspan & Rowspan

```rust
use rusty_rich::{Table, Column, Cell};

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

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 with an iterator
let items: Vec<_> = (0..100).collect();
let tracker = progress.track(items, "Processing", None);
for item in tracker {
    // process item โ€” progress auto-advances
}
```

## ๐Ÿ“ Markdown (with tables)

```rust
use rusty_rich::render_markdown;
use rusty_rich::Console;

let md = render_markdown("
# Hello

| Name  | Age |
|-------|-----|
| Alice | 30  |
| Bob   | 25  |

- list item 1
- list item 2
");

let console = Console::new();
console.println(&md);
```

## โŒจ๏ธ Interactive Prompts

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

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

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

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

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

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

## ๐Ÿ”„ Live Display with Writer

```rust
use rusty_rich::{Console, Live, LiveWriter, Panel};
use std::io::Write;
use std::thread;
use std::time::Duration;

let mut live = Live::new(Panel::new("Starting...").title("Status"));
let mut writer = live.create_writer();
live.start().unwrap();

for i in 0..=100 {
    // Redirect writes through the live display
    writeln!(writer, "Processing item {}...", i).unwrap();
    live.update(Panel::new(format!("Progress: {}%", i)).title("Status")).unwrap();
    thread::sleep(Duration::from_millis(50));
}

live.stop().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()]);
```

## ๐Ÿ” Object Inspection

```rust
use rusty_rich::Inspect;

// Inspect any Debug-printable value
let value = vec![1, 2, 3];
let insp = Inspect::new(&value)
    .title("my_vec")
    .add_attr("len", "usize", "3")
    .add_attr("capacity", "usize", "3")
    .add_method("push", "fn push(&mut self, value: T)")
    .add_method("pop", "fn pop(&mut self) -> Option<T>")
    .methods(true);
```

## ๐ŸŽ›๏ธ Terminal Control Sequences

```rust
use rusty_rich::control::{Control, control_clear, control_home, control_bell};

// Ring the bell
let bell = Control::bell();

// Clear screen and go home
let clear = Control::clear_home();

// Move cursor and set window title
let setup = Control::cursor_to(1, 1);
let title = Control::title("My App");

// Strip or escape control codes from strings
use rusty_rich::control::{strip_control_codes, escape_control_codes};
let clean = strip_control_codes("hello\x07world");  // "helloworld"
let escaped = escape_control_codes("\x07");           // "\\a"
```

## ๐Ÿ“‹ Log Record Formatting

```rust
use rusty_rich::LogRender;

let mut renderer = LogRender::new()
    .show_time(true)
    .show_level(true)
    .show_path(true);

// Format a single log record
let record = renderer.render_log(
    Some("2024-01-15T10:30:00"),
    "ERROR",
    "Connection refused",
    Some("src/main.rs"),
    Some(42),
);

// Or render a batch as a table
let records = vec![
    (Some("10:30:00"), "INFO",  "Server started",       Some("main.rs"), Some(10)),
    (Some("10:30:01"), "ERROR", "Connection refused",   Some("net.rs"),  Some(99)),
];
let table = renderer.render_batch(&records);
```

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

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

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

let mut live = Live::new(Panel::new("Loading...").title("Status"));
live.start().unwrap();

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

live.stop().unwrap();
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_SIMPLE_HEAVY` | borderless with heavy separators |
| `BOX_MINIMAL` | minimal horizontal rules |
| `BOX_ASCII` | `+--+` ASCII-safe |
| `BOX_ASCII2` | `+--+` alternate ASCII |
| `BOX_MARKDOWN` | pipe-style markdown tables |
| โ€ฆ and 4 more |

## ๐Ÿงฉ Segment Utilities

```rust
use rusty_rich::segment::{self, Segment, Segments};

let segs: Segments = vec![
    Segment::styled("Hello ", Style::new().bold(true)),
    Segment::styled("World", Style::new().bold(true)),
].into();

// Combine adjacent same-styled segments
let simplified = segs.simplify();           // โ†’ one "Hello World" segment

// Split into lines
let lines = segment::split_lines(&segs.segments);

// Strip all styling
let plain = segment::strip_styles(&segs.segments);  // โ†’ "Hello World"

// Align vertically
let aligned = segment::align_middle(&lines, 80, 10, None);
```

## ๐Ÿ“‚ Module Map (48 modules)

```
src/
โ”œโ”€โ”€ lib.rs              # Crate root + re-exports (~100 types)
โ”œโ”€โ”€ console.rs          # Central rendering engine (148 methods)
โ”œโ”€โ”€ screen.rs           # Full-screen / alt-screen / ScreenContext
โ”œโ”€โ”€ color.rs            # TrueColor / 256 / Standard (256 names)
โ”œโ”€โ”€ style.rs            # 13 attributes + links + metadata + chain/copy
โ”œโ”€โ”€ theme.rs            # 170+ named styles + stack-based inheritance
โ”œโ”€โ”€ segment.rs          # Segment + control codes + 15+ utility fns
โ”œโ”€โ”€ text.rs             # Text with Span styling (99 methods)
โ”œโ”€โ”€ 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/ISO8601/JSON/Path highlighters
โ”‚
โ”œโ”€โ”€ panel.rs            # Bordered container + .fit()
โ”œโ”€โ”€ table.rs            # Tabular data + Row/Cell + sections + .grid()
โ”œโ”€โ”€ tree.rs             # Hierarchical tree with guides
โ”œโ”€โ”€ rule.rs             # Horizontal divider with title
โ”œโ”€โ”€ padding.rs          # CSS-style padding (1โ€“4 sides)
โ”œโ”€โ”€ columns.rs          # Side-by-side column layout
โ”œโ”€โ”€ layout.rs           # Split-pane layout + 4 splitter types
โ”œโ”€โ”€ box_drawing.rs      # 17 box/border styles
โ”‚
โ”œโ”€โ”€ progress.rs         # Multi-task progress + track/wrap_file/open
โ”œโ”€โ”€ progress_columns.rs # 11 progress column types
โ”œโ”€โ”€ spinner.rs          # 55 animated spinners + get_spinner()
โ”œโ”€โ”€ status.rs           # Animated spinner + message
โ”œโ”€โ”€ live.rs             # Auto-updating display + LiveWriter
โ”‚
โ”œโ”€โ”€ syntax.rs           # Syntax highlighting (syntect, 100+ langs)
โ”œโ”€โ”€ markdown.rs         # Markdown rendering + table + image support
โ”œโ”€โ”€ json.rs             # Pretty-printed, syntax-highlighted JSON
โ”œโ”€โ”€ logging.rs          # RichHandler for the log crate
โ”œโ”€โ”€ log_render.rs       # Standalone LogRender formatter (new in 0.3!)
โ”œโ”€โ”€ prompt.rs           # 5 interactive prompt types + Select
โ”œโ”€โ”€ traceback.rs        # Rich exception tracebacks + panic hook
โ”‚
โ”œโ”€โ”€ inspect.rs          # Object introspection (new in 0.3!)
โ”œโ”€โ”€ control.rs          # Terminal control sequences (new in 0.3!)
โ”œโ”€โ”€ pretty.rs           # Pretty printing + Node tree traversal
โ”œโ”€โ”€ emoji.rs            # 100+ :shortcode: โ†’ Unicode emoji
โ”œโ”€โ”€ pager.rs            # System pager ($PAGER / less) + PagerContext
โ”œโ”€โ”€ constrain.rs        # Width constraint wrapper
โ”œโ”€โ”€ styled.rs           # Pre-styled renderable wrapper
โ”œโ”€โ”€ bar.rs              # Horizontal bar chart renderable
โ”œโ”€โ”€ filesize.rs         # Human-readable file size + speed formatting
โ”œโ”€โ”€ containers.rs       # Lines + Renderables grouping
โ”œโ”€โ”€ palette.rs          # Gradient/rainbow/monochrome palettes
โ”œโ”€โ”€ diagnose.rs         # Error diagnostics + reporting
โ”œโ”€โ”€ ansi.rs             # ANSI escape sequence decoder
โ”œโ”€โ”€ scope.rs            # Variable scope rendering
โ”œโ”€โ”€ file_proxy.rs       # Auto-refreshing file display
โ”œโ”€โ”€ repr.rs             # RichRepr trait + auto/rich_repr
โ””โ”€โ”€ export.rs           # HTML / SVG / text export + 4 themes
```

## ๐Ÿ”ฌ Compared to Python Rich

| Feature | Python Rich | rusty-rich |
|---|---|---|
| Console + markup | โœ… | โœ… |
| Text / Span / Style (full API) | โœ… | โœ… |
| 256 named colors | โœ… | โœ… |
| Table (colspan/rowspan/sections/grid) | โœ… | โœ… |
| Panel / Rule / Tree | โœ… | โœ… |
| Layout with splitters | โœ… | โœ… |
| Progress (11 column types, track/wrap/open) | โœ… | โœ… |
| Live / Status | โœ… | โœ… |
| Syntax highlighting + lexer guessing | โœ… | โœ… |
| Markdown + tables + images | โœ… | โœ… |
| JSON / Logging / LogRender | โœ… | โœ… |
| Traceback (locals, suppress, panic hook) | โœ… | โœ… |
| Screen / Alt-screen | โœ… | โœ… |
| Prompts (5 types + Select) | โœ… | โœ… |
| Pretty printing + Node tree | โœ… | โœ… |
| Object inspection (Inspect) | โœ… | โœ… (new in 0.3!) |
| Terminal control sequences (Control) | โœ… | โœ… (new in 0.3!) |
| Emoji + ANSI decoder | โœ… | โœ… |
| System pager + PagerContext | โœ… | โœ… |
| Palette (gradient/rainbow) | โœ… | โœ… |
| Bar chart | โœ… | โœ… |
| FileProxy / Scope / Diagnose | โœ… | โœ… |
| Constrain / Styled / Containers | โœ… | โœ… |
| Repr protocol (RichRepr) | โœ… | โœ… |
| Color property accessors | โœ… | โœ… (new in 0.3!) |
| ISO8601/JSON/Path highlighters | โœ… | โœ… (new in 0.3!) |
| Filesize.decimal() (SI units) | โœ… | โœ… (new in 0.3!) |
| Capture / RenderHooks / ThemeContext | โœ… | โœ… |
| 55+ Spinners | 80+ | 55 |
| 17 Box styles | 20 | 17 |
| HTML / SVG / Text export | โœ… | โœ… |
| 170+ Theme styles | 170+ | 170+ |
| Markdown element tree (extensible) | โœ… | โ€” |
| Pygments theme bridge | โœ… | โ€” (uses syntect) |
| Jupyter support | โœ… | N/A |
| **Overall parity** | | **~88%** |

## ๐Ÿงช Testing

```bash
cargo test                              # 475 unit tests
cargo test --test battle_test           # 103 integration tests
cargo test --test box_table_exhaustive  # 150 exhaustive box/table tests
```

All 778 tests passing. The exhaustive test suite covers every box style ร— every feature combination (colspan, rowspan, sections, alignment, padding, etc.).

## ๐Ÿ“„ 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>