feat: add toggleable raw diff view with color support#112
Conversation
Migrated the diff view logic from the main model into a dedicated `diffViewModel` struct to improve separation of concerns and maintainability of the Bubble Tea model. - Introduced `showDiffView` state. - Encapsulated UI rendering and message handling for the diff view. - Simplified the main `Model` update and view logic by delegating to the new component.
Apply strikethrough to the CTRL+K keybinding in the help text to visually indicate the action is currently unavailable or disabled.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Coverage Report for CI Build 26846112045Coverage decreased (-1.7%) to 32.269%Details
Uncovered Changes
Coverage Regressions3 previously-covered lines in 2 files lost coverage.
Coverage Stats
💛 - Coveralls |
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
- Consolidate duplicate diff argument construction into `diffArgs` helper - Update `diff_view` UI to mark removed shortcuts as strikethrough
- Update `diffArgs` to accept an exclusion flag for better control. - Enhance error handling in `DiffWithColor` for `io.Copy` and `cmd.Wait`. - Simplify `repeatCount` calculation in `diffViewModel` using `max`.
Cache the `lipgloss.Style` in the `diffViewModel` struct instead of re-instantiating it on every view update to improve rendering efficiency.
- Inline `viewport` initialization in `commitViewModel`.
- Update `diffViewModel` help text to include new keybindings:
- **CTRL+K**: Clear
- **CTRL+P**: Editor (swapped from Preview)
…t/diff-view * 'main' of github.com:rm-hull/git-commit-summary: fix: streamline summary generation with persistent hints (#116) fix: re-enable help text when cancelling regeneration (#115) chore: migrate to Charm v2 ecosystem (#114) chore: update download stats [skip ci] chore: go get -u && go mod tidy (#113)
Consolidate `Diff` and `DiffWithColor` into a single, parameterized `Diff` method to reduce code duplication and simplify the `GitClient` interface. - Updated `GitClient` interface to support color and exclusion flags. - Simplified `Model` diff retrieval by calling the unified `Diff` method. - Cleaned up redundant UI code.
- Replace tabs with spaces in diff output for consistent formatting. - Refactor state transitions to use custom message types for `showDiffView` and `cancelDiffView`. - Clean up `Update` logic in the main model for better maintainability.
Moved `diffColorMsg` from `diff_view.go` to the main `model.go` struct to centralize state management and allow access across different UI components.
Removed `width` and `height` from the `Model` struct as they are no longer being utilized within the UI logic.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a raw diff view accessible via CTRL+D and integrates PTY support to provide colored git diffs. Key changes include refactoring the GitClient interface, implementing a new diffViewModel, and updating the UI state machine to handle diff transitions. Feedback highlights a potential syscall.EIO error when reading from PTY on Linux, a missing window resize handler for the new view, and the accidental removal of the undo hint from the help text. Additionally, a correction was suggested for the mock git client in tests to properly track arguments.
| if _, err := io.Copy(&buf, ptmx); err != nil { | ||
| return "", errors.Wrap(err, "reading git diff output failed") | ||
| } |
There was a problem hiding this comment.
On Linux systems, reading from a PTY master file descriptor often returns a syscall.EIO error when the child process (in this case, git) terminates. This will cause io.Copy to return an error even if the command executed successfully and all output was captured. You should check for this specific error and treat it as an EOF if the command otherwise succeeded.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Update `TestModel_Update` to include the required boolean flags for the `Diff` method call to match the updated internal API signature.
Add Raw Diff view to TUI. Allow users to inspect staged changes with original git colors before/during commit summary generation.
Key Changes
DiffWithColorusing a PTY (pseudo-terminal) to trick git into emitting ANSI color codes.showDiffViewstate.CTRL+Dtoggle between commit view and diff view.diffColorMsgto handle asynchronous diff loading.diffViewModelusingbubbles/viewportfor scrollable, colored diff output.User Flow
graph TD A[Commit View] -- "CTRL+D" --> B{Diff Loaded?} B -- No --> C[Fetch Colored Diff] C --> D[Diff View] B -- Yes --> D D -- "CTRL+D / ESC" --> ATechnical Implementation Detail
git diffnormally strips colors when output is piped. To preserve them, the app now spawnsgitinside a PTY, forcing git to believe it's talking to a real terminal, thus preserving ANSI color codes for the TUI.