From b8e3172ce03c7d96ff40a0fe617789b860547776 Mon Sep 17 00:00:00 2001 From: Matt Low Date: Sat, 21 Sep 2024 02:47:03 +0000 Subject: [PATCH] Start new conversations from TUI --- pkg/tui/model/model.go | 6 ++++++ pkg/tui/shared/shared.go | 6 ++++++ pkg/tui/views/chat/input.go | 5 +++++ pkg/tui/views/conversations/conversations.go | 5 +++-- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/pkg/tui/model/model.go b/pkg/tui/model/model.go index 60132ec..88c54cf 100644 --- a/pkg/tui/model/model.go +++ b/pkg/tui/model/model.go @@ -31,6 +31,12 @@ const ( CyclePrev MessageCycleDirection = -1 ) +func (m *AppModel) ClearConversation() { + m.Conversation = nil + m.Messages = []api.Message{} + m.RootMessages = []api.Message{} +} + func (m *AppModel) LoadConversations() (error, []LoadedConversation) { messages, err := m.Ctx.Store.LatestConversationMessages() if err != nil { diff --git a/pkg/tui/shared/shared.go b/pkg/tui/shared/shared.go index 3a63978..55338cd 100644 --- a/pkg/tui/shared/shared.go +++ b/pkg/tui/shared/shared.go @@ -56,6 +56,12 @@ func ViewEnter() tea.Cmd { } } +func ChangeView(view View) tea.Cmd { + return func() tea.Msg { + return MsgViewChange(view) + } +} + func KeyHandled(key tea.KeyMsg) tea.Cmd { return func() tea.Msg { return MsgKeyHandled(key) diff --git a/pkg/tui/views/chat/input.go b/pkg/tui/views/chat/input.go index 398ee25..5d04008 100644 --- a/pkg/tui/views/chat/input.go +++ b/pkg/tui/views/chat/input.go @@ -52,6 +52,11 @@ func (m *Model) handleInput(msg tea.KeyMsg) tea.Cmd { m.rebuildMessageCache() m.updateContent() return shared.KeyHandled(msg) + case "ctrl+n": + m.App.ClearConversation() + m.rebuildMessageCache() + m.updateContent() + return shared.KeyHandled(msg) } return nil } diff --git a/pkg/tui/views/conversations/conversations.go b/pkg/tui/views/conversations/conversations.go index 55f07a7..146be52 100644 --- a/pkg/tui/views/conversations/conversations.go +++ b/pkg/tui/views/conversations/conversations.go @@ -64,8 +64,8 @@ func (m *Model) handleInput(msg tea.KeyMsg) tea.Cmd { switch msg.String() { case "enter": if len(m.App.Conversations) > 0 && m.cursor < len(m.App.Conversations) { + m.App.ClearConversation() m.App.Conversation = &m.App.Conversations[m.cursor].Conv - m.App.Messages = []api.Message{} return func() tea.Msg { return shared.MsgViewChange(shared.ViewChat) } @@ -102,7 +102,8 @@ func (m *Model) handleInput(msg tea.KeyMsg) tea.Cmd { } return shared.KeyHandled(msg) case "n": - // new conversation + m.App.ClearConversation() + return shared.ChangeView(shared.ViewChat) case "d": if !m.confirmPrompt.Focused() && len(m.App.Conversations) > 0 && m.cursor < len(m.App.Conversations) { title := m.App.Conversations[m.cursor].Conv.Title