diff options
| author | adamdottv <[email protected]> | 2025-05-28 12:35:20 -0500 |
|---|---|---|
| committer | adamdottv <[email protected]> | 2025-05-28 15:36:35 -0500 |
| commit | 15d21bf04acd6af75df97918f66df866c239b248 (patch) | |
| tree | 16ac93b0c686faaf3b21700771b082b6bc26f098 /internal/tui/components | |
| parent | 5e738ce7d3b66b88a407a1bcc53a5169d0f4a904 (diff) | |
| download | opencode-15d21bf04acd6af75df97918f66df866c239b248.tar.gz opencode-15d21bf04acd6af75df97918f66df866c239b248.zip | |
wip: refactoring tui
Diffstat (limited to 'internal/tui/components')
| -rw-r--r-- | internal/tui/components/chat/messages.go | 72 |
1 files changed, 18 insertions, 54 deletions
diff --git a/internal/tui/components/chat/messages.go b/internal/tui/components/chat/messages.go index 613c4169a..681606b9f 100644 --- a/internal/tui/components/chat/messages.go +++ b/internal/tui/components/chat/messages.go @@ -2,9 +2,9 @@ package chat import ( "context" + "encoding/json" "fmt" "math" - "strings" "time" "github.com/charmbracelet/bubbles/key" @@ -156,55 +156,6 @@ func (m *messagesCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } } } - case app.StorageWriteMsg: - // Handle storage write events from the TypeScript backend - keyParts := strings.Split(msg.Key, "/") - if len(keyParts) >= 4 && keyParts[0] == "session" && keyParts[1] == "message" { - sessionID := keyParts[2] - if sessionID == m.app.CurrentSession.ID { - // Convert storage message to internal format - convertedMsg, err := app.ConvertStorageMessage(msg.Content, sessionID) - if err != nil { - status.Error("Failed to convert message: " + err.Error()) - return m, nil - } - - // Check if message exists - messageExists := false - messageIndex := -1 - for i, v := range m.messages { - if v.ID == convertedMsg.ID { - messageExists = true - messageIndex = i - break - } - } - - needsRerender := false - if messageExists { - // Update existing message - m.messages[messageIndex] = *convertedMsg - delete(m.cachedContent, convertedMsg.ID) - needsRerender = true - } else { - // Add new message - if len(m.messages) > 0 { - lastMsgID := m.messages[len(m.messages)-1].ID - delete(m.cachedContent, lastMsgID) - } - - m.messages = append(m.messages, *convertedMsg) - delete(m.cachedContent, m.currentMsgID) - m.currentMsgID = convertedMsg.ID - needsRerender = true - } - - if needsRerender { - m.renderView() - m.viewport.GotoBottom() - } - } - } } spinner, cmd := m.spinner.Update(msg) @@ -293,20 +244,33 @@ func (m *messagesCmp) renderView() { ) } + temp, _ := json.MarshalIndent(m.app.State, "", " ") + m.viewport.SetContent( baseStyle. Width(m.width). Render( - lipgloss.JoinVertical( - lipgloss.Top, - messages..., - ), + string(temp), + // lipgloss.JoinVertical( + // lipgloss.Top, + // messages..., + // ), ), ) } func (m *messagesCmp) View() string { baseStyle := styles.BaseStyle() + return baseStyle. + Width(m.width). + Render( + lipgloss.JoinVertical( + lipgloss.Top, + m.viewport.View(), + m.working(), + m.help(), + ), + ) if m.rendering { return baseStyle. |
