fix-ctrl-c-double-exit-windows#86
Merged
Merged
Conversation
…icate events Windows Terminal (ConPTY) may deliver two KeyDown events for a single Ctrl+C press (native KEY_EVENT + ctrl_handler injected event). Without debounce, both events reach handle_ctrl_c within ~0-1ms, causing the quit-pending logic to trigger Quit on a single keypress. Added a 100ms minimum interval check: if quit_pending_since was set less than 100ms ago, treat the event as a duplicate and ignore it. Fixes #85 Co-Authored-By: mimo-v2.5-pro <XiaomiMiMo@cc-code>
lines[N] 硬编码索引在 persist hint 附加行后错位,改用 contains 检查。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
Windows Terminal (ConPTY) 下按一次 Ctrl+C 偶发直接退出程序。
根因
ctrl_handler收到CTRL_C_EVENT时注入 KeyDown + KeyUp 事件对。但 ConPTY 下原始 KEY_EVENT 可能残留在输入缓冲区中,crossterm 读到两个 KeyDown 事件(间隔约 0-1ms),直接触发 quit-pending → Quit。修复
在
handle_ctrl_c中加 100ms 防抖:quit_pending_since设置后 100ms 内的重复事件视为同一次按键,忽略。不影响正常双击退出(人类间隔 200ms+)。改动
peri-tui/src/event/keyboard/normal_keys.rs—handle_ctrl_c增加 100ms 最小间隔检查peri-tui/src/event/keyboard.rs— 端到端测试适配防抖间隔Fixes #85