diff options
| author | adamdottv <[email protected]> | 2025-07-02 16:08:06 -0500 |
|---|---|---|
| committer | adamdottv <[email protected]> | 2025-07-02 16:08:11 -0500 |
| commit | c82a060eca41b990b4dd89cecffb874b2133af6f (patch) | |
| tree | c3bb84aee2e621da9feb18f866c88fc51da0e7c1 /packages/tui/internal/components/diff | |
| parent | 63e783ef795d91c745733b945247e917f1683d31 (diff) | |
| download | opencode-c82a060eca41b990b4dd89cecffb874b2133af6f.tar.gz opencode-c82a060eca41b990b4dd89cecffb874b2133af6f.zip | |
feat(tui): file viewer, select messages
Diffstat (limited to 'packages/tui/internal/components/diff')
| -rw-r--r-- | packages/tui/internal/components/diff/diff.go | 59 |
1 files changed, 15 insertions, 44 deletions
diff --git a/packages/tui/internal/components/diff/diff.go b/packages/tui/internal/components/diff/diff.go index 3d0e41fc3..02c2c31e9 100644 --- a/packages/tui/internal/components/diff/diff.go +++ b/packages/tui/internal/components/diff/diff.go @@ -73,44 +73,6 @@ type linePair struct { right *DiffLine } -// ------------------------------------------------------------------------- -// Side-by-Side Configuration -// ------------------------------------------------------------------------- - -// SideBySideConfig configures the rendering of side-by-side diffs -type SideBySideConfig struct { - TotalWidth int -} - -// SideBySideOption modifies a SideBySideConfig -type SideBySideOption func(*SideBySideConfig) - -// NewSideBySideConfig creates a SideBySideConfig with default values -func NewSideBySideConfig(opts ...SideBySideOption) SideBySideConfig { - config := SideBySideConfig{ - TotalWidth: 160, // Default width for side-by-side view - } - - for _, opt := range opts { - opt(&config) - } - - return config -} - -// WithTotalWidth sets the total width for side-by-side view -func WithTotalWidth(width int) SideBySideOption { - return func(s *SideBySideConfig) { - if width > 0 { - s.TotalWidth = width - } - } -} - -// ------------------------------------------------------------------------- -// Unified Configuration -// ------------------------------------------------------------------------- - // UnifiedConfig configures the rendering of unified diffs type UnifiedConfig struct { Width int @@ -122,13 +84,22 @@ type UnifiedOption func(*UnifiedConfig) // NewUnifiedConfig creates a UnifiedConfig with default values func NewUnifiedConfig(opts ...UnifiedOption) UnifiedConfig { config := UnifiedConfig{ - Width: 80, // Default width for unified view + Width: 80, } - for _, opt := range opts { opt(&config) } + return config +} +// NewSideBySideConfig creates a SideBySideConfig with default values +func NewSideBySideConfig(opts ...UnifiedOption) UnifiedConfig { + config := UnifiedConfig{ + Width: 160, + } + for _, opt := range opts { + opt(&config) + } return config } @@ -907,7 +878,7 @@ func RenderUnifiedHunk(fileName string, h Hunk, opts ...UnifiedOption) string { } // RenderSideBySideHunk formats a hunk for side-by-side display -func RenderSideBySideHunk(fileName string, h Hunk, opts ...SideBySideOption) string { +func RenderSideBySideHunk(fileName string, h Hunk, opts ...UnifiedOption) string { // Apply options to create the configuration config := NewSideBySideConfig(opts...) @@ -922,10 +893,10 @@ func RenderSideBySideHunk(fileName string, h Hunk, opts ...SideBySideOption) str pairs := pairLines(hunkCopy.Lines) // Calculate column width - colWidth := config.TotalWidth / 2 + colWidth := config.Width / 2 leftWidth := colWidth - rightWidth := config.TotalWidth - colWidth + rightWidth := config.Width - colWidth var sb strings.Builder util.WriteStringsPar(&sb, pairs, func(p linePair) string { @@ -963,7 +934,7 @@ func FormatUnifiedDiff(filename string, diffText string, opts ...UnifiedOption) } // FormatDiff creates a side-by-side formatted view of a diff -func FormatDiff(filename string, diffText string, opts ...SideBySideOption) (string, error) { +func FormatDiff(filename string, diffText string, opts ...UnifiedOption) (string, error) { diffResult, err := ParseUnifiedDiff(diffText) if err != nil { return "", err |
