summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authoradamdottv <[email protected]>2025-05-30 06:47:44 -0500
committeradamdottv <[email protected]>2025-05-30 06:47:44 -0500
commit189d0e5fb2fc728c639952dd17fef1abdf251c18 (patch)
treef214079acd5cae2b01d1638486b40462c4f51888
parentb1b402faa7616a4dd976a2a79e57ae0334ab509b (diff)
downloadopencode-189d0e5fb2fc728c639952dd17fef1abdf251c18.tar.gz
opencode-189d0e5fb2fc728c639952dd17fef1abdf251c18.zip
wip: refactoring tui
-rw-r--r--internal/tui/app/app.go26
-rw-r--r--internal/tui/components/chat/messages.go4
-rw-r--r--internal/tui/components/dialog/session.go6
-rw-r--r--internal/tui/page/chat.go1
-rw-r--r--internal/tui/tui.go9
5 files changed, 26 insertions, 20 deletions
diff --git a/internal/tui/app/app.go b/internal/tui/app/app.go
index 3ee0f564d..b00a6d61a 100644
--- a/internal/tui/app/app.go
+++ b/internal/tui/app/app.go
@@ -143,26 +143,30 @@ func (a *App) ListSessions(ctx context.Context) ([]client.SessionInfo, error) {
if err != nil {
return nil, err
}
-
if resp.StatusCode() != 200 {
return nil, fmt.Errorf("failed to list sessions: %d", resp.StatusCode())
}
-
if resp.JSON200 == nil {
return []client.SessionInfo{}, nil
}
- infos := *resp.JSON200
+ sessions := *resp.JSON200
+ return sessions, nil
+}
- sessions := make([]client.SessionInfo, len(infos))
- for i, info := range infos {
- sessions[i] = client.SessionInfo{
- Id: info.Id,
- Title: info.Title,
- }
+func (a *App) ListMessages(ctx context.Context, sessionId string) ([]client.MessageInfo, error) {
+ resp, err := a.Client.PostSessionMessagesWithResponse(ctx, client.PostSessionMessagesJSONRequestBody{SessionID: sessionId})
+ if err != nil {
+ return nil, err
}
-
- return sessions, nil
+ if resp.StatusCode() != 200 {
+ return nil, fmt.Errorf("failed to list messages: %d", resp.StatusCode())
+ }
+ if resp.JSON200 == nil {
+ return []client.MessageInfo{}, nil
+ }
+ messages := *resp.JSON200
+ return messages, nil
}
// initTheme sets the application theme based on the configuration
diff --git a/internal/tui/components/chat/messages.go b/internal/tui/components/chat/messages.go
index 0dda7ae32..ae6f2a687 100644
--- a/internal/tui/components/chat/messages.go
+++ b/internal/tui/components/chat/messages.go
@@ -73,8 +73,8 @@ func (m *messagesCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
cmd := m.Reload()
return m, cmd
case state.SessionClearedMsg:
- m.rendering = false
- return m, nil
+ cmd := m.Reload()
+ return m, cmd
case tea.KeyMsg:
if key.Matches(msg, messageKeys.PageUp) || key.Matches(msg, messageKeys.PageDown) ||
key.Matches(msg, messageKeys.HalfPageUp) || key.Matches(msg, messageKeys.HalfPageDown) {
diff --git a/internal/tui/components/dialog/session.go b/internal/tui/components/dialog/session.go
index fd08a7db5..99aa41515 100644
--- a/internal/tui/components/dialog/session.go
+++ b/internal/tui/components/dialog/session.go
@@ -74,6 +74,9 @@ func (s *sessionDialogCmp) Init() tea.Cmd {
func (s *sessionDialogCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
+ case tea.WindowSizeMsg:
+ s.width = msg.Width
+ s.height = msg.Height
case tea.KeyMsg:
switch {
case key.Matches(msg, sessionKeys.Up) || key.Matches(msg, sessionKeys.K):
@@ -98,9 +101,6 @@ func (s *sessionDialogCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case key.Matches(msg, sessionKeys.Escape):
return s, util.CmdHandler(CloseSessionDialogMsg{})
}
- case tea.WindowSizeMsg:
- s.width = msg.Width
- s.height = msg.Height
}
return s, nil
}
diff --git a/internal/tui/page/chat.go b/internal/tui/page/chat.go
index 134de6afd..bf30193f5 100644
--- a/internal/tui/page/chat.go
+++ b/internal/tui/page/chat.go
@@ -114,6 +114,7 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// Continue sending keys to layout->chat
case key.Matches(msg, keyMap.NewSession):
p.app.Session = &client.SessionInfo{}
+ p.app.Messages = []client.MessageInfo{}
return p, tea.Batch(
p.clearSidebar(),
util.CmdHandler(state.SessionClearedMsg{}),
diff --git a/internal/tui/tui.go b/internal/tui/tui.go
index 1c20f5c8a..024abe000 100644
--- a/internal/tui/tui.go
+++ b/internal/tui/tui.go
@@ -271,10 +271,6 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case page.PageChangeMsg:
return a, a.moveToPage(msg.ID)
- case state.SessionSelectedMsg:
- a.app.Session = msg
- return a.updateAllPages(msg)
-
case dialog.CloseQuitMsg:
a.showQuit = false
return a, nil
@@ -286,6 +282,11 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
return a, nil
+ case state.SessionSelectedMsg:
+ a.app.Session = msg
+ a.app.Messages, _ = a.app.ListMessages(context.Background(), msg.Id)
+ return a.updateAllPages(msg)
+
case dialog.CloseCommandDialogMsg:
a.showCommandDialog = false
return a, nil