### Run richrs Demo from Source Source: https://github.com/olirice/richrs/blob/master/README.md Instructions on how to clone the richrs repository and run the interactive demo to explore all its features. This requires Git and Cargo to be installed. ```bash git clone https://github.com/olirice/richrs cd richrs cargo run --release ``` -------------------------------- ### Render Basic and Styled Trees in Rust Source: https://context7.com/olirice/richrs/llms.txt Illustrates how to construct and render hierarchical data structures using the richrs Tree component. Covers building trees with nested nodes, applying styles to nodes and guides, controlling node expansion, and customizing guide characters. Also demonstrates hiding the root node. ```rust use richrs::prelude::*; fn main() -> Result<()> { let mut console = Console::new(); // Build tree with builder pattern let mut tree = Tree::new("project"); tree.add( TreeNode::new("src") .with_child(TreeNode::new("main.rs")) .with_child(TreeNode::new("lib.rs")) .with_child( TreeNode::new("modules") .with_child(TreeNode::new("auth.rs")) .with_child(TreeNode::new("db.rs")) ) ); tree.add(TreeNode::new("Cargo.toml")); tree.add(TreeNode::new("README.md")); console.write_segments(&tree.render())?; // Styled tree let mut tree = Tree::new("System") .guide_style(Style::new().with_color(Color::Standard(StandardColor::Blue))); tree.add( TreeNode::new("Users") .style(Style::new().bold()) .with_child(TreeNode::new("admin").style(Style::new().with_color(Color::Standard(StandardColor::Red)))) .with_child(TreeNode::new("guest")) ); tree.add( TreeNode::new("Logs") .expanded(false) // Collapsed node .with_child(TreeNode::new("access.log")) .with_child(TreeNode::new("error.log")) ); console.write_segments(&tree.render())?; // Different guide styles let tree_ascii = Tree::new("Root") .guides(TreeGuides::ASCII); // Uses +-- and | let tree_bold = Tree::new("Root") .guides(TreeGuides::BOLD); // Uses thick lines let tree_rounded = Tree::new("Root") .guides(TreeGuides::ROUNDED); // Uses rounded corners // Hide root node let mut tree = Tree::new("hidden_root") .hide_root(true); tree.add(TreeNode::new("Visible child 1")); tree.add(TreeNode::new("Visible child 2")); console.write_segments(&tree.render())?; Ok(()) } ``` -------------------------------- ### Implement Live Updating Display in Rust Source: https://github.com/olirice/richrs/blob/master/README.md Provides an example of a live display that can be updated in place on the terminal. This is useful for showing continuously changing information, like counters or status updates. It utilizes the `richrs` crate. ```rust use richrs::prelude::*; use std::time::Duration; fn main() -> Result<()> { let mut live = Live::new(); for i in 0..10 { live.update(&format!("Count: {}", i))?; std::thread::sleep(Duration::from_millis(500)); } Ok(()) } ``` -------------------------------- ### Creating and Rendering Panels in Rust Source: https://github.com/olirice/richrs/blob/master/README.md Illustrates how to create a Panel object with a title and subtitle, and then render it to the console. Panels are used to visually group and present content within bordered boxes. ```rust use richrs::prelude::*; fn main() -> Result<()> { let mut console = Console::new(); let panel = Panel::new("Hello from richrs!") .title("Greeting") .subtitle("A Rust port of Rich"); console.write_segments(&panel.render(60))?; Ok(()) } ``` -------------------------------- ### Render Basic and Styled Tables in Rust Source: https://context7.com/olirice/richrs/llms.txt Demonstrates creating and rendering basic and styled tables using the richrs Table component. Includes adding columns, rows, titles, captions, and applying styles to borders, headers, and cells. Also shows how to create a grid layout by using an empty table. ```rust use richrs::prelude::*; fn main() -> Result<()> { let mut console = Console::new(); // Basic table let mut table = Table::new(); table.add_column(Column::new("Name")); table.add_column(Column::new("Age")); table.add_column(Column::new("City")); table.add_row_cells(["Alice", "30", "New York"]); table.add_row_cells(["Bob", "25", "San Francisco"]); table.add_row_cells(["Charlie", "35", "Chicago"]); console.write_segments(&table.render(80))?; // Styled table with column configuration let mut table = Table::new() .title("Employee Directory") .caption("Updated: 2024") .border_style(Style::new().with_color(Color::Standard(StandardColor::Blue))) .header_style(Style::new().bold()); table.add_column( Column::new("Employee") .justify(Justify::Left) .min_width(15) .header_style(Style::new().with_color(Color::Standard(StandardColor::Cyan))) ); table.add_column( Column::new("Department") .justify(Justify::Center) .width(20) ); table.add_column( Column::new("Salary") .justify(Justify::Right) .style(Style::new().with_color(Color::Standard(StandardColor::Green))) ); table.add_row_cells(["John Smith", "Engineering", "$95,000"]); table.add_row_cells(["Jane Doe", "Marketing", "$85,000"]); console.write_segments(&table.render(70))?; // Grid (table without borders, for layout) let mut grid = Table::grid(); grid.add_column(Column::empty()); grid.add_column(Column::empty()); grid.add_row_cells(["Left content", "Right content"]); console.write_segments(&grid.render(60))?; // Table with row objects for styling let mut table = Table::new(); table.add_column(Column::new("Status")); table.add_column(Column::new("Message")); let error_row = Row::new(["ERROR", "Connection failed"]) .style(Style::new().with_color(Color::Standard(StandardColor::Red))); table.add_row(error_row); let success_row = Row::new(["OK", "Operation complete"]) .style(Style::new().with_color(Color::Standard(StandardColor::Green))); table.add_row(success_row); console.write_segments(&table.render(50))?; Ok(()) } ``` -------------------------------- ### Basic Console Output with Markup in Rust Source: https://github.com/olirice/richrs/blob/master/README.md Demonstrates the fundamental usage of the richrs Console to print text with basic styling using BBCode-like markup. This is the entry point for most richrs applications. ```rust use richrs::prelude::*; fn main() -> Result<()> { let mut console = Console::new(); console.print("[bold red]Hello[/] [green]World![/]")?; Ok(()) } ``` -------------------------------- ### Constructing and Displaying Tables in Rust Source: https://github.com/olirice/richrs/blob/master/README.md Demonstrates the creation of a Table with columns and rows, including adding data cells. This allows for structured presentation of tabular data in the terminal. ```rust use richrs::prelude::*; fn main() -> Result<()> { let mut console = Console::new(); let mut table = Table::new(); table.add_column(Column::new("Planet")); table.add_column(Column::new("Moons")); table.add_column(Column::new("Rings")); table.add_row_cells(["Earth", "1", "No"]); table.add_row_cells(["Mars", "2", "No"]); table.add_row_cells(["Saturn", "146", "Yes"]); console.write_segments(&table.render(50))?; Ok(()) } ``` -------------------------------- ### Syntax Highlight Rust Code in Terminal Source: https://github.com/olirice/richrs/blob/master/README.md Shows how to render Rust code snippets with syntax highlighting in the terminal. This feature requires enabling the `syntax` feature for the `richrs` crate and uses the `syntect` dependency. ```rust use richrs::prelude::*; fn main() -> Result<()> { let mut console = Console::new(); let code = r#" fn main() { println!("Hello, world!"); } "#; let syntax = Syntax::new(code, "rust") .line_numbers(true) .theme("base16-ocean.dark"); console.write_segments(&syntax.render(80))?; Ok(()) } ``` -------------------------------- ### Real-time Terminal Updates with RichRS Live Source: https://context7.com/olirice/richrs/llms.txt Illustrates how to use the Live display feature in RichRS for real-time, in-place terminal updates without scrolling. It covers basic usage, configuration options like refresh rate and transient display, and using `run()` for scoped operations. ```rust use richrs::prelude::*; use std::time::Duration; fn main() -> Result<()> { // Basic live display let mut live = Live::new(); live.update("Starting..."); live.start(); for i in 0..10 { live.update(&format!("Processing item {}/10", i + 1)); std::thread::sleep(Duration::from_millis(500)); } live.stop(); // Live with configuration let mut live = Live::new() .refresh_per_second(10.0) .transient(true) // Clear display when stopped .auto_refresh(true); // Auto-update in background live.update("Working..."); live.start(); std::thread::sleep(Duration::from_secs(2)); live.stop(); // Use run() for scoped operation Live::with_content("Initializing...") .transient(false) .run(|live| { for i in 0..5 { live.update(&format!("Step {} of 5", i + 1)); std::thread::sleep(Duration::from_millis(300)); } "Operation complete" }); // Manual refresh (when auto_refresh is false) let live = Live::new().auto_refresh(false); live.update("Content"); live.refresh(); // Manually trigger render Ok(()) } ``` -------------------------------- ### Create Interactive Prompts in Rust Source: https://github.com/olirice/richrs/blob/master/README.md Demonstrates various interactive prompt types: text input, confirmation, and integer input with validation. These prompts enhance user interaction within terminal applications. The `richrs` crate is necessary. ```rust use richrs::prelude::*; fn main() -> Result<()> { // Text prompt let name = Prompt::new("What is your name?").ask()?; // Confirmation let proceed = Confirm::new("Continue?").default(true).ask()?; // Integer with validation let age = IntPrompt::new("Enter your age") .min(0) .max(150) .ask()?; Ok(()) } ``` -------------------------------- ### Rust: Use Spinners for Animated Loading Indicators Source: https://context7.com/olirice/richrs/llms.txt Illustrates how to use spinners for animated loading indicators with various built-in styles and custom options. It covers creating spinners, iterating through frames, accessing metadata, and checking for available spinner styles. Dependencies include `richrs::prelude::*`, `std::thread`, and `std::time::Duration`. ```rust use richrs::prelude::*; use std::thread; use std::time::Duration; fn main() -> Result<()> { // Basic spinner let mut spinner = Spinner::new("dots")?; for _ in 0..50 { print!("\r{} Loading...", spinner.next_frame()); std::io::Write::flush(&mut std::io::stdout())?; thread::sleep(Duration::from_millis(spinner.interval())); } println!("\rDone! "); // Different spinner styles let spinner_line = Spinner::new("line")?; let spinner_dots2 = Spinner::new("dots2")?; let spinner_arc = Spinner::new("arc")?; let spinner_moon = Spinner::new("moon")?; let spinner_clock = Spinner::new("clock")?; let spinner_earth = Spinner::new("earth")?; let spinner_hearts = Spinner::new("hearts")?; let spinner_arrow = Spinner::new("arrow")?; let spinner_bounce = Spinner::new("bouncingBall")?; // Custom spinner let custom = Spinner::custom( vec![".".to_owned(), "..".to_owned(), "...".to_owned()], 200 // interval in ms ); // Spinner metadata println!("Spinner: {}", spinner.name()); println!("Interval: {}ms", spinner.interval()); println!("Frames: {}", spinner.frame_count()); // Check if spinner exists if Spinner::exists("dots") { println!("dots spinner is available"); } // List all available spinners for name in Spinner::names() { println!("Available: {}", name); } // Iterator over frames let spinner = Spinner::new("simple")?; for frame in spinner.frames().take(8) { println!("Frame: {}", frame); } Ok(()) } ``` -------------------------------- ### Building and Rendering Trees in Rust Source: https://github.com/olirice/richrs/blob/master/README.md Shows how to construct a hierarchical Tree structure with nested nodes and then render it to the console. This is useful for visualizing file structures or other tree-like data. ```rust use richrs::prelude::*; fn main() -> Result<()> { let mut console = Console::new(); let mut tree = Tree::new("project"); tree.add( TreeNode::new("src") .with_child(TreeNode::new("main.rs")) .with_child(TreeNode::new("lib.rs")), ); tree.add(TreeNode::new("Cargo.toml")); console.write_segments(&tree.render())?; Ok(()) } ``` -------------------------------- ### Render Content in Decorative Panels with richrs in Rust Source: https://context7.com/olirice/richrs/llms.txt Illustrates how to create and render Panels in Rust using the richrs library. This includes creating simple panels, panels with titles and subtitles, styled panels, and panels with fixed or fitting widths. It also covers ASCII-safe mode for compatibility. ```rust use richrs::prelude::*; fn main() -> Result<()> { let mut console = Console::new(); // Simple panel let panel = Panel::new("Hello from richrs!"); console.write_segments(&panel.render(60))?; // Panel with title and subtitle let panel = Panel::new("This is the main content of the panel.\nIt can span multiple lines.") .title("Important Notice") .subtitle("Read carefully"); console.write_segments(&panel.render(60))?; // Styled panel let panel = Panel::new("Styled content") .title("Alert") .border_style(Style::new().with_color(Color::Standard(StandardColor::Red))) .title_style(Style::new().bold()) .subtitle_style(Style::new().dim()) .padding(2, 1, 2, 1); // left, top, right, bottom console.write_segments(&panel.render(50))?; // Fit panel to content (doesn't expand to full width) let panel = Panel::fit("Short content") .title("Compact"); console.write_segments(&panel.render(80))?; // Fixed width panel let panel = Panel::new("Content") .width(40) .expand(false); console.write_segments(&panel.render(80))?; // ASCII-safe mode for limited terminals let panel = Panel::new("Compatible content") .safe_box(true); // Uses +, -, | characters console.write_segments(&panel.render(40))?; Ok(()) } ``` -------------------------------- ### Style Manipulation and Application in Rust Source: https://context7.com/olirice/richrs/llms.txt Illustrates how to create and manipulate text styles in richrs using string parsing and a builder pattern. It covers applying colors, attributes, and combining styles, as well as generating ANSI escape codes for direct terminal output. ```rust use richrs::prelude::*; fn main() -> Result<()> { // Parse style from string let style = Style::parse("bold red on white")?; let style2 = Style::parse("italic underline #ff5500")?; let style3 = Style::parse("rgb(255, 128, 0) on color(5)")?; // Builder pattern let custom_style = Style::new() .bold() .italic() .underline() .strike() .with_color(Color::Standard(StandardColor::Cyan)) .with_bgcolor(Color::Rgb { r: 50, g: 50, b: 50 }) .link("https://example.com".to_string()); // Combine styles (later style takes precedence) let base = Style::new().bold().with_color(Color::Standard(StandardColor::Red)); let overlay = Style::new().italic().with_bgcolor(Color::Standard(StandardColor::White)); let combined = base.combine(&overlay); // Use with Text let text = Text::styled("Styled text", custom_style); // Available attributes: bold, dim, italic, underline, underline2, // blink, blink2, reverse, conceal, strike, frame, encircle, overline let all_attrs = Style::new() .bold().dim().italic().underline().blink().reverse().strike().overline(); // Generate ANSI escape sequences let ansi_start = style.to_ansi(); let ansi_reset = style.to_ansi_reset(); Ok(()) } ``` -------------------------------- ### Create and Update Progress Bars in Rust Source: https://github.com/olirice/richrs/blob/master/README.md Demonstrates how to create a progress bar with a label and total steps, then advance it incrementally. This is useful for showing the progress of long-running operations. It requires the `richrs` crate. ```rust use richrs::prelude::*; fn main() -> Result<()> { let mut progress = Progress::new(); let task = progress.add_task("Downloading", Some(100), true); for _ in 0..100 { progress.advance(task, 1)?; std::thread::sleep(std::time::Duration::from_millis(20)); } Ok(()) } ``` -------------------------------- ### User Input Prompts with RichRS Source: https://context7.com/olirice/richrs/llms.txt Demonstrates various types of user input prompts available in RichRS, including text, choices, password, styled, confirmation, integer, and float prompts. It shows how to set defaults, validation rules, and styling options. ```rust use richrs::prelude::*; fn main() -> Result<()> { // Text prompt let name = Prompt::new("What is your name?") .default("Anonymous") .ask()?; // Prompt with choices let color = Prompt::new("Choose a color") .choices(["red", "green", "blue"]) .case_sensitive(false) .ask()?; // Password prompt let password = Prompt::new("Enter password") .password(true) .ask()?; // Styled prompt let input = Prompt::new("Enter value") .style(Style::new().bold().with_color(Color::Standard(StandardColor::Cyan))) .show_default(false) .ask()?; // Confirmation prompt let proceed = Confirm::new("Do you want to continue?") .default(true) .ask()?; if proceed { println!("Continuing..."); } // Integer prompt with validation let age = IntPrompt::new("Enter your age") .default(25) .min(0) .max(150) .ask()?; // Float prompt with validation let temperature = FloatPrompt::new("Enter temperature") .default(72.0) .min(-40.0) .max(120.0) .ask()?; println!("Name: {}, Age: {}, Temp: {}", name, age, temperature); Ok(()) } ``` -------------------------------- ### Parse BBCode-like Markup for Inline Styling (Rust) Source: https://context7.com/olirice/richrs/llms.txt Demonstrates how to use the Markup module to parse BBCode-like syntax for inline text styling in Rust. It covers basic styles, colors, background colors, combined styles, nested markup, and negation. The output can be rendered to a Console object or parsed into a Text object. ```rust use richrs::prelude::*; fn main() -> Result<()> { let mut console = Console::new(); // Basic markup console.print("[bold]Bold text[/]")?; console.print("[italic]Italic text[/]")?; console.print("[underline]Underlined[/]")?; // Colors console.print("[red]Red text[/]")?; console.print("[bright_green]Bright green[/]")?; console.print("[#ff5500]Orange (hex)[/]")?; console.print("[rgb(100,150,200)]Custom RGB[/]")?; // Background colors console.print("[white on red]White text on red background[/]")?; console.print("[black on #ffff00]Black on yellow[/]")?; // Combined styles console.print("[bold italic red on white]Multiple styles[/]")?; console.print("[bold underline cyan]Formatted text[/]")?; // Nested markup console.print("[bold]Bold [italic]bold and italic[/] just bold[/]")?; // All text attributes console.print("[bold]Bold[/] [dim]Dim[/] [italic]Italic[/]")?; console.print("[underline]Underline[/] [strike]Strike[/] [reverse]Reverse[/]")?; console.print("[blink]Blink[/] [overline]Overline[/]")?; // Negation console.print("[bold]Bold [not bold]not bold[/] bold again[/]")?; // Style shortcuts console.print("[b]Bold[/] [i]Italic[/] [u]Underline[/] [s]Strike[/]")?; // Links (terminal support varies) console.print("[link https://example.com]Click here[/]")?; // Parse markup to Text object let markup = Markup::parse("[bold red]Hello[/] [green]World[/]")?; let text = markup.to_text(); Ok(()) } ``` -------------------------------- ### Rust: Create and Manage Progress Bars Source: https://context7.com/olirice/richrs/llms.txt Demonstrates how to create, update, and render progress bars for single or multiple tasks. It covers advancing tasks, changing task properties, and customizing the appearance of the progress bar. Dependencies include `richrs::prelude::*`, `std::thread`, and `std::time::Duration`. ```rust use richrs::prelude::*; use std::thread; use std::time::Duration; fn main() -> Result<()> { // Single task progress let mut progress = Progress::new(); let task = progress.add_task("Downloading files", Some(100), true); for i in 0..100 { progress.advance(task, 1)?; thread::sleep(Duration::from_millis(20)); // Render current state let segments = progress.render(80); print!("\r{}", segments.plain_text()); } println!(); // Multiple concurrent tasks let mut progress = Progress::new(); let task1 = progress.add_task("Task 1", Some(50), true); let task2 = progress.add_task("Task 2", Some(100), true); let task3 = progress.add_task("Task 3", Some(75), true); while !progress.finished() { progress.advance(task1, 1).ok(); progress.advance(task2, 2).ok(); progress.advance(task3, 1).ok(); thread::sleep(Duration::from_millis(50)); } // Update task properties let mut progress = Progress::new(); let task = progress.add_task("Processing", Some(100), false); progress.start_task(task)?; progress.update(task, Some(25), None, None, None)?; progress.update(task, None, Some(10), None, None)?; progress.update(task, None, None, Some(200), None)?; progress.update(task, None, None, None, Some(false))?; progress.stop_task(task)?; progress.remove_task(task); // Custom progress bar appearance let bar = ProgressBar::new() .width(30) .complete_char('#') .incomplete_char('-') .complete_style(Style::new().with_color(Color::Standard(StandardColor::Green))) .incomplete_style(Style::new().with_color(Color::Standard(StandardColor::BrightBlack))); let progress = Progress::new().bar(bar); // Query task state if let Some(task_ref) = progress.get_task(task) { let percentage = task_ref.percentage(); let is_done = task_ref.is_complete(); let elapsed = task_ref.elapsed(); let remaining = task_ref.remaining(); let speed = task_ref.speed(); } Ok(()) } ``` -------------------------------- ### Render Markdown Text in Terminal Source: https://github.com/olirice/richrs/blob/master/README.md Demonstrates how to render Markdown text, including basic formatting like bold and italics, within the terminal. This requires the `markdown` feature of the `richrs` crate and uses the `pulldown-cmark` dependency. ```rust use richrs::prelude::*; fn main() -> Result<()> { let mut console = Console::new(); let md = "# Hello\n\nThis is **bold** and *italic* text."; let markdown = Markdown::new(md); console.write_segments(&markdown.render(80))?; Ok(()) } ``` -------------------------------- ### Console Output and Capture in Rust Source: https://context7.com/olirice/richrs/llms.txt Demonstrates the primary usage of the Console struct in richrs for printing styled text using markup, direct styling, Text objects, and drawing rules. It also shows how to capture terminal output for testing and export content as HTML or plain text. ```rust use richrs::prelude::*; fn main() -> Result<()> { let mut console = Console::new(); // Print with markup syntax console.print("[bold red]Error:[/] Something went wrong")?; console.print("[italic cyan]Info:[/] [green]Operation successful[/]")?; // Print styled text directly let style = Style::new().bold().with_color(Color::Standard(StandardColor::Magenta)); console.print_styled("Important message", &style)?; // Print Text objects let text = Text::styled("Custom styled text", Style::new().italic().underline()); console.print_text(&text)?; // Draw horizontal rules console.rule(Some("Section Title"))?; console.rule(None)?; // Plain horizontal line // Output capture for testing console.begin_capture(); console.print("[bold]Captured text[/]")?; let captured = console.end_capture(); println!("Captured: {}", captured); // Recording and export console.begin_recording(); console.print("[red]Red[/] [green]Green[/] [blue]Blue[/]")?; let html = console.export_html()?; let text = console.export_text()?; Ok(()) } ``` -------------------------------- ### Display Animated Spinners in Rust Source: https://github.com/olirice/richrs/blob/master/README.md Shows how to create and display animated spinners with custom frames. This is ideal for indicating that a process is running without a specific progress percentage. It depends on the `richrs` crate. ```rust use richrs::prelude::*; use std::thread; use std::time::Duration; fn main() -> Result<()> { let mut spinner = Spinner::new("dots")?; for _ in 0..50 { print!("\r{} Loading...", spinner.next_frame()); thread::sleep(Duration::from_millis(80)); } println!("\rDone! "); Ok(()) } ``` -------------------------------- ### RichRS Color System for Terminal Styling Source: https://context7.com/olirice/richrs/llms.txt Explores the comprehensive color support in RichRS, including standard ANSI colors, the 256-color palette, and 24-bit true color. It demonstrates creating colors, parsing them from strings (including hex and RGB formats), and using them within styles. ```rust use richrs::prelude::*; fn main() -> Result<()> { // Standard ANSI colors let red = Color::Standard(StandardColor::Red); let bright_blue = Color::Standard(StandardColor::BrightBlue); // 256-color palette let palette_color = Color::Palette(196); // Bright red in 256 palette // 24-bit RGB let rgb_color = Color::rgb(255, 128, 0); // Orange let rgb_alt = Color::Rgb { r: 100, g: 150, b: 200 }; // Parse colors from strings let color1 = Color::parse("red")?; let color2 = Color::parse("bright_cyan")?; let color3 = Color::parse("#ff5500")?; let color4 = Color::parse("#f50")?; let color5 = Color::parse("rgb(255, 128, 64)")?; let color6 = Color::parse("color(42)")?; let color7 = Color::parse("default")?; // Web color names let coral = Color::parse("coral")?; let navy = Color::parse("navy")?; let gold = Color::parse("gold")?; let indigo = Color::parse("indigo")?; // Use in styles let style = Style::new() .with_color(Color::Standard(StandardColor::Green)) .with_bgcolor(Color::Rgb { r: 30, g: 30, b: 30 }); // Generate ANSI escape sequences let fg_ansi = red.to_ansi_fg(); // "\x1b[31m" let bg_ansi = red.to_ansi_bg(); // "\x1b[41m" // Standard color codes let code = StandardColor::Red.code(); // 1 let color_from_code = StandardColor::from_code(5)?; Ok(()) } ``` -------------------------------- ### Pretty Print Debug Data Structures in Rust Source: https://github.com/olirice/richrs/blob/master/README.md Demonstrates how to pretty print any type that implements the `Debug` trait using the `inspect` function. This is helpful for visualizing complex data structures in a readable format. It requires the `richrs` crate. ```rust use richrs::prelude::*; use std::collections::HashMap; fn main() { let mut data = HashMap::new(); data.insert("name", "Alice"); data.insert("role", "Developer"); // Pretty print any Debug type let output = inspect(&data); eprintln!("{}", output); } ``` -------------------------------- ### Text Styling with Markup in Rust Source: https://github.com/olirice/richrs/blob/master/README.md Shows how to apply various text styles like bold and italic using the markup syntax within the richrs Console. This allows for visually distinct text elements in the terminal output. ```rust use richrs::prelude::*; fn main() -> Result<()> { let mut console = Console::new(); // Print with markup console.print("[bold magenta]Welcome[/] to [italic cyan]richrs[/]!")?; // Print styled text console.print("[bold red]Error:[/] Something went wrong")?; Ok(()) } ``` -------------------------------- ### Create and Style Rich Text with Spans in Rust Source: https://context7.com/olirice/richrs/llms.txt Demonstrates various methods for creating and styling Text objects in Rust using the richrs library. This includes creating from strings, applying styles to ranges, highlighting words and regex patterns, and performing text manipulations like truncation and padding. ```rust use richrs::prelude::*; fn main() -> Result<()> { // Create from string let text = Text::from_str("Hello, World!"); // Create with initial style let styled = Text::styled("Bold text", Style::new().bold()); // Assemble from parts let assembled = Text::assemble([ ("Error: ", Some(Style::new().bold().with_color(Color::Standard(StandardColor::Red)))), ("File not found", None), ]); // Build incrementally let mut text = Text::new(); text.append_styled("Warning: ", Style::new().with_color(Color::Standard(StandardColor::Yellow))); text.append_plain("Check your configuration"); text.append_text(&Text::styled(" (important)", Style::new().bold())); // Apply styles to ranges let mut text = Text::from_str("The quick brown fox jumps over the lazy dog"); text.stylize(4, 9, Style::new().bold()); // "quick" text.stylize(10, 15, Style::new().with_color(Color::Standard(StandardColor::Red))); // "brown" text.stylize_all(Style::new().italic()); // Apply to entire text // Highlight words let mut text = Text::from_str("error: connection error occurred"); text.highlight_words(&["error"], &Style::new().with_color(Color::Standard(StandardColor::Red)), false); // Highlight with regex let mut text = Text::from_str("User ID: 12345, Order: 67890"); text.highlight_regex(r"\d+", &Style::new().bold())?; // Text manipulation let truncated = text.truncate(20, Some("...")); let padded = text.pad(50, Justify::Center); let lines = text.split_lines(); // Query style at position let style_at_pos = text.style_at(5); Ok(()) } ``` -------------------------------- ### Implement Status Spinners with Messages in Rust Source: https://github.com/olirice/richrs/blob/master/README.md Illustrates how to use a status spinner that displays a message alongside the animation. This is useful for providing real-time feedback on ongoing tasks. It requires the `richrs` crate. ```rust use richrs::prelude::*; use std::time::Duration; fn main() -> Result<()> { let status = Status::new("Processing data...", "dots")?; status.run(Duration::from_secs(3), || { // Your long-running operation here })?; Ok(()) } ``` -------------------------------- ### Rust: Use Status for Spinner with Message Source: https://context7.com/olirice/richrs/llms.txt Demonstrates how to combine a spinner with a status message for long-running operations. The `Status::run` method executes a closure while displaying the spinner and message, providing visual feedback for the operation's duration. Dependencies include `richrs::prelude::*` and `std::time::Duration`. ```rust use richrs::prelude::*; use std::time::Duration; fn main() -> Result<()> { // Basic status let status = Status::new("Processing data...", "dots")?; status.run(Duration::from_secs(3), || { // Your long-running operation here std::thread::sleep(Duration::from_secs(3)); })?; Ok(()) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.