From c82a060eca41b990b4dd89cecffb874b2133af6f Mon Sep 17 00:00:00 2001 From: adamdottv <2363879+adamdottv@users.noreply.github.com> Date: Wed, 2 Jul 2025 16:08:06 -0500 Subject: feat(tui): file viewer, select messages --- packages/tui/internal/components/diff/diff.go | 59 +++++++-------------------- 1 file changed, 15 insertions(+), 44 deletions(-) (limited to 'packages/tui/internal/components/diff/diff.go') 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 -- cgit v1.2.3