fix: hide cursor during selection mode and agent execution

- Permission selection: cursor hidden (❯ marker indicates selection)
- AskUser selection: cursor hidden (same reason)
- Agent running: cursor hidden (no text input needed)
- AskUser input mode: cursor still visible at text position
- Normal idle: cursor visible at input position

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
pull/1/head
abel533 1 month ago
parent f05732a60c
commit d63a10c221
  1. 20
      src/main/java/com/claudecode/tui/ClaudeCodeComponent.java

@ -192,27 +192,29 @@ public class ClaudeCodeComponent extends Component<ClaudeCodeComponent.TuiState>
lastLine = inputLines[inputLines.length - 1]; lastLine = inputLines[inputLines.length - 1];
} }
// 光标定位(clamp 到 >= 0 防止小终端越界) // 光标定位:仅在需要文本输入时显示光标,选择模式和 agent 运行时隐藏
if (snapAskOptions != null && !snapAskOptions.isEmpty() && snapHasCallback) { if (snapAskOptions != null && !snapAskOptions.isEmpty() && snapHasCallback) {
if (snapAskInputMode) { if (snapAskInputMode) {
// AskUser 自由输入模式:光标在文本末尾
int askCursorRow = h - 2 - (snapAskOptions.size() - snapAskSelected); int askCursorRow = h - 2 - (snapAskOptions.size() - snapAskSelected);
setCursorPosition(Math.max(0, askCursorRow), 7 + StringWidth.width(s.inputText)); setCursorPosition(Math.max(0, askCursorRow), 7 + StringWidth.width(s.inputText));
} else { } else {
int askCursorRow = h - 2 - (snapAskOptions.size() - snapAskSelected); // AskUser 选择模式:❯ 标记已指示选中项,隐藏光标
setCursorPosition(Math.max(0, askCursorRow), 6); setCursorPosition(-1, -1);
} }
} else if (snapPermOptions != null && !snapPermOptions.isEmpty() && snapHasCallback) { } else if (snapPermOptions != null && !snapPermOptions.isEmpty() && snapHasCallback) {
// 权限选择模式:光标在选中选项的 ❯ 位置 // 权限选择模式:❯ 标记已指示选中项,隐藏光标
int permCursorRow = h - 2 - (snapPermOptions.size() - snapPermSelected); setCursorPosition(-1, -1);
setCursorPosition(Math.max(0, permCursorRow), 3); } else if (agentRunning.get()) {
// Agent 运行中:无需输入,隐藏光标
setCursorPosition(-1, -1);
} else if (historySearchMode) { } else if (historySearchMode) {
// 搜索模式:光标在搜索词 █ 的位置 // 搜索模式:光标在搜索词末尾
// "(reverse-i-search)`" = 20 chars, then query, then "█"
int cursorRow = Math.max(0, h - 3); int cursorRow = Math.max(0, h - 3);
int cursorCol = 1 + 20 + StringWidth.width(historySearchQuery); int cursorCol = 1 + 20 + StringWidth.width(historySearchQuery);
setCursorPosition(cursorRow, cursorCol); setCursorPosition(cursorRow, cursorCol);
} else { } else {
// 正常模式:光标隐藏在块光标 █ 的位置 // 正常输入模式:光标在输入文本末尾
int cursorRow = Math.max(0, h - 3); int cursorRow = Math.max(0, h - 3);
int cursorCol = 1 + PROMPT_WIDTH + StringWidth.width(lastLine); int cursorCol = 1 + PROMPT_WIDTH + StringWidth.width(lastLine);
setCursorPosition(cursorRow, cursorCol); setCursorPosition(cursorRow, cursorCol);

Loading…
Cancel
Save