Start new conversations from TUI

This commit is contained in:
Matt Low 2024-09-21 02:47:03 +00:00
parent a1fdf3f7cd
commit b8e3172ce0
4 changed files with 20 additions and 2 deletions

View File

@ -31,6 +31,12 @@ const (
CyclePrev MessageCycleDirection = -1 CyclePrev MessageCycleDirection = -1
) )
func (m *AppModel) ClearConversation() {
m.Conversation = nil
m.Messages = []api.Message{}
m.RootMessages = []api.Message{}
}
func (m *AppModel) LoadConversations() (error, []LoadedConversation) { func (m *AppModel) LoadConversations() (error, []LoadedConversation) {
messages, err := m.Ctx.Store.LatestConversationMessages() messages, err := m.Ctx.Store.LatestConversationMessages()
if err != nil { if err != nil {

View File

@ -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 { func KeyHandled(key tea.KeyMsg) tea.Cmd {
return func() tea.Msg { return func() tea.Msg {
return MsgKeyHandled(key) return MsgKeyHandled(key)

View File

@ -52,6 +52,11 @@ func (m *Model) handleInput(msg tea.KeyMsg) tea.Cmd {
m.rebuildMessageCache() m.rebuildMessageCache()
m.updateContent() m.updateContent()
return shared.KeyHandled(msg) return shared.KeyHandled(msg)
case "ctrl+n":
m.App.ClearConversation()
m.rebuildMessageCache()
m.updateContent()
return shared.KeyHandled(msg)
} }
return nil return nil
} }

View File

@ -64,8 +64,8 @@ func (m *Model) handleInput(msg tea.KeyMsg) tea.Cmd {
switch msg.String() { switch msg.String() {
case "enter": case "enter":
if len(m.App.Conversations) > 0 && m.cursor < len(m.App.Conversations) { 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.Conversation = &m.App.Conversations[m.cursor].Conv
m.App.Messages = []api.Message{}
return func() tea.Msg { return func() tea.Msg {
return shared.MsgViewChange(shared.ViewChat) return shared.MsgViewChange(shared.ViewChat)
} }
@ -102,7 +102,8 @@ func (m *Model) handleInput(msg tea.KeyMsg) tea.Cmd {
} }
return shared.KeyHandled(msg) return shared.KeyHandled(msg)
case "n": case "n":
// new conversation m.App.ClearConversation()
return shared.ChangeView(shared.ViewChat)
case "d": case "d":
if !m.confirmPrompt.Focused() && len(m.App.Conversations) > 0 && m.cursor < len(m.App.Conversations) { if !m.confirmPrompt.Focused() && len(m.App.Conversations) > 0 && m.cursor < len(m.App.Conversations) {
title := m.App.Conversations[m.cursor].Conv.Title title := m.App.Conversations[m.cursor].Conv.Title