Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions packages/tui/internal/components/dialog/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ type themeDialog struct {
width int
height 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 {
Expand All @@ -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 = true
return t, tea.Sequence(
util.CmdHandler(modal.CloseModalMsg{}),
util.CmdHandler(ThemeSelectedMsg{ThemeName: selectedTheme}),
)
}

}
}

_, prevIdx := t.list.GetSelectedItem()

var cmd tea.Cmd
listModel, 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)
Comment thread
xHeaven marked this conversation as resolved.
}

return t, cmd
}

Expand All @@ -92,6 +99,9 @@ func (t *themeDialog) Render(background string) string {
}

func (t *themeDialog) Close() tea.Cmd {
if !t.themeApplied {
theme.SetTheme(t.originalTheme)
Comment thread
xHeaven marked this conversation as resolved.
}
return nil
}

Expand Down Expand Up @@ -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,
}
}
9 changes: 7 additions & 2 deletions packages/tui/internal/tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch keyString {
// Escape always closes current modal
case "esc", "ctrl+c":
cmd := a.modal.Close()
a.modal = nil
return a, nil
return a, cmd
Comment thread
xHeaven marked this conversation as resolved.
}

// Pass all other key presses to the modal
Expand Down Expand Up @@ -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, cmd
case commands.ExecuteCommandMsg:
updated, cmd := a.executeCommand(commands.Command(msg))
return updated, cmd
Expand Down