|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Development Commands |
| 6 | + |
| 7 | +### Testing |
| 8 | +```bash |
| 9 | +go test ./... # Run all tests |
| 10 | +go test ./internal/gat # Test core functionality |
| 11 | +go test ./internal/prettier # Test code formatting |
| 12 | +``` |
| 13 | + |
| 14 | +### Building |
| 15 | +```bash |
| 16 | +go build # Build for current platform |
| 17 | +goreleaser check # Validate goreleaser config |
| 18 | +goreleaser release --snapshot --clean # Build cross-platform binaries |
| 19 | +``` |
| 20 | + |
| 21 | +### Linting |
| 22 | +```bash |
| 23 | +golangci-lint run --verbose ./... # Run linter (configured via mise.toml) |
| 24 | +``` |
| 25 | + |
| 26 | +### Running |
| 27 | +```bash |
| 28 | +go run . [file]... # Run from source |
| 29 | +./gat [file]... # Run built binary |
| 30 | +``` |
| 31 | + |
| 32 | +## Architecture |
| 33 | + |
| 34 | +### Core Components |
| 35 | + |
| 36 | +**CLI Layer (`cmd/`)** |
| 37 | +- `root.go`: Main cobra command setup with terminal detection logic |
| 38 | +- `flags.go`: All CLI flags and environment variable handling (`GAT_FORMAT`, `GAT_THEME`) |
| 39 | +- `version.go`: Version command implementation |
| 40 | + |
| 41 | +**Core Engine (`internal/gat/`)** |
| 42 | +- `gat.go`: Main `Gat` struct and `Print()` method - handles content detection, lexer selection, and output formatting |
| 43 | +- `formats.go` & `languages.go`: List available output formats and supported languages |
| 44 | + |
| 45 | +**Formatters (`internal/formatters/`)** |
| 46 | +- Wrapper around Chroma formatters for terminal, HTML, JSON, SVG output |
| 47 | +- Includes minified variants for web formats |
| 48 | + |
| 49 | +**Lexers (`internal/lexers/`)** |
| 50 | +- Language detection logic using filename and content analysis |
| 51 | +- Integrates with Chroma lexer registry |
| 52 | + |
| 53 | +**Code Prettification (`internal/prettier/`)** |
| 54 | +- Language-specific formatters (Go, JSON, HTML, CSS, XML, YAML) |
| 55 | +- Registry pattern for extensible formatting support |
| 56 | +- `fallback.go`: Default pass-through for unsupported languages |
| 57 | + |
| 58 | +**Themes (`internal/styles/`)** |
| 59 | +- Custom theme registry including `noop.xml` for no-color output |
| 60 | +- Wraps Chroma's style system |
| 61 | + |
| 62 | +### Key Data Flow |
| 63 | + |
| 64 | +- **Input Processing**: `gat.Print()` reads content and detects MIME type |
| 65 | +- **Content Detection**: Binary vs text, with special handling for images and gzip |
| 66 | +- **Lexer Selection**: Auto-detect language from filename/content or use explicit `--lang` |
| 67 | +- **Content Transformation**: |
| 68 | + - Markdown rendering (glamour) if `--render-markdown` |
| 69 | + - Code prettification if `--pretty` |
| 70 | +- **Output Formatting**: Apply syntax highlighting and format (terminal/HTML/JSON/SVG) |
| 71 | + |
| 72 | +### Special Features |
| 73 | + |
| 74 | +**Image Handling** |
| 75 | +- Sixel encoding for terminal image display |
| 76 | +- Automatic resizing (max 1800px edge, disabled with `--no-resize`) |
| 77 | +- Supports JPEG, PNG, GIF |
| 78 | + |
| 79 | +**Terminal Behavior** |
| 80 | +- Auto-detects piped output and disables colors (unless `--force-color`) |
| 81 | +- Uses `noop` theme for non-terminal output |
| 82 | +- Forces binary output when piped |
| 83 | + |
| 84 | +**Environment Integration** |
| 85 | +- `GAT_FORMAT` and `GAT_THEME` environment variables |
| 86 | +- Terminal detection for appropriate output formatting |
| 87 | + |
| 88 | +## Tool Configuration |
| 89 | + |
| 90 | +The project uses: |
| 91 | +- **mise**: Tool version management (Go 1.24.3, golangci-lint, vhs, goreleaser) |
| 92 | +- **goreleaser**: Cross-platform building and release automation |
| 93 | +- **GitHub Actions**: CI with test/build/lint jobs |
| 94 | + |
| 95 | +## Testing Strategy |
| 96 | + |
| 97 | +Tests focus on: |
| 98 | +- Format and language listing functionality |
| 99 | +- Code prettification for each supported language |
| 100 | +- Error handling and edge cases in prettier modules |
0 commit comments