$ show charmbracelet/fang
Fang is a Go library that provides a batteries-included CLI starter kit built on top of the Cobra command-line framework. It extends Cobra with beautifully styled help output, error handling, and automatic versioning, completions, and manpage generation. The package offers a single high-level `Execute` function that wraps a Cobra root command and applies a rich set of default behaviors: full-color styled help and error pages with adaptive color schemes (including automatic terminal background detection), automatic `--version` derived from build info or explicitly set, hidden `man` and `completion` subcommands, and silent usage output (no help after a user error). It supports Windows VT processing for ANSI escape codes and color downsampling for terminals with limited color support. Architecturally, Fang is a library with a clear separation of concerns. The `fang.go` file defines the public API (`Execute`, `Option` functions, `ColorSchemeFunc`) and orchestrates the setup of the Cobra command. `help.go` contains the custom help and error rendering logic, including a usage error detector. `theme.go` defines the theming system with a `ColorScheme` struct, multiple built-in themes (default, ANSI), and a `Styles` struct that applies these colors to lipgloss styles. Platform-specific code for Windows VT processing is isolated in `fang_windows.go`. The library depends on Cobra, lipgloss v2 for styling, colorprofile for terminal color detection, and mango for manpage generation. It includes an example CLI application in `example/main.go` that showcases all features. Fang is designed for Go developers who want a production-ready, beautiful CLI experience without manually wiring up help formatting, version flags, completions, and error styling. Its theme system is extensible: users can provide their own color scheme functions that adapt to light/dark terminals. The project is actively maintained by Charmbracelet and follows modern Go conventions (e.g., `iter.Seq2` from Go 1.23).
The LLM identified 2 files worth highlighting for reuse:
Defines the color scheme system for CLI help and error output. Includes ColorScheme struct, built-in themes (DefaultColorScheme, AnsiColorScheme), the Styles struct that wraps lipgloss styles, and the titleFirstWord text transformer. This component is self-contained (only depends on lipgloss, charmbracelet/x/exp/charmtone, golang.org/x/text) and could be extracted into a standalone library for any Go CLI application that wants styled help output. It demonstrates non-obvious skill in adaptive color theming with terminal background detection and careful style composition.
Implements enableVirtualTerminalProcessing, a small but essential function that enables ANSI escape code processing on Windows via the Windows Console API (SetConsoleMode with ENABLE_VIRTUAL_TERMINAL_PROCESSING). It is isolated (no internal fang imports), uses only standard library and golang.org/x/sys/windows, and safely handles non-terminal writers. This pattern is reusable in any Go CLI that needs ANSI color support on Windows and demonstrates platform-specific terminal expertise.