gitmyhub

lipgloss

Go ★ 11k updated 17h ago

Style definitions for nice terminal layouts 👄

Lip Gloss is a Go library for adding colors, borders, padding, and column layouts to command-line tool output using a CSS-inspired API that automatically adapts to the user's terminal color capabilities.

Gosetup: easycomplexity 2/5

Lip Gloss is a Go library for styling text in terminal applications. If you have ever seen a command-line tool with colored output, neatly aligned columns, bordered boxes, or other visual formatting, that kind of output is built using libraries like this one. Lip Gloss handles all of the low-level terminal codes needed to produce those effects and exposes them through a simple, readable Go API.

The design takes inspiration from CSS, the language used to style web pages. You create a style object, chain properties onto it like bold, foreground color, padding, and width, and then apply it to a string of text. Developers familiar with web styling will find the approach recognizable. Styles can inherit from other styles, and properties cascade in a way similar to how CSS inheritance works.

Color support is handled gracefully across different terminal environments. You can specify colors as hex codes, standard ANSI color numbers, or 256-color values. If the user's terminal does not support the full color range you specified, Lip Gloss automatically downgrades to the best available option rather than producing broken output.

Beyond text color and decoration, the library supports block-level layout features: padding, margins, minimum widths and heights, text alignment, and a variety of border styles including rounded, thick, double, and custom. It also provides utilities for working with colors mathematically, such as darkening, lightening, or finding complementary colors.

Lip Gloss is part of the Charm toolchain, a collection of Go libraries aimed at making terminal user interfaces easier to build. It works alongside Bubble Tea, which is Charm's framework for building interactive terminal applications.

Where it fits