-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add toggleable raw diff view with color support #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
rm-hull
wants to merge
17
commits into
main
Choose a base branch
from
feat/diff-view
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1c99f48
wip
rm-hull 637f191
refactor: encapsulate diff view into its own component
rm-hull a8030bf
style: update commit view help text style
rm-hull b0d0f44
Update internal/git/client.go
rm-hull 6fa85f5
refactor: extract git diff argument builder
rm-hull 2a1a94e
refactor: improve git diff logic and UI cleanup
rm-hull b2607cf
refactor: move boxStyle to diffViewModel struct
rm-hull ec54b4a
refactor: streamline view initialization and update UI keys
rm-hull 6ab1bba
Merge branch 'main' of github.com:rm-hull/git-commit-summary into fea…
rm-hull 27cfe1f
refactor: unify diff logic in git client
rm-hull e4bcbde
feat: improve diff display and navigation
rm-hull 44bc5e5
refactor: remove manual window resizing logic
rm-hull 0c4a405
refactor: move diffColorMsg to shared model
rm-hull 99410d7
refactor: remove unused dimension fields from Model
rm-hull 4a64529
Update internal/ui/model_test.go
rm-hull e8b84e3
test: update git diff mock parameters
rm-hull fe8f1f4
Merge branch 'main' into feat/diff-view
rm-hull File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package ui | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| "charm.land/bubbles/v2/viewport" | ||
| tea "charm.land/bubbletea/v2" | ||
| "charm.land/lipgloss/v2" | ||
| ) | ||
|
|
||
| type diffViewModel struct { | ||
| viewport viewport.Model | ||
| boxStyle lipgloss.Style | ||
| } | ||
|
|
||
| func initialDiffViewModel(width, height int) *diffViewModel { | ||
| vp := viewport.New(viewport.WithWidth(width), viewport.WithHeight(height)) | ||
| vp.SoftWrap = false | ||
|
|
||
| return &diffViewModel{ | ||
| viewport: vp, | ||
| boxStyle: lipgloss.NewStyle(). | ||
| BorderForeground(lipgloss.Color("6")). // Cyan | ||
| Padding(0, 1), | ||
| } | ||
| } | ||
|
|
||
| func (m *diffViewModel) Init() tea.Cmd { | ||
| return nil | ||
| } | ||
|
|
||
| func (m *diffViewModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | ||
| switch msg := msg.(type) { | ||
| case tea.KeyPressMsg: | ||
| switch msg.String() { | ||
| case "esc", "ctrl+d": | ||
| return m, func() tea.Msg { return cancelDiffViewMsg{} } | ||
| } | ||
| case diffColorMsg: | ||
| m.viewport.SetContent(string(msg)) | ||
| return m, nil | ||
| } | ||
|
|
||
| var cmd tea.Cmd | ||
| m.viewport, cmd = m.viewport.Update(msg) | ||
| return m, cmd | ||
| } | ||
|
|
||
| func (m *diffViewModel) View() tea.View { | ||
| title := " Raw diff " | ||
| titleBorder := lipgloss.RoundedBorder() | ||
|
|
||
| repeatCount := max((m.viewport.Width()+2)-lipgloss.Width(title), 0) | ||
| titleBorder.Top = title + strings.Repeat("─", repeatCount) | ||
|
|
||
| helpText := fmt.Sprintf("%s:commit %s:clear %s:regen %s:editor %s:diff %s:back", | ||
| Strikethrough.Render("CTRL+A"), | ||
| Strikethrough.Render("CTRL+K"), | ||
| Strikethrough.Render("CTRL+R"), | ||
| Strikethrough.Render("CTRL+P"), | ||
| BoldYellow.Render("CTRL+D"), | ||
| BoldYellow.Render("ESC")) | ||
|
|
||
| return tea.NewView(m.boxStyle. | ||
| BorderStyle(titleBorder). | ||
| Render(m.viewport.View()) + "\n" + helpText) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Linux systems, reading from a PTY master file descriptor often returns a
syscall.EIOerror when the child process (in this case,git) terminates. This will causeio.Copyto 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.