feat: themes

This commit is contained in:
adamdottv
2025-04-28 08:46:09 -05:00
parent 61d9dc9511
commit 61b605e724
35 changed files with 2797 additions and 1919 deletions

View File

@@ -27,6 +27,7 @@ type keyMap struct {
SwitchSession key.Binding
Commands key.Binding
Models key.Binding
SwitchTheme key.Binding
}
var keys = keyMap{
@@ -58,6 +59,11 @@ var keys = keyMap{
key.WithKeys("ctrl+o"),
key.WithHelp("ctrl+o", "model selection"),
),
SwitchTheme: key.NewBinding(
key.WithKeys("ctrl+t"),
key.WithHelp("ctrl+t", "switch theme"),
),
}
var helpEsc = key.NewBinding(
@@ -105,6 +111,9 @@ type appModel struct {
showInitDialog bool
initDialog dialog.InitDialogCmp
showThemeDialog bool
themeDialog dialog.ThemeDialog
}
func (a appModel) Init() tea.Cmd {
@@ -126,6 +135,8 @@ func (a appModel) Init() tea.Cmd {
cmds = append(cmds, cmd)
cmd = a.initDialog.Init()
cmds = append(cmds, cmd)
cmd = a.themeDialog.Init()
cmds = append(cmds, cmd)
// Check if we should show the init dialog
cmds = append(cmds, func() tea.Msg {
@@ -255,6 +266,15 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
a.showCommandDialog = false
return a, nil
case dialog.CloseThemeDialogMsg:
a.showThemeDialog = false
return a, nil
case dialog.ThemeChangedMsg:
a.pages[a.currentPage], cmd = a.pages[a.currentPage].Update(msg)
a.showThemeDialog = false
return a, tea.Batch(cmd, util.ReportInfo("Theme changed to: "+msg.ThemeName))
case dialog.CloseModelDialogMsg:
a.showModelDialog = false
return a, nil
@@ -344,7 +364,7 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
return a, nil
case key.Matches(msg, keys.Commands):
if a.currentPage == page.ChatPage && !a.showQuit && !a.showPermissions && !a.showSessionDialog {
if a.currentPage == page.ChatPage && !a.showQuit && !a.showPermissions && !a.showSessionDialog && !a.showThemeDialog {
// Show commands dialog
if len(a.commands) == 0 {
return a, util.ReportWarn("No commands available")
@@ -359,12 +379,19 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
a.showModelDialog = false
return a, nil
}
if a.currentPage == page.ChatPage && !a.showQuit && !a.showPermissions && !a.showSessionDialog && !a.showCommandDialog {
a.showModelDialog = true
return a, nil
}
return a, nil
case key.Matches(msg, keys.SwitchTheme):
if !a.showQuit && !a.showPermissions && !a.showSessionDialog && !a.showCommandDialog {
// Show theme switcher dialog
a.showThemeDialog = true
// Theme list is dynamically loaded by the dialog component
return a, a.themeDialog.Init()
}
return a, nil
case key.Matches(msg, logsKeyReturnKey):
if a.currentPage == page.LogsPage {
return a, a.moveToPage(page.ChatPage)
@@ -465,6 +492,16 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
}
if a.showThemeDialog {
d, themeCmd := a.themeDialog.Update(msg)
a.themeDialog = d.(dialog.ThemeDialog)
cmds = append(cmds, themeCmd)
// Only block key messages send all other messages down
if _, ok := msg.(tea.KeyMsg); ok {
return a, tea.Batch(cmds...)
}
}
s, _ := a.status.Update(msg)
a.status = s.(core.StatusCmp)
a.pages[a.currentPage], cmd = a.pages[a.currentPage].Update(msg)
@@ -629,6 +666,21 @@ func (a appModel) View() string {
)
}
if a.showThemeDialog {
overlay := a.themeDialog.View()
row := lipgloss.Height(appView) / 2
row -= lipgloss.Height(overlay) / 2
col := lipgloss.Width(appView) / 2
col -= lipgloss.Width(overlay) / 2
appView = layout.PlaceOverlay(
col,
row,
overlay,
appView,
true,
)
}
return appView
}
@@ -645,6 +697,7 @@ func New(app *app.App) tea.Model {
modelDialog: dialog.NewModelDialogCmp(),
permissions: dialog.NewPermissionDialogCmp(),
initDialog: dialog.NewInitDialogCmp(),
themeDialog: dialog.NewThemeDialogCmp(),
app: app,
commands: []dialog.Command{},
pages: map[page.PageID]tea.Model{