clifmt pipes any tool’s output through a configurable formatter: syntax
highlighting, JSON pretty-printing, log-level coloring, and custom regex
rules — all composable and streaming.
the problem
I kept writing the same 20 lines of Go in every CLI tool: parse the
output, colorize tokens, stream to stdout. clifmt pulls that into a
standalone binary and a library you can import.
usage
# Colorize Go source piped from any command
cat main.go | clifmt --lang go
# Pretty-print JSON with highlight
curl -s api.example.com/data | clifmt --json
# Apply custom rules from a config file
my-tool | clifmt --rules ~/.config/clifmt/rules.toml
how it works
The formatter is a pipeline of Transformer interfaces:
type Transformer interface {
Transform(line []byte) ([]byte, error)
}
Each transformer gets a line, does its thing, and passes it on. Transformers are stateless so they compose without side effects.
Built-in transformers:
SyntaxHighlighter— tokenizes source code via a hand-rolled lexerJSONPretty— streams valid JSON throughencoding/jsonwith indentation and key coloringRegexColorizer— applies ANSI colors based on named capture groupsLogLevel— detectsERROR,WARN,INFO,DEBUGand assigns colors
install
go install github.com/handle/clifmt@latest
Or grab a pre-built binary from the releases page.