Private
Public Access
1
0

TUI view management and input handling cleanup

This commit is contained in:
2024-09-16 15:40:04 +00:00
parent 24b5cdbbf6
commit 463ca9ef40
7 changed files with 169 additions and 154 deletions

View File

@@ -47,9 +47,17 @@ func (m *Model) updateContent() {
}
}
func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
func (m Model) Update(msg tea.Msg) (shared.ViewModel, tea.Cmd) {
inputHandled := false
var cmds []tea.Cmd
switch msg := msg.(type) {
case tea.KeyMsg:
cmd := m.handleInput(msg)
if cmd != nil {
inputHandled = true
cmds = append(cmds, cmd)
}
case tea.WindowSizeMsg:
m.Width, m.Height = msg.Width, msg.Height
m.content.Width = msg.Width
@@ -167,7 +175,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
m.updateContent()
case msgChatResponseError:
m.state = idle
m.Shared.Err = error(msg)
m.ViewState.Err = error(msg)
m.updateContent()
case msgToolResults:
last := len(m.App.Messages) - 1
@@ -231,14 +239,16 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
}
prevInputLineCnt := m.input.LineCount()
inputCaptured := false
m.input, cmd = m.input.Update(msg)
if cmd != nil {
inputCaptured = true
cmds = append(cmds, cmd)
if !inputHandled {
m.input, cmd = m.input.Update(msg)
if cmd != nil {
inputHandled = true
cmds = append(cmds, cmd)
}
}
if !inputCaptured {
if !inputHandled {
m.content, cmd = m.content.Update(msg)
if cmd != nil {
cmds = append(cmds, cmd)
@@ -285,5 +295,8 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
}
}
return m, tea.Batch(cmds...)
if len(cmds) > 0 {
return m, tea.Batch(cmds...)
}
return m, nil
}