### Install Dependencies with Bundler Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Installs project dependencies using Bundler. Ensure you have a Gemfile in your project. ```bash bundle install ``` -------------------------------- ### Color Blending Examples Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Examples demonstrating the usage of color blending methods. ```APIDOC #### Generate a 5-color gradient ```ruby colors = Lipgloss::ColorBlend.blends("#FF0000", "#0000FF", 5) # => ["#ff0000", "#c1007f", "#7a00c1", "#0000ff", ...] ``` #### Blend two colors at 50% ```ruby mid = Lipgloss::ColorBlend.blend("#FF0000", "#00FF00", 0.5) # => "#b5b500" ``` ``` -------------------------------- ### Build Go Library and Compile Extension Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Builds the Go library and compiles the Ruby extension. This command is typically run after installing dependencies. ```bash bundle exec rake compile ``` -------------------------------- ### Install Lipgloss Gem Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Add the lipgloss gem to your Gemfile or install it directly using the gem command. ```ruby gem "lipgloss" ``` ```bash gem install lipgloss ``` -------------------------------- ### Create Tree Structures in Ruby Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Build and render hierarchical tree structures using Lipgloss::Tree. This example creates a simple tree with a root and child nodes. ```ruby tree = Lipgloss::Tree.root("Project") .child("src") .child("lib") .child("test") puts tree.render ``` -------------------------------- ### Create Styled Lists in Ruby Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Generate styled lists with custom enumerators like bullets. This example uses the :bullet enumerator for list items. ```ruby list = Lipgloss::List.new .items(["First item", "Second item", "Third item"]) .enumerator(:bullet) puts list.render ``` -------------------------------- ### Style List Items and Enumerators in Ruby Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Customize the appearance of list items and their enumerators using Lipgloss::Style. This example applies red foreground to the enumerator and bold style to list items. ```ruby list = Lipgloss::List.new .items(["Red", "Green", "Blue"]) .enumerator(:bullet) .enumerator_style(Lipgloss::Style.new.foreground("#FF0000")) .item_style(Lipgloss::Style.new.bold(true)) puts list.render ``` -------------------------------- ### Create Nested Tree Structures in Ruby Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Construct complex nested tree structures by adding child trees to parent trees. This example demonstrates nesting 'src' and 'test' trees under a 'Project' root. ```ruby src = Lipgloss::Tree.root("src").child("main.rb").child("helper.rb") test = Lipgloss::Tree.root("test").child("test_main.rb") tree = Lipgloss::Tree.root("Project") .child(src) .child(test) puts tree.render ``` -------------------------------- ### Style Table Cells with StyleFunc in Ruby Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Apply custom styles to table cells, including headers and alternating row colors, using a style function. This example styles header rows and even/odd data rows. ```ruby header_style = Lipgloss::Style.new.bold(true).background("#5A56E0") even_style = Lipgloss::Style.new.background("#3C3C3C") odd_style = Lipgloss::Style.new.background("#4A4A4A") table = Lipgloss::Table.new .headers(["Name", "Role"]) .rows([["Alice", "Engineer"], ["Bob", "Designer"]]) .border(:rounded) .style_func(rows: 2, columns: 2) do |row, column| if row == Lipgloss::Table::HEADER_ROW header_style elsif row.even? even_style else odd_style end end puts table.render ``` -------------------------------- ### Run Basic Demo Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Executes the basic demonstration script for Lipgloss. ```bash ./demo/basic ``` -------------------------------- ### Run Layout Demo Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Executes the demonstration script for layout and positioning features in Lipgloss. ```bash ./demo/layout ``` -------------------------------- ### Run List Demo Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Executes the demonstration script for list rendering with Lipgloss. ```bash ./demo/list ``` -------------------------------- ### Run Table Demo Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Executes the demonstration script for table rendering with Lipgloss. ```bash ./demo/table ``` -------------------------------- ### Run Tree Demo Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Executes the demonstration script for tree structure rendering with Lipgloss. ```bash ./demo/tree ``` -------------------------------- ### Run Colors Demo Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Executes the demonstration script for color-related features in Lipgloss. ```bash ./demo/colors ``` -------------------------------- ### Create and Render Basic Styled Text Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Instantiate a Lipgloss::Style object, apply styles like bold, foreground/background colors, and padding, then render text. ```ruby require "lipgloss" style = Lipgloss::Style.new .bold(true) .foreground("#FAFAFA") .background("#7D56F4") .padding(1, 2) puts style.render("Hello, Lipgloss!") ``` -------------------------------- ### Apply Padding and Margin with Lipgloss Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Demonstrates using CSS-style shorthand and individual-side variants for padding (internal spacing) and margin (external spacing) in Lipgloss. Shows how to apply padding and margin to a style. ```ruby require "lipgloss" # 4-arg shorthand: top=1, right=2, bottom=1, left=2 style = Lipgloss::Style.new.padding(1, 2) puts style.render("Padded") # => " " # " Padded " # " " # Per-side padding style2 = Lipgloss::Style.new .padding_top(1) .padding_right(2) .padding_bottom(1) .padding_left(2) puts style2.render("Same result") # Margin (external spacing) margined = Lipgloss::Style.new.margin(1, 2) puts margined.render("Margin") # => " " # " Margin " # " " # Individual margin sides Lipgloss::Style.new.margin_top(1).margin_left(4).render("Nudged right") ``` -------------------------------- ### Create a Lipgloss Style Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Demonstrates creating a new Style object and applying text formatting and padding. Shows immutability by creating a new style from an existing one. ```ruby require "lipgloss" # Bold purple text on a colored background with padding style = Lipgloss::Style.new .bold(true) .foreground("#FAFAFA") .background("#7D56F4") .padding(1, 2) puts style.render("Hello, Lipgloss!") # => (1 blank line) # Hello, Lipgloss! (styled, with 2-char horizontal padding) # (1 blank line) # Immutability: style is unchanged; heading is a new object heading = style.italic(true).foreground("#FF6B6B") puts heading.render("Still safe to use style above") ``` -------------------------------- ### Apply Text Decorations with Lipgloss Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Shows how to apply various text decorations like bold, italic, underline, strikethrough, faint, blink, and reverse using the Lipgloss::Style object. Demonstrates combining decorations and applying foreground color. ```ruby require "lipgloss" # All text decorations puts Lipgloss::Style.new.bold(true).render("Bold") puts Lipgloss::Style.new.italic(true).render("Italic") puts Lipgloss::Style.new.underline(true).render("Underline") puts Lipgloss::Style.new.strikethrough(true).render("Strikethrough") puts Lipgloss::Style.new.faint(true).render("Faint") puts Lipgloss::Style.new.blink(true).render("Blink") puts Lipgloss::Style.new.reverse(true).render("Reversed fg/bg") # Combined puts Lipgloss::Style.new .bold(true) .underline(true) .foreground("#FFD700") .render("Gold bold underline") ``` -------------------------------- ### Applying Borders with Lipgloss Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Shows how to apply various named border types and control per-side rendering. Custom border characters and per-side foreground colors can also be specified. ```ruby require "lipgloss" # Named border types [:normal, :rounded, :thick, :double, :ascii, :block, :hidden].each do |type| puts Lipgloss::Style.new.border(type).padding(0, 1).render("#{type} border") end ``` ```ruby puts Lipgloss::Style.new.border(:normal, true, false, true, false).render("Top and Bottom") ``` ```ruby puts Lipgloss::Style.new .border(:rounded) .border_top_foreground("#FF0000") .border_right_foreground("#00FF00") .border_bottom_foreground("#0000FF") .border_left_foreground("#FFFF00") .render("Rainbow border") ``` ```ruby puts Lipgloss::Style.new .border_custom( top: "~", bottom: "~", left: "|", right: "|", top_left: "+", top_right: "+", bottom_left: "+", bottom_right: "+" ) .render("Custom") ``` ```ruby puts Lipgloss::Style.new .border_custom(top: "-", bottom: "-") .render("Partial") ``` -------------------------------- ### Render an organization chart with nested trees Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Demonstrates how to create a complex organization chart by nesting tree structures and adding other elements. ```ruby engineering = Lipgloss::Tree.root("Engineering").child("Backend", "Frontend", "DevOps") sales = Lipgloss::Tree.root("Sales").child("North America", "Europe", "APAC") puts Lipgloss::Tree.root("Acme Corp") .child(engineering, sales, "HR", "Finance") .enumerator(:rounded) .render ``` -------------------------------- ### Render a styled tree Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Illustrates how to apply custom styles to the root, items, and enumerators of a tree. ```ruby root_style = Lipgloss::Style.new.bold(true).foreground("#FFD700") item_style = Lipgloss::Style.new.foreground("#98FB98") enum_style = Lipgloss::Style.new.foreground("#87CEEB") puts Lipgloss::Tree.root("Styled Root") .child("Item 1", "Item 2", "Item 3") .root_style(root_style) .item_style(item_style) .enumerator_style(enum_style) .render ``` -------------------------------- ### Style Inheritance and Unsetting Properties in Lipgloss Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Illustrates how to inherit styles from a parent and how to unset individual style properties to revert to default rendering. ```ruby require "lipgloss" # inherit: child keeps its own foreground, picks up bold from parent parent = Lipgloss::Style.new.foreground("#FF0000").bold(true) child = Lipgloss::Style.new.foreground("#00FF00").inherit(parent) puts child.render("Green and bold") # foreground stays green; bold is inherited ``` ```ruby style = Lipgloss::Style.new .bold(true) .italic(true) .foreground("#FF0000") .width(50) .padding_top(2) .margin_left(2) .border(:rounded) .unset_bold .unset_italic .unset_foreground .unset_width .unset_padding_top .unset_margin_left .unset_border_style puts style.render("All unset") ``` -------------------------------- ### Module Methods Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Utility methods for joining strings, measuring dimensions, and placing text within the terminal. ```APIDOC ## Module Methods ### String Joining - `Lipgloss.join_horizontal(position, *strings)`: Join strings horizontally. - `Lipgloss.join_vertical(position, *strings)`: Join strings vertically. ### Dimension Measurement - `Lipgloss.width(string)`: Get rendered width. - `Lipgloss.height(string)`: Get rendered height. - `Lipgloss.size(string)`: Get `[width, height]`. ### Text Placement - `Lipgloss.place(width, height, h_pos, v_pos, string)`: Place in whitespace. - `Lipgloss.place_horizontal(width, position, string)`: Place horizontally. - `Lipgloss.place_vertical(height, position, string)`: Place vertically. ### Terminal Information - `Lipgloss.has_dark_background?`: Check terminal background. ``` -------------------------------- ### Render a basic tree with rounded enumerators Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Demonstrates how to render a simple tree structure with rounded corners for the enumerator nodes. ```ruby puts Lipgloss::Tree.root("Root").child("A", "B", "C").enumerator(:rounded).render ``` -------------------------------- ### Set Dimensions with Lipgloss Style Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Illustrates setting fixed or maximum dimensions (width, height, max_width, max_height) for a Lipgloss style. Content is padded or truncated to fit the specified dimensions, useful for constrained layouts. ```ruby require "lipgloss" # Fixed width: pads short text to exactly 20 chars fixed = Lipgloss::Style.new.width(20).align_horizontal(:center) puts fixed.render("Center") # => " Center " # Fixed height: pads to 3 lines, centered vertically tall = Lipgloss::Style.new.height(3).align_vertical(:center) puts tall.render("Middle") # => " " # "Middle" # " " # Constrained width wraps long text clamped = Lipgloss::Style.new.max_width(10) puts clamped.render("This is a long text") # => each line <= 10 chars ``` -------------------------------- ### Define Multi-Profile Color with Fallbacks Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Use `CompleteColor` to specify exact colors for true color, 256-color, and 16-color terminals. Fallbacks can be symbols, integers, or strings. ```ruby require "lipgloss" color = Lipgloss::CompleteColor.new( true_color: "#FF6B6B", # 24-bit ansi256: 196, # 256-color fallback (integer) ansi: :bright_red # 16-color fallback (symbol) ) puts Lipgloss::Style.new.foreground(color).render("Coral red with fallbacks") # Inspect resolved values puts color.true_color # => "#FF6B6B" puts color.ansi256 # => "196" puts color.ansi # => "9" puts color.to_h # => { true_color: "#FF6B6B", ansi256: "196", ansi: "9" } ``` -------------------------------- ### Apply Simple Hex Colors Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Set foreground and background colors using hexadecimal color codes. ```ruby style = Lipgloss::Style.new .foreground("#FF0000") .background("#0000FF") ``` -------------------------------- ### Text Alignment with Lipgloss Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Demonstrates horizontal text alignment using width and alignment methods. Supports named constants, raw floats for percentages, and different alignment options. ```ruby puts Lipgloss::Style.new.width(20).align_horizontal(:right).render("Hi") ``` ```ruby puts Lipgloss::Style.new.height(3).align_vertical(:center).render("Mid") ``` ```ruby puts Lipgloss::Style.new.width(20).align_horizontal(Lipgloss::CENTER).render("Const") ``` ```ruby puts Lipgloss::Style.new.width(20).align_horizontal(0.25).render("25%") ``` -------------------------------- ### Run Tests with Rake Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Executes the project's test suite using the Rake build tool. ```bash bundle exec rake test ``` -------------------------------- ### Use Adaptive Colors Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Define foreground colors that automatically adapt to light or dark terminal themes. ```ruby style = Lipgloss::Style.new .foreground(Lipgloss::AdaptiveColor.new(light: "#000", dark: "#FFF")) ``` -------------------------------- ### Create Styled Terminal Tables with Lipgloss::Table Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Generate terminal tables with customizable borders, per-cell styling, and fixed widths. All methods return new `Table` instances, ensuring immutability. ```ruby require "lipgloss" # Basic table table = Lipgloss::Table.new .headers(["Language", "Formal", "Informal"]) .rows([ ["Chinese", "您好", "你好"], ["Japanese", "こんにちは", "やあ"], ["Korean", "안녕하세요", "안녕"], ["Spanish", "Buenos días", "Hola"] ]) .border(:rounded) puts table.render ``` ```ruby # Markdown table (for documentation) md = Lipgloss::Table.new .headers(["Feature", "Status"]) .rows([["Tables", "Done"], ["Lists", "Done"]]) .border(:markdown) .border_top(false) .border_bottom(false) puts md.render # => |Feature|Status| # |-------|------| # |Tables |Done | # |Lists |Done | ``` ```ruby # StyleFunc: per-cell styling via block header_style = Lipgloss::Style.new.bold(true).foreground("#FFFFFF").background("#5A56E0") even_style = Lipgloss::Style.new.foreground("#FAFAFA").background("#3C3C3C") odd_style = Lipgloss::Style.new.foreground("#FAFAFA").background("#4A4A4A") name_style = Lipgloss::Style.new.bold(true).foreground("#FF6B6B") value_style = Lipgloss::Style.new.foreground("#4ECDC4") styled = Lipgloss::Table.new .headers(["Setting", "Value"]) .rows([ ["Debug Mode", "enabled"], ["Log Level", "info"], ["Max Connections", "100"] ]) .border(:rounded) .style_func(rows: 3, columns: 2) do |row, col| if row == Lipgloss::Table::HEADER_ROW header_style elsif col.zero? name_style else value_style end end puts styled.render ``` ```ruby # Clear rows and re-add clean = styled.clear_rows ``` -------------------------------- ### Align Content with Lipgloss Style Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Shows how to align content horizontally or vertically within a style's bounding box using symbolic positions or floats. Demonstrates horizontal centering within a fixed-width box. ```ruby require "lipgloss" # Horizontal center in a 20-char wide box puts Lipgloss::Style.new.width(20).align_horizontal(:center).render("Hi") # => " Hi " ``` -------------------------------- ### Text formatting methods Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Apply common text decorations like bold, italic, underline, strikethrough, faint, blink, and reverse. Each method accepts a boolean and returns a new `Style` object. These can be freely combined. ```APIDOC ## Text formatting methods — `bold`, `italic`, `underline`, `strikethrough`, `faint`, `blink`, `reverse` ### Description Each text-decoration method accepts a boolean and returns a new `Style`. They can be freely combined. ### Request Example ```ruby require "lipgloss" # All text decorations puts Lipgloss::Style.new.bold(true).render("Bold") puts Lipgloss::Style.new.italic(true).render("Italic") puts Lipgloss::Style.new.underline(true).render("Underline") puts Lipgloss::Style.new.strikethrough(true).render("Strikethrough") puts Lipgloss::Style.new.faint(true).render("Faint") puts Lipgloss::Style.new.blink(true).render("Blink") puts Lipgloss::Style.new.reverse(true).render("Reversed fg/bg") # Combined puts Lipgloss::Style.new .bold(true) .underline(true) .foreground("#FFD700") .render("Gold bold underline") ``` ``` -------------------------------- ### Other Styling Methods Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Methods for controlling inline rendering, tab width, default text, and style inheritance. ```APIDOC ## Other Styling Methods ### `inline(bool)` Render inline (no margins/padding/borders). ### `tab_width(int)` Set tab character width (-1 to disable). ### `set_string(text)` Set default text. ### `inherit(style)` Inherit from another style. ### `to_s` Render with default text. ``` -------------------------------- ### Lipgloss::Style.new - Create a style Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt The central API for creating immutable style objects. Chain methods to accumulate formatting rules. Use `.render(text)` to apply rules to a string or `.to_s` to render a previously set string. ```APIDOC ## Lipgloss::Style.new - Create a style ### Description The central API of the gem. `Style` is an immutable object that accumulates formatting rules through chainable method calls. Calling `.render(text)` applies all accumulated rules to the given string and returns an ANSI-escaped string. Calling `.to_s` renders the string previously set with `.set_string`. ### Request Example ```ruby require "lipgloss" # Bold purple text on a colored background with padding style = Lipgloss::Style.new .bold(true) .foreground("#FAFAFA") .background("#7D56F4") .padding(1, 2) puts style.render("Hello, Lipgloss!") # => (1 blank line) # Hello, Lipgloss! (styled, with 2-char horizontal padding) # (1 blank line) # Immutability: style is unchanged; heading is a new object heading = style.italic(true).foreground("#FF6B6B") puts heading.render("Still safe to use style above") ``` ``` -------------------------------- ### Define and Use Reusable Styles Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Create multiple Lipgloss::Style objects for different purposes (e.g., headings, body text) and reuse them to render content. ```ruby heading = Lipgloss::Style.new .bold(true) .foreground("#FF6B6B") .margin_bottom(1) body = Lipgloss::Style.new .width(40) .align(:center) puts heading.render("Welcome") puts body.render("Styled terminal output") ``` -------------------------------- ### Create Styled Terminal Lists with Lipgloss::List Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Generate styled terminal lists with various enumerator styles, optional per-item and enumerator styling, and support for nesting sublists. Items can be added incrementally or at construction time. ```ruby require "lipgloss" # Construct with initial items puts Lipgloss::List.new("Apple", "Banana", "Cherry").render # => "• Apple\n• Banana\n• Cherry" ``` ```ruby # All enumerator types puts Lipgloss::List.new("A", "B", "C").enumerator(:bullet).render # • A puts Lipgloss::List.new("A", "B", "C").enumerator(:dash).render # - A puts Lipgloss::List.new("A", "B", "C").enumerator(:asterisk).render # * A puts Lipgloss::List.new("A", "B", "C").enumerator(:arabic).render # 1. A puts Lipgloss::List.new("A", "B", "C").enumerator(:alphabet).render # A. A puts Lipgloss::List.new("A", "B", "C").enumerator(:roman).render # I. A ``` ```ruby # Incremental build todo = Lipgloss::List.new .item("Write code") .item("Test code") .item("Deploy code") .item("Monitor") .enumerator(:bullet) puts todo.render ``` ```ruby # Nested list fruits = Lipgloss::List.new("Apple", "Banana", "Orange").enumerator(:bullet) vegetables = Lipgloss::List.new("Carrot", "Broccoli").enumerator(:bullet) groceries = Lipgloss::List.new .item("Fruits").item(fruits) .item("Vegetables").item(vegetables) .enumerator(:arabic) puts groceries.render # => "1. Fruits\n • Apple\n • Banana\n • Orange\n2. Vegetables\n • Carrot\n • Broccoli" ``` ```ruby # Styled enumerator and items enum_style = Lipgloss::Style.new.foreground("#FF6B6B").bold(true) item_style = Lipgloss::Style.new.foreground("#4ECDC4") puts Lipgloss::List.new("Ruby", "Python", "Go") .enumerator(:arabic) .enumerator_style(enum_style) .item_style(item_style) .render ``` -------------------------------- ### Define Complete Adaptive Colors Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Create adaptive colors that use different complete color definitions for light and dark terminal themes. ```ruby light = Lipgloss::CompleteColor.new(true_color: "#000", ansi256: :black, ansi: :black) dark = Lipgloss::CompleteColor.new(true_color: "#FFF", ansi256: :bright_white, ansi: :bright_white) color = Lipgloss::CompleteAdaptiveColor.new(light: light, dark: dark) style = Lipgloss::Style.new.foreground(color) ``` -------------------------------- ### Lipgloss::List Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Creates styled lists for terminal output with various enumerator styles and options for per-item and enumerator styling. ```APIDOC ## `Lipgloss::List` — enumerated terminal lists Creates styled terminal lists with various enumerator styles, optional per-item and enumerator styling, and support for nesting sublists. Items can be passed at construction time or added incrementally. ### Constructing with Initial Items ```ruby puts Lipgloss::List.new("Apple", "Banana", "Cherry").render # => "• Apple\n• Banana\n• Cherry" ``` ### Enumerator Types ```ruby # All enumerator types puts Lipgloss::List.new("A", "B", "C").enumerator(:bullet).render # • A puts Lipgloss::List.new("A", "B", "C").enumerator(:dash).render # - A puts Lipgloss::List.new("A", "B", "C").enumerator(:asterisk).render # * A puts Lipgloss::List.new("A", "B", "C").enumerator(:arabic).render # 1. A puts Lipgloss::List.new("A", "B", "C").enumerator(:alphabet).render # A. A puts Lipgloss::List.new("A", "B", "C").enumerator(:roman).render # I. A ``` ### Incremental Build ```ruby todo = Lipgloss::List.new .item("Write code") .item("Test code") .item("Deploy code") .item("Monitor") .enumerator(:bullet) puts todo.render ``` ### Nested List ```ruby fruits = Lipgloss::List.new("Apple", "Banana", "Orange").enumerator(:bullet) vegetables = Lipgloss::List.new("Carrot", "Broccoli").enumerator(:bullet) groceries = Lipgloss::List.new .item("Fruits").item(fruits) .item("Vegetables").item(vegetables) .enumerator(:arabic) puts groceries.render # => "1. Fruits\n • Apple\n • Banana\n • Orange\n2. Vegetables\n • Carrot\n • Broccoli" ``` ### Styled Enumerator and Items ```ruby enum_style = Lipgloss::Style.new.foreground("#FF6B6B").bold(true) item_style = Lipgloss::Style.new.foreground("#4ECDC4") puts Lipgloss::List.new("Ruby", "Python", "Go") .enumerator(:arabic) .enumerator_style(enum_style) .item_style(item_style) .render ``` ``` -------------------------------- ### Create Styled Tables in Ruby Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Use Lipgloss::Table to create tables with headers, rows, and borders. The :rounded border style is applied here. ```ruby table = Lipgloss::Table.new .headers(["Language", "Greeting"]) .rows([ ["English", "Hello"], ["Spanish", "Hola"], ["Japanese", "こんにちは"] ]) .border(:rounded) puts table.render ``` -------------------------------- ### Define Complete Colors with Fallbacks Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Create a color object that specifies true color, a 256-color fallback, and a 16-color fallback using symbols. ```ruby color = Lipgloss::CompleteColor.new( true_color: "#FF6B6B", # 24-bit color ansi256: 196, # 256-color fallback (integer) ansi: :bright_red # 16-color fallback (symbol) ) style = Lipgloss::Style.new.foreground(color) ``` -------------------------------- ### Set Default Text for a Style Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Assign a default string to a style object, which can then be rendered using `to_s`. ```ruby style = Lipgloss::Style.new .bold(true) .foreground("#7D56F4") .set_string("Hello!") puts style.to_s # Renders "Hello!" with the style ``` -------------------------------- ### Adaptive Colors for Light/Dark Terminals Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Utilizes `Lipgloss::AdaptiveColor` to automatically select foreground or background colors based on the terminal's light or dark theme. Raw color values can be accessed. ```ruby require "lipgloss" subtle = Lipgloss::AdaptiveColor.new(light: "#D9DCCF", dark: "#383838") highlight = Lipgloss::AdaptiveColor.new(light: "#874BFD", dark: "#7D56F4") style = Lipgloss::Style.new.foreground(highlight).background(subtle) puts style.render("Adapts to your terminal theme") # Access the raw values puts subtle.light # => "#D9DCCF" puts subtle.dark # => "#383838" puts subtle.to_h # => { light: "#D9DCCF", dark: "#383838" } ``` -------------------------------- ### Spacing — `padding`, `margin` and per-side variants Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Apply CSS-style shorthand or individual-side spacing for padding (internal spacing) and margin (external spacing). Shorthands follow CSS conventions. ```APIDOC ## Spacing — `padding`, `margin` and per-side variants ### Description CSS-style shorthand and individual-side spacing. Shorthand follows CSS convention: 1 arg sets all sides, 2 args set top/bottom and left/right, 4 args set top/right/bottom/left individually. ### Request Example ```ruby require "lipgloss" # 4-arg shorthand: top=1, right=2, bottom=1, left=2 style = Lipgloss::Style.new.padding(1, 2) puts style.render("Padded") # => " " # " Padded " # " " # Per-side padding style2 = Lipgloss::Style.new .padding_top(1) .padding_right(2) .padding_bottom(1) .padding_left(2) puts style2.render("Same result") # Margin (external spacing) margined = Lipgloss::Style.new.margin(1, 2) puts margined.render("Margin") # => " " # " Margin " # " " # Individual margin sides Lipgloss::Style.new.margin_top(1).margin_left(4).render("Nudged right") ``` ``` -------------------------------- ### Blend Colors and Generate Gradients Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Use `ColorBlend` to create perceptually uniform color blends and gradients. Supports `:luv`, `:rgb`, and `:hcl` blend modes. Specify the number of steps for gradients. ```ruby require "lipgloss" # Blend two colors at 50% mid = Lipgloss::ColorBlend.blend("#FF0000", "#0000FF", 0.5) puts mid # => "#7a00c1" (LUV blend) mid_rgb = Lipgloss::ColorBlend.blend("#FF0000", "#0000FF", 0.5, mode: :rgb) puts mid_rgb # different result # Generate a 5-step gradient array colors = Lipgloss::ColorBlend.blends("#FF0000", "#0000FF", 5) puts colors.inspect # => ["#ff0000", "#c1007f", "#7a00c1", "#0000ff", ...] colors.each { |c| print Lipgloss::Style.new.background(c).render(" ") } puts # Generate a 2D color grid (x_steps columns × y_steps rows) grid = Lipgloss::ColorBlend.grid("#F25D94", "#EDFF82", "#643AFF", "#14F9D5", 14, 8) # grid is Array[Array[String]] — each element is a hex color string grid.each do |row| puts row.map { |c| Lipgloss::Style.new.set_string(" ").background(c).to_s }.join end ``` -------------------------------- ### Add children to a tree from an array Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Shows how to add multiple child nodes to a tree by passing an array of names. ```ruby puts Lipgloss::Tree.root("Languages").children(["Ruby", "Python", "Go"]) .render ``` -------------------------------- ### Inherit Styles from a Parent Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Create a child style that inherits properties (like foreground color and bold) from a base style, while adding its own properties like padding. ```ruby base = Lipgloss::Style.new .foreground("#FF0000") .bold(true) child = Lipgloss::Style.new .padding(1) .inherit(base) # Inherits foreground and bold puts child.render("Inherited style!") ``` -------------------------------- ### Place Content in Whitespace Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Position a styled string within a specified width and height, using alignment options. ```ruby puts Lipgloss.place(40, 10, :center, :center, "Centered") ``` -------------------------------- ### Render Hierarchical Trees with Lipgloss::Tree Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Display hierarchical data in a tree structure similar to the `tree` Unix command. Supports custom enumerators, root/item/enumerator styles, and both class and instance constructors. ```ruby require "lipgloss" # Basic tree puts Lipgloss::Tree.root("Project") .child("README.md", "Gemfile", "Rakefile") .render # => "Project\n├── README.md\n├── Gemfile\n└── Rakefile" ``` ```ruby # Deeply nested structure lib = Lipgloss::Tree.root("lib").child("lipgloss.rb").child( Lipgloss::Tree.root("lipgloss").child("version.rb", "style.rb", "border.rb")) test = Lipgloss::Tree.root("test").child("test_helper.rb", "style_test.rb") puts Lipgloss::Tree.root("lipgloss-ruby") .child(lib, test, "README.md", "Gemfile") .render ``` -------------------------------- ### Dimensions — `width`, `height`, `max_width`, `max_height` Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Set fixed or maximum dimensions for a style. Content is padded or truncated to fit. Useful for creating fixed-width columns or constrained text blocks. ```APIDOC ## Dimensions — `width`, `height`, `max_width`, `max_height` ### Description Set fixed or maximum dimensions on a style. Content is padded or truncated to fit. Useful for creating fixed-width columns or constrained text blocks. ### Request Example ```ruby require "lipgloss" # Fixed width: pads short text to exactly 20 chars fixed = Lipgloss::Style.new.width(20).align_horizontal(:center) puts fixed.render("Center") # => " Center " # Fixed height: pads to 3 lines, centered vertically tall = Lipgloss::Style.new.height(3).align_vertical(:center) puts tall.render("Middle") # => " " # "Middle" # " " # Constrained width wraps long text clamped = Lipgloss::Style.new.max_width(10) puts clamped.render("This is a long text") # => each line <= 10 chars ``` ``` -------------------------------- ### Define Adaptive Color with Full Fallbacks Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Combine `CompleteColor` with adaptive light/dark selection for the most robust color specification. This class handles both terminal capability fallbacks and light/dark mode adaptation. ```ruby require "lipgloss" light_color = Lipgloss::CompleteColor.new( true_color: "#1A1A2E", ansi256: 234, ansi: :black ) dark_color = Lipgloss::CompleteColor.new( true_color: "#EAEAEA", ansi256: 255, ansi: :bright_white ) color = Lipgloss::CompleteAdaptiveColor.new(light: light_color, dark: dark_color) puts Lipgloss::Style.new.foreground(color).render("Adapts + has fallbacks") puts color.to_h # => { # light: { true_color: "#1A1A2E", ansi256: "234", ansi: "0" }, # dark: { true_color: "#EAEAEA", ansi256: "255", ansi: "15" } # } ``` -------------------------------- ### Lipgloss::CompleteAdaptiveColor Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Combines `CompleteColor` with adaptive light/dark selection for the most robust color specification. It provides different color fallbacks for light and dark terminal themes. ```APIDOC ## `Lipgloss::CompleteAdaptiveColor` — full fallback + adaptive Combines `CompleteColor` with adaptive light/dark selection — the most robust color specification available. ### Constructor ```ruby Lipgloss::CompleteAdaptiveColor.new( light: light_color_object, # A Lipgloss::CompleteColor object for light themes dark: dark_color_object # A Lipgloss::CompleteColor object for dark themes ) ``` ### Example Usage ```ruby light_color = Lipgloss::CompleteColor.new(true_color: "#1A1A2E", ansi256: 234, ansi: :black) dark_color = Lipgloss::CompleteColor.new(true_color: "#EAEAEA", ansi256: 255, ansi: :bright_white) color = Lipgloss::CompleteAdaptiveColor.new(light: light_color, dark: dark_color) puts Lipgloss::Style.new.foreground(color).render("Adapts + has fallbacks") ``` ### Instance Methods - **`to_h`**: Returns a hash representation of the adaptive color object, including light and dark color details. ``` -------------------------------- ### Measure Rendered String Dimensions Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Use `Lipgloss.width`, `height`, and `size` to accurately determine the visible terminal width and height of rendered strings, accounting for ANSI escape codes and multi-byte characters. ```ruby require "lipgloss" text = "Hello\nWorld" puts Lipgloss.width(text) # => 5 puts Lipgloss.height(text) # => 2 width, height = Lipgloss.size(text) puts "#{width}x#{height}" # => "5x2" # Measure a rendered box to calculate remaining space box = Lipgloss::Style.new.border(:rounded).padding(0, 1).render("Content") puts Lipgloss.width(box) # accounts for borders and padding ``` -------------------------------- ### Create Custom Borders Source: https://github.com/marcoroth/lipgloss-ruby/blob/main/README.md Define a custom border using specific characters for each side and corner. ```ruby style = Lipgloss::Style.new .border_custom( top: "~", bottom: "~", left: "|", right: "|", top_left: "+", top_right: "+", bottom_left: "+", bottom_right: "+" ) puts style.render("Custom border!") ``` -------------------------------- ### Lipgloss::Table Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Generates styled tables for terminal output with support for headers, rows, borders, and per-cell styling. ```APIDOC ## `Lipgloss::Table` — styled tabular data Creates terminal tables with configurable borders, per-cell style functions, fixed widths, and row/column border visibility controls. All methods return new `Table` instances (immutable). ### Basic Table ```ruby require "lipgloss" table = Lipgloss::Table.new .headers(["Language", "Formal", "Informal"]) .rows([ ["Chinese", "您好", "你好"], ["Japanese", "こんにちは", "やあ"], ["Korean", "안녕하세요", "안녕"], ["Spanish", "Buenos días", "Hola"] ]) .border(:rounded) puts table.render ``` ### Markdown Table ```ruby md = Lipgloss::Table.new .headers(["Feature", "Status"]) .rows([["Tables", "Done"], ["Lists", "Done"]]) .border(:markdown) .border_top(false) .border_bottom(false) puts md.render # => |Feature|Status| # |-------|------| # |Tables |Done | # |Lists |Done | ``` ### Styling with `style_func` ```ruby header_style = Lipgloss::Style.new.bold(true).foreground("#FFFFFF").background("#5A56E0") even_style = Lipgloss::Style.new.foreground("#FAFAFA").background("#3C3C3C") odd_style = Lipgloss::Style.new.foreground("#FAFAFA").background("#4A4A4A") name_style = Lipgloss::Style.new.bold(true).foreground("#FF6B6B") value_style = Lipgloss::Style.new.foreground("#4ECDC4") styled = Lipgloss::Table.new .headers(["Setting", "Value"]) .rows([ ["Debug Mode", "enabled"], ["Log Level", "info"], ["Max Connections", "100"] ]) .border(:rounded) .style_func(rows: 3, columns: 2) do |row, col| if row == Lipgloss::Table::HEADER_ROW header_style elsif col.zero? name_style else value_style end end puts styled.render ``` ### Clearing Rows ```ruby clean = styled.clear_rows ``` ``` -------------------------------- ### Inline Rendering and Tab Width Control Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Configures Lipgloss for single-line output using `inline(true)` and controls tab character expansion with `tab_width(n)`. A value of -1 disables tab conversion. ```ruby require "lipgloss" # Inline mode: no newlines even with padding or borders puts Lipgloss::Style.new.inline(true).padding(2).render("Inline") ``` ```ruby puts Lipgloss::Style.new.tab_width(4).render("col1\ttab2") ``` ```ruby puts Lipgloss::Style.new.tab_width(-1).render("col1\ttab2") ``` -------------------------------- ### Lipgloss::Tree Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Renders hierarchical tree structures in the terminal, similar to the `tree` Unix command. ```APIDOC ## `Lipgloss::Tree` — hierarchical tree display Renders a tree structure in the style of the `tree` Unix command. Nodes can be strings or nested `Tree` instances. Supports custom enumerators, root/item/enumerator styles, and both `.root` (class method alias) and `.new` constructors. ### Basic Tree ```ruby puts Lipgloss::Tree.root("Project") .child("README.md", "Gemfile", "Rakefile") .render # => "Project\n├── README.md\n├── Gemfile\n└── Rakefile" ``` ### Deeply Nested Structure ```ruby lib = Lipgloss::Tree.root("lib").child("lipgloss.rb").child( Lipgloss::Tree.root("lipgloss").child("version.rb", "style.rb", "border.rb")) test = Lipgloss::Tree.root("test").child("test_helper.rb", "style_test.rb") puts Lipgloss::Tree.root("lipgloss-ruby") .child(lib, test, "README.md", "Gemfile") .render ``` ``` -------------------------------- ### Lipgloss.join_horizontal / Lipgloss.join_vertical Source: https://context7.com/marcoroth/lipgloss-ruby/llms.txt Composes multiple rendered strings side-by-side (horizontal) or stacked (vertical). Allows alignment of shorter strings against taller/wider ones using a position argument. ```APIDOC ## `Lipgloss.join_horizontal` / `Lipgloss.join_vertical` — compose rendered strings Joins multiple rendered strings side-by-side (horizontal) or stacked (vertical). The position argument controls how shorter blocks are aligned against taller/wider ones. ### Usage - **`Lipgloss.join_horizontal(position, *strings)`**: Joins strings horizontally. `position` can be `:top`, `:center`, or `:bottom`. ```ruby left = box.render("Left\nContent") center = box.render("Center") right = box.render("Right\nContent\nHere") puts Lipgloss.join_horizontal(:top, left, center, right) puts Lipgloss.join_horizontal(:center, left, center, right) ``` - **`Lipgloss.join_vertical(position, *strings)`**: Joins strings vertically. `position` can be `:left`, `:center`, or `:right`. ```ruby puts Lipgloss.join_vertical(:left, left, right) ``` - **Splat operator**: Can accept an array of strings using the splat operator (`*`). ```ruby cols = [left, center, right] puts Lipgloss.join_horizontal(:top, *cols) ``` ```