Skip to main content

Crate lipgloss

Crate lipgloss 

Source
Expand description

§Lipgloss

A powerful terminal styling library for creating beautiful CLI applications.

Lipgloss provides a declarative, CSS-like approach to terminal styling with support for:

  • Colors: ANSI, 256-color, true color, and adaptive colors
  • Text formatting: Bold, italic, underline, strikethrough, and more
  • Layout: Padding, margins, borders, and alignment
  • Word wrapping and text truncation

§Role in charmed_rust

Lipgloss is the styling foundation for the entire stack:

  • bubbletea renders views using lipgloss styles.
  • bubbles components expose styling hooks via lipgloss.
  • glamour uses lipgloss for Markdown theming.
  • charmed_log formats log output with lipgloss styles.
  • demo_showcase centralizes themes and visual identity with lipgloss.

§Quick Start

use lipgloss::{Style, Border, Position};

// Create a styled box
let style = Style::new()
    .bold()
    .foreground("#ff00ff")
    .background("#1a1a1a")
    .padding((1, 2))
    .border(Border::rounded())
    .align(Position::Center);

println!("{}", style.render("Hello, Lipgloss!"));

§Style Builder

Styles are built using a fluent API where each method returns a new style:

use lipgloss::Style;

let base = Style::new().bold();
let red = base.clone().foreground("#ff0000");
let blue = base.clone().foreground("#0000ff");

§Colors

Multiple color formats are supported:

use lipgloss::{Style, AdaptiveColor, Color};

// Hex colors
let style = Style::new().foreground("#ff00ff");

// ANSI 256 colors
let style = Style::new().foreground("196");

// Adaptive colors (light/dark themes)
let adaptive = AdaptiveColor {
    light: Color::from("#000000"),
    dark: Color::from("#ffffff"),
};
let style = Style::new().foreground_color(adaptive);

§Borders

Several preset borders are available:

use lipgloss::{Style, Border};

let style = Style::new()
    .border(Border::rounded())
    .padding(1);

// Available borders:
// Border::normal()    ┌───┐
// Border::rounded()   ╭───╮
// Border::thick()     ┏━━━┓
// Border::double()    ╔═══╗
// Border::hidden()    (spaces)
// Border::ascii()     +---+

§Layout

CSS-like padding and margin with shorthand notation:

use lipgloss::Style;

// All sides
let style = Style::new().padding(2);

// Vertical, horizontal
let style = Style::new().padding((1, 2));

// Top, horizontal, bottom
let style = Style::new().padding((1, 2, 3));

// Top, right, bottom, left (clockwise)
let style = Style::new().padding((1, 2, 3, 4));

Re-exports§

pub use backend::AnsiBackend;
pub use backend::DefaultBackend;
pub use backend::HtmlBackend;
pub use backend::OutputBackend;
pub use backend::PlainBackend;
pub use backend::default_backend;
pub use border::Border;
pub use border::BorderEdges;
pub use color::AdaptiveColor;
pub use color::AnsiColor;
pub use color::Color;
pub use color::ColorProfile;
pub use color::CompleteAdaptiveColor;
pub use color::CompleteColor;
pub use color::NoColor;
pub use color::RgbColor;
pub use color::TerminalColor;
pub use position::Position;
pub use position::Sides;
pub use renderer::Renderer;
pub use renderer::color_profile;
pub use renderer::default_renderer;
pub use renderer::has_dark_background;
pub use style::Style;
pub use style::truncate_line_ansi;
pub use theme::CachedThemedStyle;
pub use theme::CatppuccinFlavor;
pub use theme::ColorSlot;
pub use theme::ColorTransform;
pub use theme::ListenerId;
pub use theme::Theme;
pub use theme::ThemeChangeListener;
pub use theme::ThemeColors;
pub use theme::ThemeContext;
pub use theme::ThemePreset;
pub use theme::ThemeRole;
pub use theme::ThemedColor;
pub use theme::ThemedStyle;
pub use theme::global_theme;
pub use theme::set_global_preset;
pub use theme::set_global_theme;

Modules§

backend
Output backend abstraction for rendering styles to different targets.
border
Border styles for terminal boxes.
color
Terminal color types and color profile handling.
position
Position and alignment types.
prelude
Prelude module for convenient imports.
renderer
Terminal renderer with color profile detection.
style
Style definition and builder.
theme
Theme system with semantic color slots.

Structs§

Range
Range specifies a section of text with a start index, end index, and the Style to apply.

Functions§

height
Get the number of lines in a string.
join_horizontal
Horizontally joins multi-line strings along a vertical axis.
join_vertical
Vertically joins multi-line strings along a horizontal axis.
new_range
Creates a new Range that can be used with style_ranges.
new_style
Create a new empty style.
place
Place a string at a position within a given width and height.
style_ranges
Applies styles to ranges in a string. Existing ANSI styles will be taken into account. Ranges should not overlap.
style_runes
Applies styles to runes at the given indices in the string.
visible_width
Calculate the visible width of a string, excluding ANSI escape sequences.
width
Get the width of the widest line in a string.