feat: add Ctrl+D cancellation to TUI

This commit is contained in:
Luxferre
2026-03-22 17:12:34 +02:00
parent 9a0a4e7155
commit 10fa5def68
+21 -5
View File
@@ -321,6 +321,20 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.viewport.HalfViewUp()
return m, nil
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()
return m, nil
case tea.KeyCtrlJ:
@@ -411,11 +425,13 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Batch(tiCmd, vpCmd)
}
func (m model) runAgent() tea.Cmd {
return func() tea.Msg {
res, err := m.agent.Run(context.Background(), m.history, m.pool)
return agentResponseMsg{response: res, err: err}
}
func (m *model) runAgent() tea.Cmd {
var ctx context.Context
ctx, m.cancel = context.WithCancel(context.Background())
return func() tea.Msg {
res, err := m.agent.Run(ctx, m.history, m.pool)
return agentResponseMsg{response: res, err: err}
}
}
func (m model) View() string {