diff options
| author | adamdottv <[email protected]> | 2025-06-22 05:34:22 -0500 |
|---|---|---|
| committer | adamdottv <[email protected]> | 2025-06-22 05:34:22 -0500 |
| commit | 3ea2daaa4c1fef54c3e827300a63bd3b41b88806 (patch) | |
| tree | 17e2aabe13ecf01a2aa047cc9fec00ae604b864c /packages/tui/internal/components/dialog | |
| parent | 137e964131703704e99a632b3aa0351ab4921fae (diff) | |
| download | opencode-3ea2daaa4c1fef54c3e827300a63bd3b41b88806.tar.gz opencode-3ea2daaa4c1fef54c3e827300a63bd3b41b88806.zip | |
fix(tui): theme dialog visuals
Diffstat (limited to 'packages/tui/internal/components/dialog')
| -rw-r--r-- | packages/tui/internal/components/dialog/theme.go | 44 |
1 files changed, 11 insertions, 33 deletions
diff --git a/packages/tui/internal/components/dialog/theme.go b/packages/tui/internal/components/dialog/theme.go index f00b8d1f0..eea3e74e7 100644 --- a/packages/tui/internal/components/dialog/theme.go +++ b/packages/tui/internal/components/dialog/theme.go @@ -5,7 +5,6 @@ import ( list "github.com/sst/opencode/internal/components/list" "github.com/sst/opencode/internal/components/modal" "github.com/sst/opencode/internal/layout" - "github.com/sst/opencode/internal/styles" "github.com/sst/opencode/internal/theme" "github.com/sst/opencode/internal/util" ) @@ -20,35 +19,12 @@ type ThemeDialog interface { layout.Modal } -type themeItem struct { - name string -} - -func (t themeItem) Render(selected bool, width int) string { - th := theme.CurrentTheme() - baseStyle := styles.BaseStyle(). - Width(width - 2). - Background(th.BackgroundElement()) - - if selected { - baseStyle = baseStyle. - Background(th.Primary()). - Foreground(th.BackgroundElement()). - Bold(true) - } else { - baseStyle = baseStyle. - Foreground(th.Text()) - } - - return baseStyle.Padding(0, 1).Render(t.name) -} - type themeDialog struct { width int height int modal *modal.Modal - list list.List[themeItem] + list list.List[list.StringItem] originalTheme string themeApplied bool } @@ -66,7 +42,7 @@ func (t *themeDialog) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg.String() { case "enter": if item, idx := t.list.GetSelectedItem(); idx >= 0 { - selectedTheme := item.name + selectedTheme := string(item) if err := theme.SetTheme(selectedTheme); err != nil { // status.Error(err.Error()) return t, nil @@ -85,11 +61,11 @@ func (t *themeDialog) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmd tea.Cmd listModel, cmd := t.list.Update(msg) - t.list = listModel.(list.List[themeItem]) + t.list = listModel.(list.List[list.StringItem]) if item, newIdx := t.list.GetSelectedItem(); newIdx >= 0 && newIdx != prevIdx { - theme.SetTheme(item.name) - return t, util.CmdHandler(ThemeSelectedMsg{ThemeName: item.name}) + theme.SetTheme(string(item)) + return t, util.CmdHandler(ThemeSelectedMsg{ThemeName: string(item)}) } return t, cmd } @@ -101,6 +77,7 @@ func (t *themeDialog) Render(background string) string { func (t *themeDialog) Close() tea.Cmd { if !t.themeApplied { theme.SetTheme(t.originalTheme) + return util.CmdHandler(ThemeSelectedMsg{ThemeName: t.originalTheme}) } return nil } @@ -110,17 +87,15 @@ func NewThemeDialog() ThemeDialog { themes := theme.AvailableThemes() currentTheme := theme.CurrentThemeName() - var themeItems []themeItem var selectedIdx int for i, name := range themes { - themeItems = append(themeItems, themeItem{name: name}) if name == currentTheme { selectedIdx = i } } - list := list.NewListComponent( - themeItems, + list := list.NewStringList( + themes, 10, // maxVisibleThemes "No themes available", true, @@ -128,6 +103,9 @@ func NewThemeDialog() ThemeDialog { // Set the initial selection to the current theme list.SetSelectedIndex(selectedIdx) + + // Set the max width for the list to match the modal width + list.SetMaxWidth(36) // 40 (modal max width) - 4 (modal padding) return &themeDialog{ list: list, |
