diff options
| author | adamdottv <[email protected]> | 2025-06-17 07:09:04 -0500 |
|---|---|---|
| committer | adamdottv <[email protected]> | 2025-06-17 07:09:04 -0500 |
| commit | a5da5127faffacd7703fc0dde061ef1f490d3dce (patch) | |
| tree | ab9c65d0eb45ab9fdc326187ca5881dc9b10936e /packages/tui/internal/components/chat | |
| parent | b5a4439704c70a17d661f1984bb030d5325d141a (diff) | |
| download | opencode-a5da5127faffacd7703fc0dde061ef1f490d3dce.tar.gz opencode-a5da5127faffacd7703fc0dde061ef1f490d3dce.zip | |
chore: consolidate chat page into tui.go
Diffstat (limited to 'packages/tui/internal/components/chat')
| -rw-r--r-- | packages/tui/internal/components/chat/editor.go | 13 | ||||
| -rw-r--r-- | packages/tui/internal/components/chat/messages.go | 21 |
2 files changed, 24 insertions, 10 deletions
diff --git a/packages/tui/internal/components/chat/editor.go b/packages/tui/internal/components/chat/editor.go index 349087fbe..a2d33f172 100644 --- a/packages/tui/internal/components/chat/editor.go +++ b/packages/tui/internal/components/chat/editor.go @@ -16,12 +16,17 @@ import ( "github.com/sst/opencode/internal/commands" "github.com/sst/opencode/internal/components/dialog" "github.com/sst/opencode/internal/image" - "github.com/sst/opencode/internal/layout" "github.com/sst/opencode/internal/styles" "github.com/sst/opencode/internal/theme" "github.com/sst/opencode/internal/util" ) +type EditorComponent interface { + tea.Model + tea.ViewModel + Value() string +} + type editorComponent struct { width int height int @@ -99,7 +104,7 @@ func (m *editorComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmds []tea.Cmd var cmd tea.Cmd switch msg := msg.(type) { - case dialog.ThemeChangedMsg: + case dialog.ThemeSelectedMsg: m.textarea = createTextArea(&m.textarea) m.spinner = createSpinner() return m, m.spinner.Tick @@ -434,11 +439,11 @@ func createSpinner() spinner.Model { ) } -func (m *editorComponent) GetValue() string { +func (m *editorComponent) Value() string { return m.textarea.Value() } -func NewEditorComponent(app *app.App) layout.ModelWithView { +func NewEditorComponent(app *app.App) EditorComponent { s := createSpinner() ta := createTextArea(nil) diff --git a/packages/tui/internal/components/chat/messages.go b/packages/tui/internal/components/chat/messages.go index d0d839845..37e3380ca 100644 --- a/packages/tui/internal/components/chat/messages.go +++ b/packages/tui/internal/components/chat/messages.go @@ -12,12 +12,16 @@ import ( "github.com/sst/opencode/internal/app" "github.com/sst/opencode/internal/components/dialog" "github.com/sst/opencode/internal/layout" - "github.com/sst/opencode/internal/state" "github.com/sst/opencode/internal/styles" "github.com/sst/opencode/internal/theme" "github.com/sst/opencode/pkg/client" ) +type MessagesComponent interface { + tea.Model + tea.ViewModel +} + type messagesComponent struct { app *app.App width, height int @@ -69,7 +73,7 @@ func (m *messagesComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.viewport.GotoBottom() m.tail = true return m, nil - case dialog.ThemeChangedMsg: + case dialog.ThemeSelectedMsg: m.cache.Clear() m.renderView() return m, nil @@ -77,12 +81,12 @@ func (m *messagesComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.showToolResults = !m.showToolResults m.renderView() return m, nil - case state.SessionSelectedMsg: + case app.SessionSelectedMsg: m.cache.Clear() cmd := m.Reload() m.viewport.GotoBottom() return m, cmd - case state.SessionClearedMsg: + case app.SessionClearedMsg: m.cache.Clear() cmd := m.Reload() return m, cmd @@ -101,7 +105,12 @@ func (m *messagesComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if m.tail { m.viewport.GotoBottom() } - case state.StateUpdatedMsg: + case client.EventSessionUpdated: + m.renderView() + if m.tail { + m.viewport.GotoBottom() + } + case client.EventMessageUpdated: m.renderView() if m.tail { m.viewport.GotoBottom() @@ -389,7 +398,7 @@ func (m *messagesComponent) Reload() tea.Cmd { } } -func NewMessagesComponent(app *app.App) layout.ModelWithView { +func NewMessagesComponent(app *app.App) MessagesComponent { customSpinner := spinner.Spinner{ Frames: []string{" ", "┃", "┃"}, FPS: time.Second / 3, |
