Skills2026年5月13日·1 分钟阅读

Lipgloss — Style Definitions for Terminal Layouts in Go

A Go library by Charm for defining terminal UI styles with a CSS-like declarative API, including colors, borders, padding, and layout.

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Lipgloss Overview
通用 CLI 安装命令
npx tokrepo install 2f1dcdff-4ee7-11f1-9bc6-00163e2b0d79

Introduction

Lipgloss is a Go library from Charm that brings CSS-like styling to terminal applications. Instead of manually concatenating ANSI escape codes, you define styles declaratively and apply them to strings. It pairs naturally with Bubble Tea and other Charm libraries to build polished terminal user interfaces.

What Lipgloss Does

  • Applies foreground and background colors using ANSI, 256-color, and true-color palettes
  • Adds padding, margin, borders, and alignment to terminal-rendered text blocks
  • Supports adaptive color profiles that degrade gracefully on limited terminals
  • Provides table rendering with configurable column widths and styles
  • Composes styles through inheritance and inline overrides

Architecture Overview

Lipgloss works by building a Style struct that stores rendering properties like color, bold, italic, padding, and border. When Render is called, it measures the text, applies padding and margins, wraps borders around the content, and emits the appropriate ANSI escape sequences. The library detects the terminal color profile at runtime and maps colors to the best available representation.

Self-Hosting & Configuration

  • Add to your Go module with go get and import the package
  • Detect terminal capabilities automatically or set a color profile manually
  • Define reusable styles as package-level variables for consistency across your UI
  • Use lipgloss.JoinHorizontal and JoinVertical to compose multi-block layouts
  • Combine with Bubble Tea for interactive TUI applications with styled components

Key Features

  • Declarative CSS-like API that chains padding, margin, border, and color methods
  • Automatic color profile detection for ANSI, 256-color, and true-color terminals
  • Built-in table component with customizable headers, rows, and borders
  • Responsive width handling with MaxWidth and word wrapping
  • Works on Windows, macOS, and Linux without platform-specific code

Comparison with Similar Tools

  • termenv — lower-level terminal color library from the same Charm team; Lipgloss builds on top of it
  • color (fatih/color) — simple color output for Go, but lacks layout, padding, and border features
  • tcell — full terminal screen manipulation library, more complex than Lipgloss for styling tasks
  • Rich (Python) — similar concept for Python terminals with tables, panels, and markdown rendering

FAQ

Q: Does Lipgloss work on Windows? A: Yes. It supports Windows Terminal, PowerShell, and cmd.exe with automatic color profile detection.

Q: Can I use Lipgloss without Bubble Tea? A: Yes. Lipgloss is a standalone styling library. You can use it in any Go program that prints to the terminal.

Q: How does Lipgloss handle wide characters and emoji? A: It uses the go-runewidth library to correctly measure character widths, including CJK characters and emoji.

Q: Does it support nested styles? A: Yes. You can nest styled strings by rendering inner content first and passing the result to an outer style.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产