feat: Add TUI diff mode with mouse scroll and self-detection#5
Conversation
Add comprehensive diff viewing capabilities to the CWT TUI: ## Diff Mode Features - Press 'v' on sessions with changes to view unified diff - Syntax highlighting for additions, deletions, and context - Line numbers for easy reference - Scroll with ↑↓/jk, PgUp/PgDn, or mouse wheel - Toggle between working tree and staged changes with 'c' - Refresh diff with 'r', exit with Esc/q ## Mouse Support - Enable mouse wheel scrolling in diff mode - Mouse wheel navigation in main session list - Natural scrolling experience for reviewing long diffs ## Self-Detection for Commands - Auto-detect whether running from source or built binary - Switch/merge/publish commands work with both: - go run cmd/cwt/main.go (development) - ./cwt or cwt (built binary) - Created shared utils.ExecuteCWTCommand() for consistency ## Technical Implementation - New DiffMode state with scroll management - Git diff parsing with structured DiffLine types - Lipgloss styling for syntax highlighting - Mouse event handling in Bubble Tea - Robust executable detection logic Fixes the issue where TUI commands failed when running locally with 'go run' instead of built binary. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Claude finished @jlaneve's task —— View job 🔍 Code Review: TUI Diff Mode & Self-DetectionI've thoroughly analyzed the implementation and have several observations across code quality, potential issues, performance, security, and testing: ✅ StrengthsCode Quality & Design
Self-Detection Implementation
|
- Fix code formatting issues identified by CI - Add missing newline at end of command.go - All files now pass gofmt and go vet checks 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Fix final gofmt formatting issue - Ensure proper file ending without extra blank lines 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…andling - Fix cross-platform temp directory detection in utils/command.go - Add git repository validation before changing directories - Change diff target from 'main' to 'origin/main' for remote comparison - Add ScrollAmount constant to replace magic numbers - Improve error messages by capturing stderr in ExecuteCWTCommand 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
🎯 Overview
This PR adds a comprehensive diff viewing mode to the CWT TUI, along with mouse scroll support and automatic binary detection for command execution.
✨ Key Features
📋 Diff Mode
von any session with changes↑↓/jk,PgUp/PgDn, or mouse wheelc), refresh (r), exit (Esc/q)🖱️ Mouse Support
🔧 Self-Detection
go run cmd/cwt/main.govs built binary🛠️ Technical Implementation
Core Components
ExecuteCWTCommand()with detection logicFiles Changed
internal/tui/model.go: Diff mode state and event handlinginternal/tui/view.go: Diff rendering with lipgloss stylinginternal/tui/commands.go: Git diff parsing and data loadinginternal/utils/command.go: Self-detection utility (new)🧪 Testing
Tested with both execution methods:
go run cmd/cwt/main.go(development)./cwt(built binary)📸 Demo
The diff mode provides:
🔗 Related Issues
Fixes the issue where TUI commands (switch/merge/publish) failed when running with
go runinstead of a built binary.Ready for review! The diff mode makes it much easier to review changes before deciding to merge or publish sessions. 🚀