Skip to content

Refactor: Consolidate view style factory pattern #88

@yimsk

Description

@yimsk

Summary

Extract duplicated style struct + factory function pattern across 12+ views into a common utility.

Current Duplication

Similar pattern in every view:

View Struct Location Lines
LogView log_view.go:61-80 20
DetailView detail_view.go:22-35 14
DiffView diff_view.go:32-47 16
HelpView help_view.go:13-28 16
MultiSelector multi_selector.go:19-36 18
ServiceBrowser service_browser.go:78-125 48
ResourceBrowser resource_browser.go:30-49 20
DashboardView dashboard_view.go:21-32 12
HeaderPanel header_panel.go ~15
Modal modal.go ~10
CommandInput command_input.go ~12
ActionMenu action_menu.go ~15
// Every view has this pattern
type xxxViewStyles struct {
    header    lipgloss.Style
    title     lipgloss.Style
    dim       lipgloss.Style
    // ... many repeated fields
}

func newXxxViewStyles() xxxViewStyles {
    t := ui.Current()
    return xxxViewStyles{
        header: lipgloss.NewStyle().Bold(true).Foreground(t.Primary),
        dim:    lipgloss.NewStyle().Foreground(t.TextDim),
        // ... repetitive construction
    }
}

Proposed Solution

Option A: Common style presets in internal/ui/

// internal/ui/styles.go
func (t *Theme) HeaderStyle() lipgloss.Style {
    return lipgloss.NewStyle().Bold(true).Foreground(t.Primary)
}

func (t *Theme) DimStyle() lipgloss.Style {
    return lipgloss.NewStyle().Foreground(t.TextDim)
}

func (t *Theme) ErrorStyle() lipgloss.Style {
    return lipgloss.NewStyle().Foreground(t.Danger)
}

Option B: StyleBuilder pattern

type StyleBuilder struct {
    theme *Theme
    styles map[string]lipgloss.Style
}

func NewStyleBuilder() *StyleBuilder { ... }
func (b *StyleBuilder) Header() lipgloss.Style { ... }
func (b *StyleBuilder) Dim() lipgloss.Style { ... }

Common Style Names Across Views

Style Name Usage Count Pattern
header 8+ views Bold, Primary
title 6+ views Bold, Primary
dim 10+ views TextDim
error 6+ views Danger
paused/warning 3+ views Warning
timestamp 2 views Secondary

Impact

  • Lines removed: 175+ lines of boilerplate
  • Files simplified: 12+ view files
  • Maintainability: Theme changes propagate automatically
  • Consistency: All views use same style definitions

Notes

  • Views may still need custom styles, but common ones should be shared
  • Consider caching at Theme level for performance

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions