feat: add Ctrl+D cancellation to TUI
This commit is contained in:
@@ -321,6 +321,20 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.viewport.HalfViewUp()
|
m.viewport.HalfViewUp()
|
||||||
return m, nil
|
return m, nil
|
||||||
case tea.KeyPgDown, tea.KeyCtrlD:
|
case tea.KeyPgDown, tea.KeyCtrlD:
|
||||||
|
if msg.Type == tea.KeyCtrlD && m.isThinking {
|
||||||
|
if m.cancel != nil {
|
||||||
|
m.cancel()
|
||||||
|
}
|
||||||
|
m.isThinking = false
|
||||||
|
m.currentReasoning = ""
|
||||||
|
m.currentStream = ""
|
||||||
|
m.history = append(m.history, sidekick.Message{
|
||||||
|
Role: sidekick.MessageRoleSystem,
|
||||||
|
Content: "Request cancelled.",
|
||||||
|
})
|
||||||
|
m.updateViewportContent()
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
m.viewport.HalfViewDown()
|
m.viewport.HalfViewDown()
|
||||||
return m, nil
|
return m, nil
|
||||||
case tea.KeyCtrlJ:
|
case tea.KeyCtrlJ:
|
||||||
@@ -411,9 +425,11 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
return m, tea.Batch(tiCmd, vpCmd)
|
return m, tea.Batch(tiCmd, vpCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m model) runAgent() tea.Cmd {
|
func (m *model) runAgent() tea.Cmd {
|
||||||
|
var ctx context.Context
|
||||||
|
ctx, m.cancel = context.WithCancel(context.Background())
|
||||||
return func() tea.Msg {
|
return func() tea.Msg {
|
||||||
res, err := m.agent.Run(context.Background(), m.history, m.pool)
|
res, err := m.agent.Run(ctx, m.history, m.pool)
|
||||||
return agentResponseMsg{response: res, err: err}
|
return agentResponseMsg{response: res, err: err}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user