Repository navigation
fix(terminal_view): 粘贴按实时终端模式判断 bracketed paste,避免包装序列字面泄漏 - #441
Merged
Merged
Conversation
问题(issue #198):macOS 粘贴到远程 bash 时出现 \`[200~ 字面文本。 根因:粘贴路径读取渲染帧缓存的 terminal_frame_snapshot.mode 判断是否 包装 \\x1b[200~,而 bash 5.1+ 每次执行命令都会翻转 2004 模式(执行前 发 ?2004l、回到提示符发 ?2004h)。渲染快照在解析线程持锁(try_lock 失败)或帧间隙时滞后,用过期 ON 判断去包装、远端实际 OFF,包装序列 被当字面文本回显。 修复:粘贴入口(paste_text / paste_text_unchecked / paste_remote_image_path) 改为实时 try_lock 读取 Term mode(resolve_live_term_mode),锁被解析器 占用时回退渲染快照,与既有行为一致。 回归测试:快照 ON + 实时 OFF 时不包装;锁占用时回退快照。
CI 的 setup-rust-toolchain 默认注入 RUSTFLAGS=-D warnings, 本地 cargo test 只告警不拦截,导致 3 处 unused import 漏过: paste_mode_test_term 的 StdSyncHandler 与两个测试函数内重复 的 FairMutex 导入。删除后以 RUSTFLAGS=-D warnings 重跑 cargo test -p terminal_view --lib,599 项全部通过。
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.
问题
Closes #198
macOS 上 Ctrl+V 粘贴多行文本到远程 Ubuntu bash 时,终端出现 `[200~ 字面控制序列(如 `cd [200
verify_activity)。根因
粘贴路径通过渲染帧缓存的
terminal_frame_snapshot.mode判断是否用\\x1b[200~ ... \\x1b[201~包装粘贴内容。但 bash 5.1+ 的 readahead 优化会在每次执行命令时翻转 2004 bracketed paste 模式:执行前发?2004l关闭、回到提示符发?2004h开启。渲染快照只在渲染线程成功 try_lock 解析锁时更新,解析线程持锁(大量输出)或帧间隙时快照滞后。当快照停留在过期的 ON、而远端 bash 实际已关闭 2004 时,我方仍按 ON 包装 → 远端把包装序列当字面文本回显。
修复
粘贴入口(
paste_text/paste_text_unchecked/paste_remote_image_path)改为实时try_lock读取 Term mode:resolve_live_term_mode(helpers.rs):实时读取 + 快照回退的纯函数TerminalView::live_term_mode(state.rs):集中代理,避免各入口散落 try_lock解析锁被占用时回退渲染快照,与既有行为一致(该场景粘贴本身也会被写队列排队)。
验证
cargo test -p terminal_view --lib:599 passed(含 2 个新增回归测试)resolve_live_term_mode_prefers_realtime_term_mode_over_stale_snapshot:快照 ON + 实时 OFF 时不包装(issue [Bug]: Bracketed paste control characters[200~leaked into terminal on Ctrl+V #198 场景)resolve_live_term_mode_falls_back_to_snapshot_when_term_locked:锁占用时回退快照cargo clippy -p terminal_view:无新增警告(既有基线不变)rustfmt --check:改动文件全部干净