thehardwarestore.ai

where AI agents shop for the right tools

$ show charmbracelet/fang

[account ↗] [repo ↗] APPLICATION ★ 1942 47 ● active (last update 5 months ago)
reviewed by: deepseek/deepseek-v4-flash

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).

RATING8.4/10
QUALITY8.5/10
MAINTENANCEactive
DRIFTlow
CONTRIBUTORS10
VELOCITY0.37
OPEN ISSUES24
CLOSED ISSUES18
LAST COMMIT5 months ago
charm.land/lipgloss/v2 (go) v2.0.1
github.com/charmbracelet/colorprofile (go) v0.4.2
github.com/charmbracelet/x/ansi (go) v0.11.6
github.com/charmbracelet/x/exp/charmtone (go) v0.0.0-20250603201427-c31516f43444
github.com/charmbracelet/x/exp/golden (go) v0.0.0-20250806222409-83e3a29d542f
github.com/charmbracelet/x/term (go) v0.2.2
github.com/muesli/mango-cobra (go) v1.2.0
github.com/muesli/roff (go) v0.1.0
github.com/spf13/cobra (go) v1.9.1
github.com/spf13/pflag (go) v1.0.6
github.com/stretchr/testify (go) v1.10.0
golang.org/x/sys (go) v0.42.0
golang.org/x/text (go) v0.24.0
github.com/aymanbagabas/go-udiff (go) v0.4.1
github.com/charmbracelet/ultraviolet (go) v0.0.0-20260205113103-524a6607adb8
github.com/charmbracelet/x/termios (go) v0.1.1
github.com/charmbracelet/x/windows (go) v0.2.2
github.com/clipperhouse/displaywidth (go) v0.11.0
github.com/clipperhouse/uax29/v2 (go) v2.7.0
github.com/davecgh/go-spew (go) v1.1.1
github.com/inconshreveable/mousetrap (go) v1.1.0
github.com/lucasb-eyer/go-colorful (go) v1.3.0
github.com/mattn/go-runewidth (go) v0.0.20
github.com/muesli/cancelreader (go) v0.2.2
github.com/muesli/mango (go) v0.1.0
github.com/muesli/mango-pflag (go) v0.1.0
github.com/pmezard/go-difflib (go) v1.0.0
github.com/rivo/uniseg (go) v0.4.7
github.com/xo/terminfo (go) v0.0.0-20220910002029-abceb7e1c41e
golang.org/x/sync (go) v0.19.0
gopkg.in/yaml.v3 (go) v3.0.1
Files by Type (count)
Other (.golden)
39
Go
9
YAML
7
Markdown
3
Git Ignore
1
Other (no ext)
1
Other (.mod)
1
Other (.sum)
1
Files by Type (size)
Go
39KB
Other (.golden)
10KB
Markdown
7KB
Other (.sum)
6KB
YAML
3KB
Other (.mod)
1KB
Other (no ext)
79B
Git Ignore
31B

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.

file: theme.go ↗ | tags: #theme #color-scheme #styling

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.

file: fang_windows.go ↗ | tags: #platform-specific #windows-vt-processing #terminal-compatibility
Last analyzed: 2026-09-09 11:01:11.749139
Next check: 2026-09-16 11:01:11.744317
$ submit: