|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +go-fzf is a Go library and CLI tool for creating fuzzy finders. It provides: |
| 8 | +- A library (`github.com/koki-develop/go-fzf`) for building custom fuzzy finders |
| 9 | +- A CLI tool (`gofzf`) that demonstrates the library's capabilities |
| 10 | + |
| 11 | +## Development Commands |
| 12 | + |
| 13 | +### Build |
| 14 | +```bash |
| 15 | +# Build the CLI tool |
| 16 | +go build ./cmd/gofzf |
| 17 | +``` |
| 18 | + |
| 19 | +### Test |
| 20 | +```bash |
| 21 | +# Run all tests |
| 22 | +go test ./... |
| 23 | + |
| 24 | +# Run tests for a specific package |
| 25 | +go test ./search_test.go |
| 26 | + |
| 27 | +# Run a specific test |
| 28 | +go test -run TestName |
| 29 | +``` |
| 30 | + |
| 31 | +### Lint |
| 32 | +```bash |
| 33 | +# Run golangci-lint (used in CI) |
| 34 | +golangci-lint run |
| 35 | +``` |
| 36 | + |
| 37 | +## Architecture |
| 38 | + |
| 39 | +### Core Components |
| 40 | + |
| 41 | +1. **FZF struct** (`fzf.go`): Main entry point for the library |
| 42 | + - `New()`: Creates a new fuzzy finder instance with options |
| 43 | + - `Find()`: Launches the fuzzy finder and returns selected indexes |
| 44 | + - `ForceReload()`: Forces reload when hot reload is enabled |
| 45 | + |
| 46 | +2. **Model** (`model.go`): Implements the Bubble Tea Model interface |
| 47 | + - Manages UI state, cursor position, selections |
| 48 | + - Handles window sizing and layout |
| 49 | + - Integrates with Bubble Tea for terminal UI |
| 50 | + |
| 51 | +3. **Items** (`item.go`): Manages the list of searchable items |
| 52 | + - Supports both static slices and hot-reloadable pointer-to-slice |
| 53 | + - Provides thread-safe access for hot reload scenarios |
| 54 | + |
| 55 | +4. **Search** (`search.go`): Implements fuzzy search algorithm |
| 56 | + - Case-sensitive/insensitive matching |
| 57 | + - Returns matched indexes for highlighting |
| 58 | + |
| 59 | +5. **Options** (`option.go`): Configuration for fuzzy finder behavior |
| 60 | + - UI customization (prompts, cursors, styles) |
| 61 | + - Behavioral options (multiple selection, limits, case sensitivity) |
| 62 | + - Keymaps and preview windows |
| 63 | + |
| 64 | +6. **Styles** (`styles.go`): Lipgloss styles for UI components |
| 65 | + - Customizable colors and formatting |
| 66 | + - Separate styles for different UI elements |
| 67 | + |
| 68 | +### Key Design Patterns |
| 69 | + |
| 70 | +- **Builder Pattern**: Options are configured through functional options |
| 71 | +- **Model-View Pattern**: Uses Bubble Tea's Model interface for UI state management |
| 72 | +- **Interface-based Design**: Items are accessed through reflection to support any slice type |
| 73 | + |
| 74 | +### Dependencies |
| 75 | + |
| 76 | +- **Bubble Tea**: Terminal UI framework |
| 77 | +- **Lipgloss**: Styling and layout |
| 78 | +- **Cobra**: CLI command framework (for gofzf) |
| 79 | +- **testify**: Testing assertions |
| 80 | + |
| 81 | +## Examples |
| 82 | + |
| 83 | +The `/examples` directory contains multiple demonstrations of library usage: |
| 84 | +- basic: Simple fuzzy finder |
| 85 | +- multiple: Multi-selection |
| 86 | +- hotreload: Dynamic item updates |
| 87 | +- styles: Custom styling |
| 88 | +- keymap: Custom key bindings |
| 89 | +- preview-window: Preview pane functionality |
0 commit comments