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
//! Demonstrates using fast-rich's print!/println! macros as drop-in replacements
//! for the standard library versions.
//!
//! Run with: cargo run --example print_shadowing
// Shadow the standard library print macros with rich versions
use fast_rich::{print, println};
fn main() {
// Basic rich markup
println!("[bold green]Success![/] All systems operational.");
println!();
// Format arguments work exactly like std::println!
let name = "Alice";
let score = 100;
println!(
"[cyan]Player[/]: {} scored [yellow]{}[/] points",
name, score
);
println!();
// Named arguments
println!(
"[magenta]{role}[/] {name} completed [blue]{task}[/]",
role = "Admin",
name = "Bob",
task = "backup"
);
println!();
// Colors and styles
println!("[red]Error[/] | [yellow]Warning[/] | [green]Info[/] | [blue]Debug[/]");
println!();
// print! without newline for inline progress
print!("[blue]Processing[/]");
for _ in 0..3 {
print!(".");
std::thread::sleep(std::time::Duration::from_millis(300));
}
println!(" [bold green]Done![/]");
println!();
// Complex formatting
println!(
"[bold magenta]Statistics[/]:\n • Items: [cyan]{}[/]\n • Status: [green]{}[/]",
42, "Active"
);
println!();
// ==========================================================================
// Handling data with brackets (like debug output)
// ==========================================================================
//
// The markup parser is smart: it ignores brackets if they don't look like styles.
// So simple debug output often "just works":
let data = vec![1, 2, 3, 4, 5];
println!("[yellow]Vector (auto):[/] {:?}", data); // Works thanks to smart parser!
// However, for strict raw output (or if data might contain valid style syntax),
// use `println_raw!` to skip markup parsing entirely:
use fast_rich::println_raw;
let map = std::collections::HashMap::from([("a", 1), ("b", 2)]);
print!("[cyan]HashMap (raw):[/] ");
println_raw!("{:?}", map);
// ✅ Regular values without brackets work fine with styled println!
println!("[green]Length:[/] {}", data.len());
println!();
// ==========================================================================
// LIMITATION: Unintended Tag Collisions
// ==========================================================================
// If your debug data looks exactly like a style tag, the "smart" parser
// will be fooled and consume it.
//
// Example: A singleton Vec of an Enum named "Red".
// Debug output is "[Red]". "Red" is a valid color.
#[derive(Debug)]
enum Status {
Red,
}
let status = vec![Status::Red];
// ⚠️ PROBLEM: {:?} prints "[Red]" -> interpreted as color red!
// The parser consumes [Red], text becomes red, and content disappears.
print!("Problem: ");
println!("{:?}", status);
// ✅ SOLUTION: Use `println_raw!` to force literal output
print!("Fixed: ");
println_raw!("{:?}", status);
println!();
// ==========================================================================
// Printing to Stderr
// ==========================================================================
use fast_rich::{eprint, eprintln};
eprintln!("[bold red]Critical Error:[/] Connection failed");
eprint!("[bold magenta]Loading stderr...[/]");
eprintln!("[green]OK[/]");
// Using raw stderr macro for data
use fast_rich::eprintln_raw;
eprintln_raw!("Error Context: {:?}", vec!["timeout", "retry"]);
println!();
// ==========================================================================
// Using aliases when you need both std and rich
// ==========================================================================
use fast_rich::rprintln;
std::println!("Standard print (no markup): [bold]this is literal[/]");
rprintln!("Rich print: [bold]this is bold[/]");
}