Overview
Bubble Tea supports terminal styling through ANSI codes and integrates seamlessly with Lip Gloss, Charm’s styling library for terminal applications. The framework automatically handles color profile detection and downsampling.Lip Gloss Integration
The recommended way to style Bubble Tea applications is with Lip Gloss:examples/spinner/main.go:12-28
Basic Styling
Color Profiles
Bubble Tea automatically detects the terminal’s color capabilities:- TrueColor (24-bit) - 16 million colors
- ANSI256 - 256 colors
- ANSI - 16 colors
- Ascii - No colors
Automatic Detection
Color profiles are detected from environment variables and terminal capabilities:Manual Color Profile
Override the detected color profile:examples/colorprofile/main.go:46-52
Color Profile Messages
React to color profile changes:examples/colorprofile/main.go:28-35
ANSI Styling
For direct ANSI control, use theansi package:
examples/colorprofile/main.go:39-44
ANSI Color Codes
Dynamic Background Colors
Query the terminal’s background color to adapt your styles:color.go:48-77
Foreground and Cursor Colors
Query other terminal colors:color.go:17-31
Lip Gloss Layouts
Lip Gloss provides powerful layout primitives:Horizontal Layout
Vertical Layout
Borders and Padding
Text Formatting
Basic Formatting
Alignment
Adaptive Colors
Lip Gloss supports adaptive colors that change based on background:Color Rendering
Bubble Tea usescolorprofile.Writer to automatically downsample colors:
options.go:148-157
Best Practices
Use Lip Gloss for Consistency
Use Lip Gloss for Consistency
Lip Gloss provides a declarative API that’s easier to maintain than raw ANSI codes:
Define Styles Once
Define Styles Once
Create style variables at package level:
Use Adaptive Colors
Use Adaptive Colors
Support both light and dark terminals:
Let Bubble Tea Handle Color Profiles
Let Bubble Tea Handle Color Profiles
Don’t force TrueColor unless necessary:
Common Patterns
Status Bar
Table Layout
Progress Indicators
Related
- Lip Gloss Documentation
- Bubbles Components - Pre-styled UI components
- Input Handling - Add interactivity to styled elements
- Testing - Test with specific color profiles