在通过 CancellationToken 取消列表提示后,Cursor 留下了隐藏项

作者: glen-84创建于 2026年7月19日更新于 2026年7月19日
标签area: promptarea: progressarea: console

Information

  • OS: Linux
  • Version: 0.57.2 (also present on main as of this writing)
  • Terminal: any ANSI terminal (observed on Ghostty) Describe the bug When an interactive list-based prompt (SelectionPrompt, MultiSelectionPrompt) is cancelled through the CancellationToken passed to ShowAsync — e.g. by wiring Console.CancelKeyPress to a CancellationTokenSource so Ctrl+C aborts the prompt — the terminal Cursor is left hidden. The rest of the terminal state is restored correctly (input/rendering), but the Cursor never becomes visible again, so it looks like typed input has no caret until the Cursor is manually restored (printf '\033[?25h' / tput cnorm).

Root cause In ListPrompt<T>.Show(...), the Cursor is hidden inside the using (new RenderHookScope(...)) block, but Cursor.Show() is only called after the block, past the while loop:

内容来源: spectreconsole/spectre.console