### Create and Render a Basic Table Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-table/README.md Quick start example demonstrating how to create a new table, set headers, add rows, and render it. ```rust use lipgloss_table::Table; let mut t = Table::new() .headers(vec!["Name", "Age", "City"]) .row(vec!["Alice", "30", "New York"]) .row(vec!["Bob", "25", "London"]); println!("{}", t.render()); ``` -------------------------------- ### Install lipgloss-table with features Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-table/README.md Use the batteries-included facade for installation, recommended for most use cases. ```toml [dependencies] lipgloss-extras = { version = "0.1.0", features = ["tables"] } ``` -------------------------------- ### Install lipgloss-tree with Features Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-tree/README.md Shows how to add `lipgloss-extras` with the `trees` feature enabled for a batteries-included approach. ```toml [dependencies] lipgloss-extras = { version = "0.1.0", features = ["trees"] } ``` -------------------------------- ### Install lipgloss-list directly Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-list/README.md Provides the TOML dependency configuration for directly installing the `lipgloss-list` crate and its dependency `lipgloss`. ```toml [dependencies] lipgloss-list = "0.1.0" lipgloss = "0.1.0" ``` -------------------------------- ### Install lipgloss-extras with list feature Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-list/README.md Provides the TOML dependency configuration for installing the `lipgloss-extras` crate with the `lists` feature enabled. ```toml [dependencies] lipgloss-extras = { version = "0.1.0", features = ["lists"] } ``` -------------------------------- ### Basic Usage with Prelude Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/docs/API.md Import common items using the `prelude` module for easy access to `Style` and `Color`. This example demonstrates creating a styled string. ```rust use lipgloss_extras::prelude::*; let style = Style::new().foreground(Color::from("201")); println!("{}", style.render("Hello, world!")); ``` -------------------------------- ### Install Lipgloss-extras with Specific Features Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/README.md Add the lipgloss-extras crate with specific features like 'lists' and 'tables' enabled to manage dependencies more granularly. ```toml [dependencies] lipgloss-extras = { version = "0.1.0", features = ["lists", "tables"] } ``` -------------------------------- ### Install lipgloss-table directly Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-table/README.md Alternatively, depend directly on the lipgloss-table component and lipgloss for styling. ```toml [dependencies] lipgloss-table = "0.1.0" lipgloss = "0.1.0" ``` -------------------------------- ### Basic Styling with Lipgloss Extras Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/README.md Demonstrates basic styling using the Style and Color types from lipgloss_extras. This example requires the 'full' feature or specific features like 'lists'. ```rust use lipgloss_extras::prelude::*; fn main() { let style = Style::new().foreground(Color::from("201")); #[allow(unused)] let list = List::new().items(vec!["A", "B", "C"]); println!("{}", style.render("installed with extras")); } ``` -------------------------------- ### Basic Usage of lipgloss-extras Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-extras/README.md Demonstrates how to use the Style and Color types from lipgloss_extras::lipgloss to style text. This example requires the `lists` feature to be enabled if you were to use the `List` type. ```rust use lipgloss_extras::lipgloss::{Style, Color}; #[cfg(feature = "lists")] use lipgloss_extras::list::List; fn main() { let s = Style::new().foreground(Color::from("#ff6b6b")); println!("{}", s.render("hello")); } ``` -------------------------------- ### Complete Responsive Layout Example Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/docs/API.md Builds a centered responsive layout with a header and content area. It detects terminal width, applies styles, joins components vertically, and centers the final layout within the terminal. ```rust use lipgloss_extras::lipgloss::{ join_vertical, place, Style, Color, CENTER, LEFT, rounded_border, }; use crossterm::terminal; // A dependency of lipgloss fn main() { // --- Step 1: Detect Terminal Size --- let terminal_width = match terminal::size() { Ok((cols, _)) => cols as i32, Err(_) => 80, // Fallback width }; // --- Step 2: Create and Apply Responsive Styles --- // Header Style let header_style = Style::new() .bold(true) .foreground(Color::from("#FAFAFA")) .background(Color::from("#7D56F4")) .padding(0, 1, 0, 1); // Main Content Style let content_style = Style::new() .border(rounded_border()) .border_foreground(Color::from("63")) .padding(1, 2, 1, 2); // Render the components let header = header_style.render("My Awesome App"); let content = content_style.render("This is the main content area.\nIt will be centered within the terminal."); // Combine the components vertically let app_view = join_vertical(LEFT, &[&header, &content]); // Place the entire application view in the center of the terminal window let final_layout = place( terminal_width, // Use the detected width here lipgloss_extras::lipgloss::height(&app_view) as i32, CENTER, CENTER, &app_view, &[], ); println!("{}", final_layout); } ``` -------------------------------- ### Install Core Lipgloss Crate Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/README.md Add only the core lipgloss crate to your project if you do not need the additional components provided by lipgloss-extras. ```toml [dependencies] lipgloss = "0.1.0" ``` -------------------------------- ### Install lipgloss-tree Directly Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-tree/README.md Provides the TOML dependency configuration for directly including `lipgloss-tree` and `lipgloss` in your project. ```toml [dependencies] lipgloss-tree = "0.1.0" lipgloss = "0.1.0" ``` -------------------------------- ### Set Minimum Width and Height Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/README.md Define minimum dimensions for a style. This example also shows setting foreground color. ```rust use lipgloss_extras::lipgloss::{Style, Color}; let style = Style::new() .set_string("What's for lunch?") .width(24) .height(32) .foreground(Color::from("63")); ``` -------------------------------- ### Style::new() Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/docs/API.md Creates a new, empty Style object with default settings. This is the starting point for building custom text styles. ```APIDOC ## Style::new() ### Description Creates a new, empty style with default settings. ### Method `Style::new() -> Style` ### Parameters None ### Request Example ```rust use lipgloss_extras::lipgloss::Style; let style = Style::new(); ``` ### Response Returns a new `Style` object. ``` -------------------------------- ### Apply Text Attributes Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/docs/API.md Configure text formatting such as bold, italic, and underline using fluent builder methods on the `Style` struct. This example applies both bold and underline. ```rust use lipgloss_extras::lipgloss::Style; let special_style = Style::new() .bold(true) .underline(true) .foreground("201"); println!("{}", special_style.render("Special Announcement")); ``` -------------------------------- ### Control List Visibility and Item Subsets Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-list/README.md Demonstrates how to hide an entire list using `hide(true)` or display only a subset of items using `offset(start, end)`. ```rust use lipgloss_list::List; let visible_slice = List::new().items(vec!["A", "B", "C", "D"]).offset(1, 1); let hidden = List::new().items(vec!["X", "Y"]).hide(true); println!("{}", visible_slice); assert_eq!(format!("{}", hidden), ""); ``` -------------------------------- ### Set Foreground and Background Colors Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/docs/API.md Define text and background colors using various formats, including hex strings and `AdaptiveColor` for theme-aware styling. This snippet shows examples of both. ```rust use lipgloss_extras::lipgloss::{Style, Color, AdaptiveColor}; // Using a hex color string let style1 = Style::new().background("#7D56F4"); // Using an AdaptiveColor for theme-awareness let style2 = Style::new().foreground(AdaptiveColor { light: "#333", dark: "#EEE" }); ``` -------------------------------- ### Apply Borders to Styled Text Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/docs/API.md This example demonstrates how to add borders to styled text using predefined border styles like `rounded_border()`. Import `Style` and the desired border function. ```rust use lipgloss_extras::lipgloss::{Style, rounded_border}; let border_style = Style::new() .border(rounded_border()) .border_foreground("63"); println!("{}", border_style.render("A bordered box.")); ``` -------------------------------- ### Create Color Gradients in Rust Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/docs/API.md Generates a visual gradient bar using a specified start and end hex color. Requires `lipgloss_extras::lipgloss::{gradient, Style}`. ```rust use lipgloss_extras::lipgloss::{gradient, Style}; // Create a gradient bar let colors = gradient("#FF6B6B", "#4ECDC4", 20); let mut bar = String::new(); for color in colors { bar.push_str(&Style::new().background(color).render(" ")); } println!("{}", bar); ``` -------------------------------- ### Style Table Cells with a Boxed Closure Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-table/README.md For complex styling logic, use a boxed closure to capture state. This example highlights the first column based on row index. ```rust use lipgloss::{Color, Style}; use lipgloss_table::{Table, HEADER_ROW}; let highlight = Color::from("201"); let mut t = Table::new() .headers(vec!["Status", "Message"]) .row(vec!["ERROR", "Something went wrong"]) .row(vec!["OK", "All good"]) .style_func_boxed(move |row, col| { if row == HEADER_ROW { return Style::new().bold(true); } if col == 0 { match row { 0 => Style::new().foreground(highlight.clone()), _ => Style::new(), } } else { Style::new() } }); println!("{}", t.render()); ``` -------------------------------- ### Create a Basic List Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-list/README.md Demonstrates how to create a simple list with items using the `List::new()` constructor and the `items()` method. ```rust use lipgloss_list::List; let l = List::new() .items(vec!["A", "B", "C"]); println!("{}", l); ``` -------------------------------- ### Run Simple List Demo Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-list/README.md Command to run the simple list demo package from the repository root. ```bash cargo run --package simple-list-demo ``` -------------------------------- ### Run Simple Tree Demo Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-tree/README.md Command to run the simple tree demonstration package. ```bash cargo run --package tree-demo-simple ``` -------------------------------- ### Run Styles Tree Demo Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-tree/README.md Command to run the styled tree demonstration package. ```bash cargo run --package tree-demo-styles ``` -------------------------------- ### Run Files Tree Demo Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-tree/README.md Command to run the file system tree demonstration package. ```bash cargo run --package tree-demo-files ``` -------------------------------- ### Run lipgloss-table Demos in Bash Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-table/README.md Execute various demo packages for lipgloss-table using Cargo from the repository root. ```bash cargo run --package table-demo-languages cargo run --package table-demo-chess cargo run --package table-demo-mindy cargo run --package table-demo-pokemon cargo run --package table-demo-ansi ``` -------------------------------- ### Running lipgloss-rs Demos Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/README.md Commands to execute various demo applications provided with the lipgloss-rs library, showcasing different functionalities. ```bash # Layout demo - comprehensive styling showcase cargo run --package layout-demo ``` ```bash # Simple list rendering demo cargo run --package simple-list-demo ``` ```bash # Languages table rendering demo cargo run --package table-demo-languages ``` ```bash # Simple tree rendering demo cargo run --package tree-demo-simple ``` -------------------------------- ### Run List Demo Glow Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-list/README.md Command to run the list demo package named glow from the repository root. ```bash cargo run --package list-demo-glow ``` -------------------------------- ### Run List Demo Grocery Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-list/README.md Command to run the list demo package named grocery from the repository root. ```bash cargo run --package list-demo-grocery ``` -------------------------------- ### Basic Tree Creation in Rust Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-tree/README.md Demonstrates how to create a simple hierarchical tree structure with leaves and nested trees using the `Tree` and `Leaf` components. ```rust use lipgloss_tree::{Leaf, Node, Tree}; let t = Tree::new().root(".") .child(vec![ Box::new(Leaf::new("macOS", false)) as Box, Box::new( Tree::new().root("Linux") .child(vec![ Box::new(Leaf::new("NixOS", false)) as Box, Box::new(Leaf::new("Arch Linux (btw)", false)) as Box, ]) ) as Box, ]); println!("{}", t); ``` -------------------------------- ### Create and Render a Styled Table Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/docs/API.md Illustrates creating a table with headers, data rows, a fixed width, and a custom styling function for cells. ```rust use lipgloss_extras::lipgloss::{Style, Color, CENTER}; use lipgloss_extras::table::{Table, HEADER_ROW}; let data = vec![ vec!["Pikachu", "Electric", "Static"], vec!["Charmander", "Fire", "Blaze"], ]; let style_fn = |row, col| { if row == HEADER_ROW { return Style::new().bold(true).align_horizontal(CENTER); } // Custom styling for data rows... Style::new() }; let table = Table::new() .headers(vec!["Pokémon", "Type", "Ability"]) .rows(data) .width(40) .style_func_boxed(Box::new(style_fn)); println!("{}", table.render()); ``` -------------------------------- ### Running the Theme Showcase Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/README.md Commands to run the lipgloss-rs theme showcase application. Includes testing with default, explicit light, and explicit dark terminal themes. ```bash cargo run --package theme-showcase ``` ```bash # Test with explicit light theme COLORFGBG='0;15' cargo run --package theme-showcase ``` ```bash # Test with explicit dark theme COLORFGBG='15;0' cargo run --package theme-showcase ``` -------------------------------- ### Run List Demo Duckduckgoose Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-list/README.md Command to run the list demo package named duckduckgoose from the repository root. ```bash cargo run --package list-demo-duckduckgoose ``` -------------------------------- ### Styled Tree Creation in Rust Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-tree/README.md Shows how to apply custom `lipgloss` styles to the root, enumerators, and items of a tree component for enhanced visual presentation. ```rust use lipgloss::{Color, Style}; use lipgloss_tree::{Leaf, Node, Tree}; let t = Tree::new() .root("Project") .root_style(Style::new().bold(true).foreground(Color::from("63"))) .enumerator_style(Style::new().foreground(Color::from("238")).padding_right(1)) .item_style(Style::new().foreground(Color::from("201"))) .child(vec![ Box::new(Leaf::new("README.md", false)) as Box, Box::new(Leaf::new("src/", false)) as Box, ]); println!("{}", t); ``` -------------------------------- ### Create and Render a Nested List Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/docs/API.md Demonstrates creating a new list with items and a nested sublist using roman numeral enumeration. ```rust use lipgloss_extras::list::{List, roman}; let list = List::new() .item("First item") .item("Second item") .item_list( List::new() .items(vec!["Sub-item A", "Sub-item B"]) .enumerator(roman) ); println!("{}", list); ``` -------------------------------- ### Create a New Style Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/docs/API.md Instantiate a new `Style` object using `Style::new()`. This creates a style with default settings, ready to be configured. ```rust use lipgloss_extras::lipgloss::Style; let style = Style::new(); ``` -------------------------------- ### Set Layout and Sizing Properties Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/docs/API.md Use this snippet to control the dimensions, padding, margin, and alignment of styled blocks. Ensure `lipgloss_extras::lipgloss` is imported. ```rust use lipgloss_extras::lipgloss::{Style, CENTER, BOTTOM}; let block_style = Style::new() .width(40) .height(10) .padding(1, 2, 1, 2) .margin(1, 1, 1, 1) .align_horizontal(CENTER) .align_vertical(BOTTOM); println!("{}", block_style.render("Aligned content.")); ``` -------------------------------- ### Run List Demo Roman Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-list/README.md Command to run the list demo package named roman from the repository root. ```bash cargo run --package list-demo-roman ``` -------------------------------- ### Compare Go and Rust Output with xxd Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/docs/TREE_IN_LIST_SPACING_ISSUE.md Compare the byte-by-byte output of Go and Rust test cases for complex sublists to identify differences in rendering. ```bash # Go output cd lipgloss-master && go test -v TestComplexSublist | xxd ``` ```bash # Rust output cargo test -p lipgloss-list golden_complex_sublist 2>&1 | xxd ``` -------------------------------- ### Adjust Brightness and Mix Colors Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/README.md Demonstrates adjusting the brightness of a base color and applying it as a background with white foreground text. Use `lighten` for increasing brightness. ```rust use lipgloss_extras::lipgloss::{Style, Color, lighten}; // Brightness adjustments and color mixing let base_color = Color::from("#7C3AED"); let bright_style = Style::new() .background(lighten(&base_color, 0.3)) .foreground(Color::from("#FFFFFF")); ``` -------------------------------- ### Use Theme-Aware Constants in Rust Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/docs/API.md Demonstrates using predefined theme-aware constants for text and status colors. Ensure `lipgloss_extras::lipgloss` is imported. ```rust use lipgloss_extras::lipgloss::{Style, TEXT_PRIMARY, STATUS_SUCCESS}; let normal_text = Style::new().foreground(TEXT_PRIMARY); let success_text = Style::new().foreground(STATUS_SUCCESS); println!("{}", normal_text.render("This is standard text.")); println!("{}", success_text.render("Operation successful!")); ``` -------------------------------- ### Handle Multiline List Items Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-list/README.md Shows how to create list items that span multiple lines, ensuring correct indentation for continuation lines. ```rust use lipgloss_list::List; let l = List::new().items(vec![ "Item1 \nline 2\nline 3", "Item2 \nline 2\nline 3", "3", ]); println!("{}", l); ``` -------------------------------- ### Create and Render a Tree Structure Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/docs/API.md Shows how to build a tree structure with a root, leaves, and nested subtrees using the Tree component. ```rust use lipgloss_extras::tree::{Tree, Leaf, Node}; let tree = Tree::new().root("Project") .child(vec![ Box::new(Leaf::new("README.md", false)) as Box, Box::new(Tree::new().root("src") .child(vec![ Box::new(Leaf::new("main.rs", false)) as Box ]) ) as Box, ]); println!("{}", tree); ``` -------------------------------- ### Apply Base Styles to Items and Enumerators Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-list/README.md Demonstrates applying a consistent style to all list items using `item_style` and to all enumerators using `enumerator_style`. ```rust use lipgloss::{Color, Style}; use lipgloss_list::List; let l = List::new() .items(vec!["Alpha", "Beta", "Gamma"]) .item_style(Style::new().foreground(Color::from("201"))) .enumerator_style(Style::new().foreground(Color::from("238")).padding_right(1)); println!("{}", l); ``` -------------------------------- ### Style::apply() Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/docs/API.md A convenient alias for the `render()` method, providing an alternative way to apply configured styles to text. ```APIDOC ## Style::apply() ### Description A convenient alias for `render()`. ### Method `apply(&self, text: &str) -> String` ### Parameters * `text` (string) - The text to apply the style to. ### Request Example ```rust use lipgloss_extras::lipgloss::Style; let style = Style::new().bold(true).foreground("red"); let styled_text = style.apply("This is important!"); println!("{}", styled_text); ``` ### Response Returns the styled string with ANSI escape codes. ``` -------------------------------- ### Render a File System Tree Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/README.md Use the `Tree` component to visualize hierarchical data, such as a file system structure. Nodes can be `Leaf` types or other `Tree` structures. ```rust use lipgloss_extras::tree::{Leaf, Node, Tree}; let t = Tree::new().root(".") .child(vec![ Box::new(Leaf::new("macOS", false)) as Box, Box::new( Tree::new().root("Linux") .child(vec![ Box::new(Leaf::new("NixOS", false)) as Box, Box::new(Leaf::new("Arch Linux (btw)", false)) as Box, ]) ) as Box, ]); println!("{}", t); ``` -------------------------------- ### Unsetting Styles Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/docs/API.md Demonstrates how to unset specific styling rules to revert them to their default state. ```APIDOC ## Unsetting Rules ### Description All style rules can be unset, reverting them to their default state. ### Example Usage ```rust use lipgloss_extras::lipgloss::Style; let style = Style::new() .bold(true) .foreground("red") .unset_bold(); // No longer bold, but still red println!("{}", style.render("Just red.")); ``` ``` -------------------------------- ### Create Styled Terminal Block Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/README.md This snippet demonstrates how to create a styled block with borders, background, foreground colors, padding, and alignment. It sets minimum width and height constraints, centers content, and fills the background in whitespace. ```rust use lipgloss_extras::lipgloss::{Style, Color, rounded_border, CENTER}; fn main() { // Create a solid colored block with automatic padding and borders let style = Style::new() .bold(true) .foreground(Color::from("#FAFAFA")) .background(Color::from("#7D56F4")) .padding(1, 2, 1, 2) .width(30) // Minimum width constraint .height(5) // Minimum height constraint .align_horizontal(CENTER) // Center content within width .align_vertical(CENTER) // Center content within height .border_style(rounded_border()) .border(true, true, true, true) .color_whitespace(true); // Fill background in whitespace println!("{}", style.render("Hello, kitty.")); // Creates a solid 30x5 purple block with white text centered inside } ``` -------------------------------- ### Render Text with Style Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/docs/API.md Apply defined styles to a given text string using the `render` method. The `apply` method is an alias for `render`. ```rust use lipgloss_extras::lipgloss::Style; let style = Style::new().bold(true).foreground("red"); let styled_text = style.render("This is important!"); println!("{}", styled_text); ``` -------------------------------- ### Dynamic Item Styling in Rust Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-tree/README.md Illustrates how to dynamically style tree items based on their index using a closure, allowing for alternating or conditional styling. ```rust use lipgloss::{Color, Style}; use lipgloss_tree::Tree; let t = Tree::new() .root("Roman List") .child(vec!["First".into(), "Second".into(), "Third".into()]) .item_style_func(|_, i| { if i % 2 == 0 { Style::new().foreground(Color::from("86")) } else { Style::new().foreground(Color::from("219")) } }); println!("{}", t); ``` -------------------------------- ### Advanced Renderer API in Rust Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-tree/README.md Explains how to use the `Renderer` and `TreeStyle` for full control over tree rendering, including custom styles for roots, enumerators, and items. ```rust use lipgloss::{Color, Style}; use lipgloss_tree::{renderer::{TreeStyle, new_renderer}, Tree}; let style = TreeStyle { root: Style::new().bold(true).foreground(Color::from("63")), enumerator_func: |_, _| Style::new().padding_right(1), item_func: |_, _| Style::new(), enumerator_base: None, item_base: None, }; let tree = Tree::new().root("Styled Tree").child(vec!["Item 1".into(), "Item 2".into()]); let renderer = new_renderer().style(style); println!("{}", renderer.render(&tree, true, "")); ``` -------------------------------- ### Color Methods Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/docs/API.md Methods for setting foreground, background, and border colors. Colors can be specified using hex codes, ANSI indices, or AdaptiveColor for theme-aware styling. ```APIDOC ## Color Methods ### Description Colors can be set for text, backgrounds, borders, and margins. They accept any type that implements `TerminalColor`, including strings for hex codes and ANSI indices. ### Methods * `.foreground(color)`: Sets the text color. * `.background(color)`: Sets the background color. * `.margin_background(color)`: Sets the background color for margin areas. * `.border_foreground(color)`: Sets the color for all border sides. * `.border_background(color)`: Sets the background for all border sides. * `.border_top_foreground(color)`: Sets the color for the top border. * `.border_right_foreground(color)`: Sets the color for the right border. * ... (and so on for all sides) ### Request Example ```rust use lipgloss_extras::lipgloss::{Style, Color, AdaptiveColor}; // Using a hex color string let style1 = Style::new().background("#7D56F4"); // Using an AdaptiveColor for theme-awareness let style2 = Style::new().foreground(AdaptiveColor { light: "#333", dark: "#EEE" }); ``` ``` -------------------------------- ### Use Predefined Enumerators Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-list/README.md Shows how to apply different built-in enumerator styles like arabic, roman, alphabet, bullet, dash, and asterisk to a list. ```rust use lipgloss_list::{List, roman, arabic, alphabet, bullet, dash, asterisk}; let a = List::new().items(vec!["Foo", "Bar", "Baz"]).enumerator(arabic); let r = List::new().items(vec!["Foo", "Bar", "Baz"]).enumerator(roman); let ab = List::new().items(vec!["Foo", "Bar", "Baz"]).enumerator(alphabet); let b = List::new().items(vec!["Foo", "Bar", "Baz"]).enumerator(bullet); let d = List::new().items(vec!["Foo", "Bar", "Baz"]).enumerator(dash); let s = List::new().items(vec!["Foo", "Bar", "Baz"]).enumerator(asterisk); println!("{}\n\n{}\n\n{}\n\n{}\n\n{}\n\n{}", a, r, ab, b, d, s); ``` -------------------------------- ### Test Go Implementation of Complex Sublist Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/docs/TREE_IN_LIST_SPACING_ISSUE.md Execute this bash command to run the Go tests for `TestComplexSublist` and filter the output for lines related to 'tree within'. This is useful for comparing behavior between Go and Rust implementations. ```bash cd lipgloss-master && go test -v TestComplexSublist 2>&1 | grep -A 20 "tree within" ``` -------------------------------- ### Layout & Sizing Methods Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/docs/API.md These methods control the dimensions, spacing, and alignment of styled blocks within the lipgloss-rs library. ```APIDOC ## Layout & Sizing ### Description Methods to control the dimensions, spacing, and alignment of styled blocks. ### Methods - `.width(i32)`: Sets a minimum width. Content will be padded to fit. - `.height(i32)`: Sets a minimum height. Content will be padded to fit. - `.max_width(i32)`: Sets a maximum width. Content will wrap or be truncated. - `.max_height(i32)`: Sets a maximum height. Content will be truncated. - `.padding(t, r, b, l)`: Sets padding for all four sides. - `.padding_shorthand(&[i32])`: Sets padding using CSS-style shorthand (1-4 values). - `.margin(t, r, b, l)`: Sets margin for all four sides. - `.margin_shorthand(&[i32])`: Sets margin using CSS-style shorthand (1-4 values). - `.align_horizontal(pos)`: Sets horizontal alignment (`LEFT`, `CENTER`, `RIGHT`). - `.align_vertical(pos)`: Sets vertical alignment (`TOP`, `CENTER`, `BOTTOM`). ### Example Usage ```rust use lipgloss_extras::lipgloss::{Style, CENTER, BOTTOM}; let block_style = Style::new() .width(40) .height(10) .padding(1, 2, 1, 2) .margin(1, 1, 1, 1) .align_horizontal(CENTER) .align_vertical(BOTTOM); println!("{}", block_style.render("Aligned content.")); ``` ``` -------------------------------- ### Create Nested Lists (Sublists) Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-list/README.md Demonstrates how to embed a list within another list by using the `item_list` method, creating nested structures. ```rust use lipgloss_list::{List, roman}; let l = List::new() .item("A") .item("B") .item_list(List::new().items(vec!["C1", "C2", "C3"]).enumerator(roman)) .item("D"); println!("{}", l); ``` -------------------------------- ### Add lipgloss-extras Dependency Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/docs/API.md Add the lipgloss-extras crate with the 'full' feature enabled to your Cargo.toml file. This provides access to the core lipgloss library and all components. ```toml [dependencies] lipgloss-extras = { version = "0.1.0", features = ["full"] } ``` -------------------------------- ### Add lipgloss-extras to Cargo.toml Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-extras/README.md Specify the lipgloss-extras dependency in your Cargo.toml file. You can enable all features with `full` or select specific features like `lists` and `tables`. ```toml [dependencies] # Everything: lipgloss-extras = { version = "0.1.0", features = ["full"] } # or cherry-pick: # lipgloss-extras = { version = "0.1.0", features = ["lists", "tables"] } ``` -------------------------------- ### Style::render() Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/docs/API.md Applies all configured style properties to the given text and returns a string with the appropriate ANSI escape sequences. This is the primary method for outputting styled text. ```APIDOC ## Style::render() ### Description Applies all configured style properties to the given text and returns a string with the appropriate ANSI escape sequences. ### Method `render(&self, text: &str) -> String` ### Parameters * `text` (string) - The text to apply the style to. ### Request Example ```rust use lipgloss_extras::lipgloss::Style; let style = Style::new().bold(true).foreground("red"); let styled_text = style.render("This is important!"); println!("{}", styled_text); ``` ### Response Returns the styled string with ANSI escape codes. ``` -------------------------------- ### Copying Styles in Lipgloss Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/README.md Explicitly create a copy of a style using `.clone()` or implicitly create a new modified style with each builder method call. ```rust use lipgloss_extras::lipgloss::{Style, Color}; let style = Style::new().foreground(Color::from("219")); let copied_style = style.clone(); // this is a true copy let wild_style = style.blink(true); // this is also a new copy, with blink added ``` -------------------------------- ### Fixed Column Widths and Padding Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-table/README.md Set fixed column widths and add padding using the style function. The widest explicit width per column is respected. ```rust use lipgloss::Style; use lipgloss_table::{Table, HEADER_ROW}; let style_fn = |row: i32, col: usize| { let mut s = Style::new(); if row == HEADER_ROW { s = s.bold(true); } // Fix the first column to width 12, add padding to all cells if col == 0 { s = s.width(12); } s.padding(0, 1, 0, 1) }; let mut t = Table::new() .headers(vec!["Name", "Role"]) .row(vec!["Alice Johnson", "Engineer"]) .row(vec!["Bob", "PM"]) .style_func(style_fn) .width(32); println!("{}", t.render()); ``` -------------------------------- ### Apply Predefined Table Styles Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-table/README.md Utilize predefined helper functions like `zebra_style` for common styling patterns. ```rust use lipgloss_table::{Table, header_row_style, zebra_style, minimal_style}; let mut t = Table::new() .headers(vec!["Item", "Qty"]) .row(vec!["Apples", "3"]) .row(vec!["Bananas", "5"]) .style_func(zebra_style); println!("{}", t.render()); ``` -------------------------------- ### Configure Tab Rendering in Lipgloss Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/README.md Control how tab characters are rendered by setting the tab width for a style. Use `NO_TAB_CONVERSION` to leave tabs as they are. ```rust use lipgloss_extras::lipgloss::{Style, NO_TAB_CONVERSION}; let style = Style::new(); // tabs will render as 4 spaces, the default let style_2 = style.clone().tab_width(2); // render tabs as 2 spaces let style_0 = style.clone().tab_width(0); // remove tabs entirely let style_neg_1 = style.clone().tab_width(NO_TAB_CONVERSION); // leave tabs intact ``` -------------------------------- ### Border Methods Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/docs/API.md Methods for applying and customizing borders around styled content. ```APIDOC ## Borders ### Description Provides a rich border system with several presets and individual side control. ### Methods - `.border(border)`: Sets the border style and enables all sides. - `.border_style(border)`: Sets the border style without enabling sides. - `.border_top(bool)`: Enables or disables the top border. - `.border_right(bool)`: Enables or disables the right border. - `.border_bottom(bool)`: Enables or disables the bottom border. - `.border_left(bool)`: Enables or disables the left border. ### Available Border Presets `normal_border()`, `rounded_border()`, `thick_border()`, `double_border()`, `block_border()`, `hidden_border()`, `markdown_border()`, `ascii_border()`. ### Example Usage ```rust use lipgloss_extras::lipgloss::{Style, rounded_border}; let border_style = Style::new() .border(rounded_border()) .border_foreground("63"); println!("{}", border_style.render("A bordered box.")); ``` ``` -------------------------------- ### Apply Block-Level Padding and Margins Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/README.md Configure padding and margins for block-level elements. Supports individual sides or shorthand CSS-like properties. ```rust use lipgloss_extras::lipgloss::Style; // Padding let style = Style::new() .padding_top(2) .padding_right(4) .padding_bottom(2) .padding_left(4); // Margins let style = Style::new() .margin_top(2) .margin_right(4) .margin_bottom(2) .margin_left(4); ``` ```rust // 2 cells on all sides Style::new().padding(2, 2, 2, 2); // 2 cells on the top and bottom, 4 cells on the left and right Style::new().margin(2, 4, 2, 4); ``` -------------------------------- ### Create and Render a Filtered Table in Rust Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-table/README.md Use `StringData` to provide rows and `Filter` to conditionally include rows based on a predicate. The table is then configured with headers and width before rendering. ```rust use lipgloss_table::{rows::{StringData, Filter}, Table}; let data = StringData::new(vec![ vec!["A".into(), "1".into()], vec!["B".into(), "2".into()], vec!["C".into(), "3".into()], ]); let filtered = Filter::new(data).filter(|row| row % 2 == 0); // keep even rows let mut t = Table::new() .headers(vec!["Key", "Val"]) .data(filtered) .width(18); println!("{}", t.render()); ``` -------------------------------- ### Create Custom Borders Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/README.md Define and apply custom border characters to styles for unique visual appearances. ```rust use lipgloss_extras::lipgloss::{Border, Style}; let my_cute_border = Border::new( "._.:*:", "._.:*:", "|*", "|*", "*", "*", "*", "*", "*", "*", "*", "*", "*", ); let custom_style = Style::new() .border_style(my_cute_border) .border(true, true, true, true) .width(22) .height(3); ``` -------------------------------- ### Create Basic 1D Color Gradients Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/README.md Generates a specified number of colors between two hex color codes. Useful for creating smooth transitions for text or background elements. ```rust use lipgloss_extras::lipgloss::{gradient, Style}; // Create smooth color gradients let colors = gradient("#FF0000", "#0000FF", 10); for color in colors { let block = Style::new() .set_string("██") .background(color) .render(""); print!("{}", block); } ``` -------------------------------- ### Unset Specific Style Rules Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/docs/API.md Demonstrates how to remove specific styling rules, such as bold text, while retaining others like foreground color. Import `Style` to use this functionality. ```rust use lipgloss_extras::lipgloss::Style; let style = Style::new() .bold(true) .foreground("red") .unset_bold(); // No longer bold, but still red println!("{}", style.render("Just red.")); ``` -------------------------------- ### Multiline Content in Tree Items in Rust Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-tree/README.md Demonstrates how to handle tree items that contain multiple lines of text, ensuring correct indentation and alignment for each line. ```rust use lipgloss_tree::Tree; let tree = Tree::new().root("Logs").child(vec![ "Build:\nOK".into(), "Test:\nFAIL\nflake".into(), ]); println!("{}", tree); ``` -------------------------------- ### Use Custom Indenter for Sublists Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-list/README.md Explains how to customize the indentation string for sublists using the `indenter` method with a custom function. ```rust use lipgloss_list::List; use lipgloss_tree::Children; fn arrow_indenter(_items: &dyn Children, _i: usize) -> String { "→ ".into() } let l = List::new() .items(vec!["Foo", "Bar", "Baz"]) .indenter(arrow_indenter); println!("{}", l); ``` -------------------------------- ### Table Width, Wrapping, and Truncation Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-table/README.md Control table width, enable content wrapping, or truncate with ellipsis. `width()` constrains total width, `wrap()` toggles behavior. ```rust use lipgloss_table::Table; let mut wrap_demo = Table::new() .headers(vec!["Product", "Description"]) .row(vec![ "MacBook Pro", "Powerful laptop for developers with long descriptions that wrap", ]) .width(40) .wrap(true); let mut trunc_demo = Table::new() .headers(vec!["Product", "Description"]) .row(vec![ "MacBook Pro", "This description will be truncated rather than wrapped", ]) .width(30) .wrap(false); println!("{}\n\n{}", wrap_demo.render(), trunc_demo.render()); ``` -------------------------------- ### Style List Items Conditionally Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-list/README.md Shows how to apply different styles to list items based on their index using `item_style_func`. ```rust use lipgloss::{Color, Style}; use lipgloss_list::List; use lipgloss_tree::Children; let l = List::new() .items(vec!["First", "Second", "Third", "Fourth"]) .item_style_func(|_items: &dyn Children, i| { if i % 2 == 0 { Style::new().foreground(Color::from("86")) } else { Style::new().foreground(Color::from("219")) } }) .enumerator_style_func(|items: &dyn Children, i| { if i == items.length() - 1 { Style::new().bold(true) } else { Style::new() } }); println!("{}", l); ``` -------------------------------- ### Generate 2D Bilinear Interpolation Grids Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/README.md Creates a 2D grid of colors using bilinear interpolation between four corner colors. This is useful for generating complex color backgrounds or patterns. ```rust use lipgloss_extras::lipgloss::bilinear_interpolation_grid; // 2D color grids with bilinear interpolation let grid = bilinear_interpolation_grid( 8, 4, // 8 columns, 4 rows ("#FF0000", "#00FF00", "#0000FF", "#FFFF00") // corner colors ); ``` -------------------------------- ### Enforce Style Constraints Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/README.md Use `inline`, `max_width`, and `max_height` to control how styles render, such as forcing single-line output or limiting dimensions. ```rust use lipgloss::Style; // Force rendering onto a single line, ignoring margins, padding, and borders. let some_style = Style::new().inline(true); // Limit rendering to a 5x5 cell block let block_style = Style::new().max_width(5).max_height(5); ``` -------------------------------- ### Expected Tree Spacing in List Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/docs/TREE_IN_LIST_SPACING_ISSUE.md Illustrates the correct spacing for tree symbols within a list, as expected by golden test files. Note the single space after '├──' and three spaces after '│'. ```text ├── another (1 space after tree symbol) │ multine (3 spaces after │) │ string (3 spaces after │) ``` -------------------------------- ### Render a Table with Custom Styles Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/README.md Use the `Table` component to render data with custom borders, headers, and row styling. The `style_func_boxed` allows for per-row/column styling. ```rust use lipgloss_extras::lipgloss::{style::Style, thick_border, Color, CENTER}; use lipgloss_extras::table::{Table, HEADER_ROW}; let data: Vec> = vec![ vec!["Chinese", "您好", "你好"], vec!["Japanese", "こんにちは", "やあ"], vec!["Russian", "Здравствуйте", "Привет"], ]; let style_func = move |row: i32, col: usize| -> Style { // Styles... Style::new().padding(0, 1, 0, 1) // placeholder }; let t = Table::new() .border(thick_border()) .border_style(Style::new().foreground(Color::from("238"))) .wrap(true) .headers(vec!["LANGUAGE", "FORMAL", "INFORMAL"]) .width(46) .rows(data) .style_func_boxed(style_func); println!("{}", t); ``` -------------------------------- ### Adaptive Color Constants in Rust Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/README.md Uses semantic color constants from lipgloss-rs to style text, status indicators, and UI elements. These constants automatically adapt to light and dark terminal backgrounds. ```rust use lipgloss_extras::lipgloss::{ Style, TEXT_PRIMARY, TEXT_MUTED, TEXT_SUBTLE, STATUS_SUCCESS, STATUS_WARNING, STATUS_ERROR, ACCENT_PRIMARY, SURFACE_ELEVATED }; // Text hierarchy - automatically adjusts contrast let title = Style::new().foreground(TEXT_PRIMARY).bold(true); let body = Style::new().foreground(TEXT_MUTED); let caption = Style::new().foreground(TEXT_SUBTLE).italic(true); // Status indicators - semantic colors for different states let success = Style::new() .foreground(STATUS_SUCCESS) .render("✓ Operation completed"); let warning = Style::new() .background(STATUS_WARNING) .foreground(Color::from("#000000")) .padding(0, 1, 0, 1) .render("⚠ Check configuration"); // UI surfaces with proper contrast let card = Style::new() .background(SURFACE_ELEVATED) .border(rounded_border()) .padding(1, 2, 1, 2); ``` -------------------------------- ### Custom Enumerators and Indenters in Rust Source: https://github.com/whit3rabbit/lipgloss-rs/blob/main/lipgloss-tree/README.md Demonstrates using built-in or custom functions for enumerators and indenters to control the appearance of tree branches and prefixes. ```rust use lipgloss_tree::{default_indenter, rounded_enumerator, Tree}; let t = Tree::new() .root("Cute Rounds") .enumerator(rounded_enumerator) .indenter(default_indenter) .child(vec!["Foo".into(), "Bar".into(), "Baz".into()]); println!("{}", t); ``` ```rust use lipgloss_tree::{Children, Tree}; let t = Tree::new() .root("Custom") .enumerator(|children: &dyn Children, i| { if i == children.length() - 1 { "╰──".to_string() } else { "├──".to_string() } }) .indenter(|children: &dyn Children, i| { if i == children.length() - 1 { " ".to_string() } else { "│ ".to_string() } }) .child(vec!["A".into(), "B".into(), "C".into()]); println!("{}", t); ```