Charm Bracelet
Rendering

Rendering

Render static or dynamic content in Lip Gloss for stylish terminal output.

Render Your Content

Lip Gloss makes rendering content in your terminal apps simple, supporting both static and dynamic text. Whether you’re styling a CLI or a Bubble Tea TUI, you can render styled text with ease using the Render method or custom renderers for specific outputs.

Combine rendering with colors and formatting for vibrant terminal interfaces.

Rendering Options

Lip Gloss provides flexible ways to render content:

Use the Render method or Stringer interface to style and display text:

style := lipgloss.NewStyle().Bold(true).SetString("Hello,")
fmt.Println(style.Render("kitty.")) // Hello, kitty.
fmt.Println(style.Render("puppy.")) // Hello, puppy.

// Using Stringer interface
var style = lipgloss.NewStyle().SetString("你好,猫咪。").Bold(true)
fmt.Println(style) // 你好,猫咪。

Create renderers for specific outputs, like SSH sessions, to detect color profiles:

func myLittleHandler(sess ssh.Session) {
    // Create a renderer for the client.
    renderer := lipgloss.NewRenderer(sess)

    // Create a new style on the renderer.
    style := renderer.NewStyle().Background(lipgloss.AdaptiveColor{Light: "63", Dark: "228"})

    // Render. The color profile and dark background state will be correctly detected.
    io.WriteString(sess, style.Render("Heyyyyyyy"))
}

For an example using a custom renderer over SSH with Wish, see the SSH example.

How It Works

Render styled content in your terminal apps:

Define a Style

Create a style with properties like bold or colors using lipgloss.NewStyle().

Render Content

Use Render to style dynamic text or print the style directly via the Stringer interface:

style := lipgloss.NewStyle().Bold(true)
fmt.Println(style.Render("Hello, world!"))

Use Custom Renderers

For specific outputs (e.g., SSH), create a renderer with lipgloss.NewRenderer to ensure proper color detection.

Custom renderers are essential for server-client scenarios to correctly detect terminal color profiles and background settings.

How is this guide?