A high-performance, terminal-based Minesweeper game built with Go. This project demonstrates a professional CLI architecture using the "Golden Stack" of Go terminal development: Cobra, Viper, and Bubble Tea.
- Language: Go (1.21+)
- CLI Framework: Cobra (Standard for Kubernetes/Docker CLIs)
- TUI Engine: Bubble Tea (Functional state management)
- Styling: Lip Gloss & ANSI Escape Sequences
- Configuration: Viper
This project follows the Standard Go Project Layout to ensure a strict separation of concerns:
| Layer | Package | Responsibility |
|---|---|---|
| CLI | cmd/ |
Handles flag parsing (--mines, --rows) and command execution. |
| Logic | internal/engine/ |
Pure game logic: mine placement, neighbor counting, and flood-fill algorithms. |
| UI | internal/ui/ |
The "View" layer. Implements the Bubble Tea Update/View lifecycle. |
- Model-View-Update (MVU): Used via Bubble Tea to handle UI states without side effects.
- Dependency Injection: The Game Engine is injected into the UI Model, making the core logic testable without a terminal.
- Encapsulation: All game internals are kept in
internal/to prevent external package leakage.
- In-Place Rendering: Uses ANSI escape codes for smooth, flicker-free terminal updates.
- APT-Style Progress Bar: Real-time visual feedback on board clearance using the
bubbles/progresscomponent. - Dynamic Difficulty: Fully configurable board dimensions and mine density via CLI flags.
- Color-Coded Interface: High-contrast ANSI colors for numerical proximity and hazard warnings.
go install# Start with default settings (10x10, 12 mines)
minesweeper
# Custom difficulty
minesweeper --rows 15 --cols 20 --mines 40- The Recursive Reveal (Flood Fill) Implemented an optimized flood-fill algorithm that automatically clears empty areas when a "0" cell is revealed. This ensures the game feels fluid and follows classic Minesweeper mechanics.
- State Management in TUI Managed the transition between "Input Mode" (typing coordinates) and "Action Mode" (revealing/flagging) within the Bubble Tea event loop, ensuring a 0-latency user experience.