The open source coding agent.
TypeScript
wip: refactoring tui
adamdottv1b8cfe9e99e7
diff --git a/packages/tui/internal/components/chat/editor.go b/packages/tui/internal/components/chat/editor.goindex f78bd192609..24cb588edde 100644--- a/packages/tui/internal/components/chat/editor.go+++ b/packages/tui/internal/components/chat/editor.go@@ -273,7 +273,7 @@ func (m *editorComponent) View() string {Width(m.width).Background(t.BackgroundElement()).Border(lipgloss.ThickBorder(), false, true).- BorderForeground(t.BorderActive()).+ BorderForeground(t.BackgroundSubtle()).BorderBackground(t.Background()).Render(textarea)diff --git a/packages/tui/internal/components/chat/messages.go b/packages/tui/internal/components/chat/messages.goindex ef35a353290..81f2d2a38aa 100644--- a/packages/tui/internal/components/chat/messages.go+++ b/packages/tui/internal/components/chat/messages.go@@ -245,7 +245,7 @@ func (m *messagesComponent) header() string {base := styles.BaseStyle().Rendermuted := styles.Muted().RenderheaderLines := []string{}- headerLines = append(headerLines, toMarkdown("# "+m.app.Session.Title, width, t.Background()))+ headerLines = append(headerLines, toMarkdown("# "+m.app.Session.Title, width-4, t.BackgroundElement()))if m.app.Session.Share != nil && m.app.Session.Share.Url != "" {headerLines = append(headerLines, muted(m.app.Session.Share.Url))} else {@@ -255,20 +255,25 @@ func (m *messagesComponent) header() string {header = styles.BaseStyle().Width(width).- PaddingTop(1).- BorderBottom(true).- BorderForeground(t.BorderSubtle()).- BorderStyle(lipgloss.NormalBorder()).- Background(t.Background()).+ PaddingLeft(2).+ Background(t.BackgroundElement()).+ BorderLeft(true).+ BorderRight(true).+ BorderBackground(t.Background()).+ BorderForeground(t.BackgroundSubtle()).+ BorderStyle(lipgloss.ThickBorder()).Render(header)- return header+ return "\n" + header + "\n"}func (m *messagesComponent) View() string {- if len(m.app.Messages) == 0 || m.rendering {+ if len(m.app.Messages) == 0 {return m.home()}+ if m.rendering {+ return m.viewport.View()+ }return lipgloss.JoinVertical(lipgloss.Left,lipgloss.PlaceHorizontal(m.width, lipgloss.Center, m.header()),@@ -301,8 +306,8 @@ func (m *messagesComponent) home() string {styles.Muted().Render(open),styles.BaseStyle().Render(code),)- cwd := app.Info.Path.Cwd- config := app.Info.Path.Config+ // cwd := app.Info.Path.Cwd+ // config := app.Info.Path.Configcommands := [][]string{{"/help", "show help"},@@ -329,9 +334,9 @@ func (m *messagesComponent) home() string {lines = append(lines, "")lines = append(lines, logoAndVersion)lines = append(lines, "")- lines = append(lines, base("cwd ")+muted(cwd))- lines = append(lines, base("config ")+muted(config))- lines = append(lines, "")+ // lines = append(lines, base("cwd ")+muted(cwd))+ // lines = append(lines, base("config ")+muted(config))+ // lines = append(lines, "")lines = append(lines, commandLines...)lines = append(lines, "")if m.rendering {diff --git a/packages/tui/internal/components/dialog/models.go b/packages/tui/internal/components/dialog/models.goindex ed2ab33548e..6163470883f 100644--- a/packages/tui/internal/components/dialog/models.go+++ b/packages/tui/internal/components/dialog/models.go@@ -112,8 +112,14 @@ func (m *modelDialog) Update(msg tea.Msg) (tea.Model, tea.Cmd) {}case key.Matches(msg, modelKeys.Enter):models := m.models()- cmd := util.CmdHandler(state.ModelSelectedMsg{Provider: m.provider, Model: models[m.selectedIdx]})- return m, tea.Batch(cmd, util.CmdHandler(modal.CloseModalMsg{}))+ return m, tea.Sequence(+ util.CmdHandler(modal.CloseModalMsg{}),+ util.CmdHandler(+ state.ModelSelectedMsg{+ Provider: m.provider,+ Model: models[m.selectedIdx],+ }),+ )case key.Matches(msg, modelKeys.Escape):return m, util.CmdHandler(modal.CloseModalMsg{})}diff --git a/packages/tui/internal/components/dialog/quit.go b/packages/tui/internal/components/dialog/quit.goindex be540065208..1be3cce9530 100644--- a/packages/tui/internal/components/dialog/quit.go+++ b/packages/tui/internal/components/dialog/quit.go@@ -73,15 +73,11 @@ func (q *quitDialog) Update(msg tea.Msg) (tea.Model, tea.Cmd) {if !q.selectedNo {return q, tea.Quit}- return q, tea.Batch(- util.CmdHandler(modal.CloseModalMsg{}),- )+ return q, util.CmdHandler(modal.CloseModalMsg{})case key.Matches(msg, helpKeys.Yes):return q, tea.Quitcase key.Matches(msg, helpKeys.No):- return q, tea.Batch(- util.CmdHandler(modal.CloseModalMsg{}),- )+ return q, util.CmdHandler(modal.CloseModalMsg{})}}return q, nildiff --git a/packages/tui/internal/components/dialog/session.go b/packages/tui/internal/components/dialog/session.goindex 9bcf0690c24..46e01595078 100644--- a/packages/tui/internal/components/dialog/session.go+++ b/packages/tui/internal/components/dialog/session.go@@ -67,9 +67,9 @@ func (s *sessionDialog) Update(msg tea.Msg) (tea.Model, tea.Cmd) {if item, idx := s.list.GetSelectedItem(); idx >= 0 {selectedSession := item.sessions.selectedSessionID = selectedSession.Id- return s, tea.Batch(- util.CmdHandler(state.SessionSelectedMsg(&selectedSession)),+ return s, tea.Sequence(util.CmdHandler(modal.CloseModalMsg{}),+ util.CmdHandler(state.SessionSelectedMsg(&selectedSession)),)}}diff --git a/packages/tui/internal/components/dialog/theme.go b/packages/tui/internal/components/dialog/theme.goindex 66fd5feec20..332d0582468 100644--- a/packages/tui/internal/components/dialog/theme.go+++ b/packages/tui/internal/components/dialog/theme.go@@ -74,9 +74,9 @@ func (t *themeDialog) Update(msg tea.Msg) (tea.Model, tea.Cmd) {status.Error(err.Error())return t, nil}- return t, tea.Batch(- util.CmdHandler(ThemeChangedMsg{ThemeName: selectedTheme}),+ return t, tea.Sequence(util.CmdHandler(modal.CloseModalMsg{}),+ util.CmdHandler(ThemeChangedMsg{ThemeName: selectedTheme}),)}}@@ -125,4 +125,3 @@ func NewThemeDialog() ThemeDialog {modal: modal.New(modal.WithTitle("Select Theme"), modal.WithMaxWidth(40)),}}-diff --git a/packages/tui/internal/theme/manager.go b/packages/tui/internal/theme/manager.goindex 3e351f7f1a2..c54ed11196c 100644--- a/packages/tui/internal/theme/manager.go+++ b/packages/tui/internal/theme/manager.go@@ -6,6 +6,8 @@ import ("slices""strings""sync"++ "github.com/alecthomas/chroma/v2/styles"// "github.com/alecthomas/chroma/v2/styles")@@ -45,22 +47,7 @@ func RegisterTheme(name string, theme Theme) {func SetTheme(name string) error {globalManager.mu.Lock()defer globalManager.mu.Unlock()- // delete(styles.Registry, "charm")-- // Handle custom theme- // if name == "custom" {- // cfg := config.Get()- // if cfg == nil || cfg.TUI.CustomTheme == nil || len(cfg.TUI.CustomTheme) == 0 {- // return fmt.Errorf("custom theme selected but no custom theme colors defined in config")- // }- //- // customTheme, err := LoadCustomTheme(cfg.TUI.CustomTheme)- // if err != nil {- // return fmt.Errorf("failed to load custom theme: %w", err)- // }- //- // // Register the custom theme- // globalManager.themes["custom"] = customTheme+ delete(styles.Registry, "charm")if _, exists := globalManager.themes[name]; !exists {return fmt.Errorf("theme '%s' not found", name)diff --git a/packages/tui/internal/tui/tui.go b/packages/tui/internal/tui/tui.goindex 639e573d98d..03fc2e0dd30 100644--- a/packages/tui/internal/tui/tui.go+++ b/packages/tui/internal/tui/tui.go@@ -271,6 +271,10 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {cmds = append(cmds, cmd)}+ s, cmd := a.status.Update(msg)+ cmds = append(cmds, cmd)+ a.status = s.(core.StatusComponent)+t := theme.CurrentTheme()cmds = append(cmds, tea.SetBackgroundColor(t.Background()))return a, tea.Batch(cmds...)