feat: 添加 Escape/Ctrl+C 中断 Agent 运行功能
- AgentLoop 添加 cancel()/resetCancel() 中断机制 - executeLoop 在每次迭代前和API调用后检查取消标志 - Escape 键和 Ctrl+C 在 Agent 运行时触发中断 - 快捷键栏更新提示 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -508,7 +508,7 @@ public class ClaudeCodeComponent extends Component<ClaudeCodeComponent.TuiState>
|
||||
}
|
||||
|
||||
return Box.of(
|
||||
Text.of("↑↓ history wheel scroll Ctrl+D exit").dimmed(),
|
||||
Text.of("↑↓ history Esc interrupt Ctrl+D exit").dimmed(),
|
||||
Spacer.create(),
|
||||
Text.of(tokenInfo).color(Color.BRIGHT_GREEN)
|
||||
).paddingX(1).height(1);
|
||||
@@ -536,7 +536,7 @@ public class ClaudeCodeComponent extends Component<ClaudeCodeComponent.TuiState>
|
||||
// Ctrl+C: 取消当前输入或中断 Agent
|
||||
if (key.ctrl() && "c".equals(input)) {
|
||||
if (agentRunning.get()) {
|
||||
// TODO: 中断 Agent 运行
|
||||
agentLoop.cancel();
|
||||
addMessageInternal(new SystemMsg("^C (interrupt)", Color.BRIGHT_YELLOW), s);
|
||||
} else {
|
||||
setState(new TuiState("", s.messages, s.scrollOffset, false, ""));
|
||||
@@ -554,9 +554,15 @@ public class ClaudeCodeComponent extends Component<ClaudeCodeComponent.TuiState>
|
||||
return;
|
||||
}
|
||||
|
||||
// AI 运行中时忽略大部分输入(但允许滚动)
|
||||
// AI 运行中时允许滚动和 Escape 中断
|
||||
if (agentRunning.get()) {
|
||||
handleScrollInput(key, s);
|
||||
if (key.escape()) {
|
||||
// Esc: 中断 Agent 运行
|
||||
agentLoop.cancel();
|
||||
addMessageInternal(new SystemMsg("⚡ Interrupted", Color.BRIGHT_YELLOW), s);
|
||||
} else {
|
||||
handleScrollInput(key, s);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user