Cleaned up tui view switching
This commit is contained in:
parent
ed784bb1cf
commit
97cd047861
@ -91,21 +91,13 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.state = shared.View(msg)
|
m.state = shared.View(msg)
|
||||||
switch m.state {
|
switch m.state {
|
||||||
case shared.StateChat:
|
case shared.StateChat:
|
||||||
m.chat.HandleResize(m.State.Width, m.State.Height)
|
m.chat.HandleResize(m.Width, m.Height)
|
||||||
case shared.StateConversations:
|
case shared.StateConversations:
|
||||||
m.conversations.HandleResize(m.State.Width, m.State.Height)
|
m.conversations.HandleResize(m.Width, m.Height)
|
||||||
}
|
}
|
||||||
return m, func() tea.Msg { return shared.MsgViewEnter(struct{}{}) }
|
return m, func() tea.Msg { return shared.MsgViewEnter(struct{}{}) }
|
||||||
case conversations.MsgConversationSelected:
|
|
||||||
// passed up through conversation list model
|
|
||||||
m.State.Values.ConvShortname = msg.ShortName.String
|
|
||||||
cmds = append(cmds, func() tea.Msg {
|
|
||||||
return shared.MsgViewChange(shared.StateChat)
|
|
||||||
})
|
|
||||||
case tea.WindowSizeMsg:
|
case tea.WindowSizeMsg:
|
||||||
m.State.Width, m.State.Height = msg.Width, msg.Height
|
m.Width, m.Height = msg.Width, msg.Height
|
||||||
case shared.MsgError:
|
|
||||||
m.State.Err = msg
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmd tea.Cmd
|
var cmd tea.Cmd
|
||||||
@ -123,18 +115,13 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m Model) View() string {
|
func (m Model) View() string {
|
||||||
if m.State.Width == 0 {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
switch m.state {
|
switch m.state {
|
||||||
case shared.StateConversations:
|
case shared.StateConversations:
|
||||||
return m.conversations.View()
|
return m.conversations.View()
|
||||||
case shared.StateChat:
|
case shared.StateChat:
|
||||||
return m.chat.View()
|
return m.chat.View()
|
||||||
default:
|
|
||||||
return ""
|
|
||||||
}
|
}
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func Launch(ctx *lmcli.Context, convShortname string) error {
|
func Launch(ctx *lmcli.Context, convShortname string) error {
|
||||||
|
@ -90,9 +90,9 @@ type Model struct {
|
|||||||
replyCursor cursor.Model // cursor to indicate incoming response
|
replyCursor cursor.Model // cursor to indicate incoming response
|
||||||
}
|
}
|
||||||
|
|
||||||
func Chat(tui shared.State) Model {
|
func Chat(state shared.State) Model {
|
||||||
m := Model{
|
m := Model{
|
||||||
State: tui,
|
State: state,
|
||||||
|
|
||||||
conversation: &models.Conversation{},
|
conversation: &models.Conversation{},
|
||||||
persistence: true,
|
persistence: true,
|
||||||
@ -125,7 +125,7 @@ func Chat(tui shared.State) Model {
|
|||||||
m.replyCursor.SetChar(" ")
|
m.replyCursor.SetChar(" ")
|
||||||
m.replyCursor.Focus()
|
m.replyCursor.Focus()
|
||||||
|
|
||||||
system := tui.Ctx.GetSystemPrompt()
|
system := state.Ctx.GetSystemPrompt()
|
||||||
if system != "" {
|
if system != "" {
|
||||||
m.messages = []models.Message{{
|
m.messages = []models.Message{{
|
||||||
Role: models.MessageRoleSystem,
|
Role: models.MessageRoleSystem,
|
||||||
|
@ -24,7 +24,7 @@ type (
|
|||||||
// sent when conversation list is loaded
|
// sent when conversation list is loaded
|
||||||
msgConversationsLoaded ([]loadedConversation)
|
msgConversationsLoaded ([]loadedConversation)
|
||||||
// sent when a conversation is selected
|
// sent when a conversation is selected
|
||||||
MsgConversationSelected models.Conversation
|
msgConversationSelected models.Conversation
|
||||||
)
|
)
|
||||||
|
|
||||||
type Model struct {
|
type Model struct {
|
||||||
@ -51,7 +51,7 @@ func (m *Model) HandleInput(msg tea.KeyMsg) (bool, tea.Cmd) {
|
|||||||
case "enter":
|
case "enter":
|
||||||
if len(m.conversations) > 0 && m.cursor < len(m.conversations) {
|
if len(m.conversations) > 0 && m.cursor < len(m.conversations) {
|
||||||
return true, func() tea.Msg {
|
return true, func() tea.Msg {
|
||||||
return MsgConversationSelected(m.conversations[m.cursor].conv)
|
return msgConversationSelected(m.conversations[m.cursor].conv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "j", "down":
|
case "j", "down":
|
||||||
@ -121,6 +121,11 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
|||||||
case msgConversationsLoaded:
|
case msgConversationsLoaded:
|
||||||
m.conversations = msg
|
m.conversations = msg
|
||||||
m.content.SetContent(m.renderConversationList())
|
m.content.SetContent(m.renderConversationList())
|
||||||
|
case msgConversationSelected:
|
||||||
|
m.Values.ConvShortname = msg.ShortName.String
|
||||||
|
cmds = append(cmds, func() tea.Msg {
|
||||||
|
return shared.MsgViewChange(shared.StateChat)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmd tea.Cmd
|
var cmd tea.Cmd
|
||||||
|
Loading…
Reference in New Issue
Block a user