The open source coding agent.
TypeScript
feat(tui): theme switcher with preview (#264)
Márk Magyareee396f903df
diff --git a/packages/tui/internal/components/dialog/theme.go b/packages/tui/internal/components/dialog/theme.goindex 63135bc8139..2bbcebc7153 100644--- a/packages/tui/internal/components/dialog/theme.go+++ b/packages/tui/internal/components/dialog/theme.go@@ -47,8 +47,10 @@ type themeDialog struct {width intheight int- modal *modal.Modal- list list.List[themeItem]+ modal *modal.Modal+ list list.List[themeItem]+ originalTheme string+ themeApplied bool}func (t *themeDialog) Init() tea.Cmd {@@ -64,26 +66,31 @@ func (t *themeDialog) Update(msg tea.Msg) (tea.Model, tea.Cmd) {switch msg.String() {case "enter":if item, idx := t.list.GetSelectedItem(); idx >= 0 {- previousTheme := theme.CurrentThemeName()selectedTheme := item.name- if previousTheme == selectedTheme {- return t, util.CmdHandler(modal.CloseModalMsg{})- }if err := theme.SetTheme(selectedTheme); err != nil {// status.Error(err.Error())return t, nil}+ t.themeApplied = truereturn t, tea.Sequence(util.CmdHandler(modal.CloseModalMsg{}),util.CmdHandler(ThemeSelectedMsg{ThemeName: selectedTheme}),)}+}}+ _, prevIdx := t.list.GetSelectedItem()+var cmd tea.CmdlistModel, cmd := t.list.Update(msg)t.list = listModel.(list.List[themeItem])++ if item, newIdx := t.list.GetSelectedItem(); newIdx >= 0 && newIdx != prevIdx {+ theme.SetTheme(item.name)+ }+return t, cmd}@@ -92,6 +99,9 @@ func (t *themeDialog) Render(background string) string {}func (t *themeDialog) Close() tea.Cmd {+ if !t.themeApplied {+ theme.SetTheme(t.originalTheme)+ }return nil}@@ -120,7 +130,9 @@ func NewThemeDialog() ThemeDialog {list.SetSelectedIndex(selectedIdx)return &themeDialog{- list: list,- modal: modal.New(modal.WithTitle("Select Theme"), modal.WithMaxWidth(40)),+ list: list,+ modal: modal.New(modal.WithTitle("Select Theme"), modal.WithMaxWidth(40)),+ originalTheme: currentTheme,+ themeApplied: false,}}diff --git a/packages/tui/internal/tui/tui.go b/packages/tui/internal/tui/tui.goindex f88e3e976dd..5de8bfbd65e 100644--- a/packages/tui/internal/tui/tui.go+++ b/packages/tui/internal/tui/tui.go@@ -77,8 +77,9 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {switch keyString {// Escape always closes current modalcase "esc", "ctrl+c":+ cmd := a.modal.Close()a.modal = nil- return a, nil+ return a, cmd}// Pass all other key presses to the modal@@ -194,8 +195,12 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {}slog.Debug("Background color", "isDark", msg.IsDark())case modal.CloseModalMsg:+ var cmd tea.Cmd+ if a.modal != nil {+ cmd = a.modal.Close()+ }a.modal = nil- return a, nil+ return a, cmdcase commands.ExecuteCommandMsg:updated, cmd := a.executeCommand(commands.Command(msg))return updated, cmd