summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authoradamdottv <[email protected]>2025-06-13 06:49:59 -0500
committeradamdottv <[email protected]>2025-06-13 06:49:59 -0500
commit1b8cfe9e99e7b97069580a2e8aaa8cf1abb56d31 (patch)
treec701adcb2ac2b097bfd18d05804e68a144b17b54
parent97837d2d23195942dbbb15f3c5ed749b1af688aa (diff)
downloadopencode-1b8cfe9e99e7b97069580a2e8aaa8cf1abb56d31.tar.gz
opencode-1b8cfe9e99e7b97069580a2e8aaa8cf1abb56d31.zip
wip: refactoring tui
-rw-r--r--packages/tui/internal/components/chat/editor.go2
-rw-r--r--packages/tui/internal/components/chat/messages.go31
-rw-r--r--packages/tui/internal/components/dialog/models.go10
-rw-r--r--packages/tui/internal/components/dialog/quit.go8
-rw-r--r--packages/tui/internal/components/dialog/session.go4
-rw-r--r--packages/tui/internal/components/dialog/theme.go5
-rw-r--r--packages/tui/internal/theme/manager.go19
-rw-r--r--packages/tui/internal/tui/tui.go4
8 files changed, 40 insertions, 43 deletions
diff --git a/packages/tui/internal/components/chat/editor.go b/packages/tui/internal/components/chat/editor.go
index f78bd1926..24cb588ed 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.go
index ef35a3532..81f2d2a38 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().Render
muted := styles.Muted().Render
headerLines := []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.Config
commands := [][]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.go
index ed2ab3354..616347088 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.go
index be5400652..1be3cce95 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.Quit
case key.Matches(msg, helpKeys.No):
- return q, tea.Batch(
- util.CmdHandler(modal.CloseModalMsg{}),
- )
+ return q, util.CmdHandler(modal.CloseModalMsg{})
}
}
return q, nil
diff --git a/packages/tui/internal/components/dialog/session.go b/packages/tui/internal/components/dialog/session.go
index 9bcf0690c..46e015950 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.session
s.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.go
index 66fd5feec..332d05824 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.go
index 3e351f7f1..c54ed1119 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.go
index 639e573d9..03fc2e0dd 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...)