clifmt

live

Streaming syntax formatter for CLI output. Colorize, filter, and reshape terminal output from any tool.

view source →

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 lexer
  • JSONPretty — streams valid JSON through encoding/json with indentation and key coloring
  • RegexColorizer — applies ANSI colors based on named capture groups
  • LogLevel — detects ERROR, WARN, INFO, DEBUG and assigns colors
clifmt --json
❯ echo '{"status":"ok","code":200}' | clifmt --json { "status": "ok", "code": 200 }

install

go install github.com/handle/clifmt@latest

Or grab a pre-built binary from the releases page.