Charm Bracelet
Advanced

Utilities

Use Lip Gloss utilities to assemble layouts for your terminal apps.

Assemble Layouts with Utilities

In addition to styling, Lip Gloss provides utilities to help assemble your terminal layouts, making it easy to join paragraphs, measure text dimensions, or place text in whitespace for precise UI design.

Combine utilities with colors and rendering for sophisticated terminal interfaces.

Utility Options

Lip Gloss offers tools to streamline layout assembly:

Horizontally or vertically join paragraphs with alignment control:

// Horizontally join three paragraphs along their bottom edges
lipgloss.JoinHorizontal(lipgloss.Bottom, paragraphA, paragraphB, paragraphC)

// Vertically join two paragraphs along their center axes
lipgloss.JoinVertical(lipgloss.Center, paragraphA, paragraphB)

// Horizontally join three paragraphs, with shorter ones aligning 20% from the top of the tallest
lipgloss.JoinHorizontal(0.2, paragraphA, paragraphB, paragraphC)

Measure the width and height of text blocks:

// Render a block of text
var style = lipgloss.NewStyle().
    Width(40).
    Padding(2)
var block string = style.Render(someLongString)

// Get the actual, physical dimensions of the text block
width := lipgloss.Width(block)
height := lipgloss.Height(block)

// Shorthand function
w, h := lipgloss.Size(block)

Place text within whitespace for precise positioning:

// Center a paragraph horizontally in a space 80 cells wide
block := lipgloss.PlaceHorizontal(80, lipgloss.Center, fancyStyledParagraph)

// Place a paragraph at the bottom of a space 30 cells tall
block := lipgloss.PlaceVertical(30, lipgloss.Bottom, fancyStyledParagraph)

// Place a paragraph in the bottom right corner of a 30x80 cell space
block := lipgloss.Place(30, 80, lipgloss.Right, lipgloss.Bottom, fancyStyledParagraph)

For details on styling whitespace, see the go doc.

How It Works

Use utilities to enhance your terminal layouts:

Join Paragraphs

Use JoinHorizontal or JoinVertical to combine paragraphs with specific alignments:

block := lipgloss.JoinHorizontal(lipgloss.Center, paragraphA, paragraphB)

Measure Dimensions

Use Width, Height, or Size to get text block dimensions for layout planning.

Place Text

Position text in whitespace with PlaceHorizontal, PlaceVertical, or Place for precise control.

Utilities like Place allow styling of whitespace for advanced layouts. Check the docs for more options.

How is this guide?