Repository navigation
feat(desktop): 终端同步 Motty 改进:输出保留选区、行纹理复用、Windows Ctrl+C 与 PowerShell 修正 - #1989
Merged
Merged
Conversation
同步 Motty 自移植基线 8958a472 之后的 6 个终端改动,适配合并后的 View: - 3a2b91dc:屏幕记录缓冲区代数(重置、进出备用屏、清屏时递增)。输出不再 清除选区;回滚丢弃选区开头时截到保留的最早一行,代数变化时才清除。 - c3cc6f6c:每行按「视图 owner + 行 ID」的稳定文字标识绘制,滚动时复用 同一行的纹理,不同视图的标识互不冲突。 - 546e40ae:Windows 启动 Shell 前调用 SetConsoleCtrlHandler(NULL, FALSE), 继承了忽略 Ctrl+C 状态时也能中断伪控制台中的程序。 - dbd2a6f2:「清除」后向停在提示符的 PowerShell 发送换页符,让 PSReadLine 从顶行重绘。没有提示符上报,所以只在 Shell 菜单启动、未运行程序、不在 备用屏时发送。 - 2f73c352:Shell 发现和默认 Shell 加入 Microsoft Store 版 PowerShell 7 的 WindowsApps 别名,排在 Windows PowerShell 5.1 之前。 - 02916ed5:PowerShell 目录集成不再传 -NoLogo(目录集成当前未开启,见 #1984)。 termview/NOTICE 记录了同步的提交;功能矩阵 terminal-interaction、 terminal-shell 补了证据和验证说明,Windows 验证保持 pending。 Refs #1987
xiaoyumuxi
marked this pull request as ready for review
November 15, 2026 18:01
This was referenced Nov 15, 2026
This was referenced Nov 15, 2026
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.
关联 Issue / Linked issue
PR 类型 / Type
改动说明 / What changes
背景 / Why
Lithe 的终端是从 Motty 移植的(基线 8958a472)。之后 Motty 修了几处终端体验问题,Lithe 还没跟上:
本 PR 同步其中 6 个提交,并适配 Lithe 合并后的 View。只移植这几项需要的
term代码,不整体同步 Motty 的term包。改动 / Changes
1. 输出时保留选区(Motty 3a2b91dc)
term/terminal.go、term/csi.go:屏幕新增缓冲区代数BufferGeneration(),在以下四种情况递增:Reset,即 RIS);enterAlt);leaveAlt);ClearScreen()。新增
RetainedFrom(),返回回滚中保留的最早一行。Shell 用ED 3清掉回滚时代数不变,选区由RetainedFrom截短或清除。termview/session.go:write和start之后调用reconcileSelection()。termview/selection.go:新增trim,把选区截到保留的最早一行;整段都被丢弃时清除选区。termview/view.go:View 记录上次对齐到的代数。Prefill后同步代数,避免把预填内容当成新的缓冲区。2. 行纹理复用(Motty c3cc6f6c)
termview/paint.go:每行用LabelRunsWithIdentity绘制,标识是gfx.TextIdentity{Owner: 视图 owner, Item: 行 ID}。行在屏幕上移动后,Viva 能认出是同一行并复用它的纹理。termview/view.go:每个 View 从原子计数器取一个 owner,不同终端视图的标识互不冲突。3. Windows 重新打开 Ctrl+C(Motty 546e40ae)
localshell/backend_windows.go:startBackend启动 ConPTY 前调用SetConsoleCtrlHandler(NULL, FALSE)(restoreCtrlC)。CREATE_NEW_PROCESS_GROUP方式或忽略 Ctrl+C 的父进程启动时,会继承「忽略 Ctrl+C」的状态并传给 Shell;这一步把它清掉。terminal.session.start_failed)。4. 「清除」后让 PowerShell 重绘(Motty dbd2a6f2)
termview/menu.go:Clear()清屏成功后,若lineEditorNeedsFormFeed()成立,向 Shell 发送换页符\f(PSReadLine 当作 Ctrl+L,会从顶行重绘输入行)。cfg.Args == nil);Kind() == PowerShell;!Busy();termview/view.go:shell接口新增Kind() shellkind.Kind。localshell的 Shell 已经实现了它,测试用的假 Shell 补了实现。5. Store 版 PowerShell 7(Motty 2f73c352)
localshell/discovery_windows.go:新增storePowerShell(),返回%LOCALAPPDATA%\Microsoft\WindowsApps\pwsh.exe和…\WindowsApps\Microsoft.PowerShell_8wekyb3d8bbwe\pwsh.exe。localshell/backend_windows.go:defaultShell()的候选顺序改为pwsh.exe→ Store 别名 →powershell.exe。6. 保留 PowerShell 横幅(Motty 02916ed5)
localshell/integration_windows.go:PowerShell 目录集成不再传-NoLogo。测试
term/terminal_test.go:代数的递增时机,以及RetainedFrom。termview/selection_test.go(新):TestOutputKeepsTheSelectionOnItsText);TestOutputTrimsASelectionTheScrollbackDropped);TestBufferChangesClearASelection);TestASelectionMadeAfterClearSurvivesOutput)。termview/paint_test.go(新):TestRowsKeepTheirTextIdentityAcrossScrolling);TestViewsPaintUnderOwnersOfTheirOwn)。termview/menu_test.go(新):TestClearSendsAFormFeedToPowerShellAtItsPrompt);TestClearSendsNoFormFeedWhereNoLineEditorReadsIt):正在运行程序、cmd、POSIX、未知 Shell、插件终端、备用屏。termview/pluginterm_test.go:假 Shell 记录写入内容,可以设置kind和busy。localshell/shell_windows_test.go:继承了关闭 Ctrl+C 的进程组时,Ctrl+C 仍能中断伪控制台中的程序(TestConPTYCtrlCInterruptsAProgramInAnInheritedCtrlCDisabledGroup)。localshell/discovery_windows_test.go:TestWindowsShellDiscoveryFindsTheStorePowerShellAlias);TestWindowsDefaultShellPrefersTheStorePowerShell)。localshell/integration_windows_test.go:保留横幅(TestPowerShellIntegrationKeepsTheBanner)。其他
termview/NOTICE:记录从 8958a472 之后同步的 6 个 Motty 提交,以及各自的适配说明。terminal-interaction、terminal-shell:补了证据路径、验证说明和备注,两端状态保持pending。不在本 PR 范围内 / Out of scope
pwsh.exe时多查两个绝对路径;问题没有在这里处理。localshell中原有的丢弃错误写法(backend_unix.go:67-84、backend_windows.go:108,176,197-198,237的_ =)没有补豁免标记,本 PR 没有新增此类写法。类型专属:feat
多平台对齐
platform-specific),理由:说明:
pwsh。范围检查 / Scope checks
功能矩阵 / Feature matrix
shared/platform-feature-matrix/features/<id>.json:两端的实现状态和验证状态、证据路径、owner、验证动作都如实填写;没有运行验证的保持pending(terminal-interaction、terminal-shell)./scripts/platform-feature-matrix/verify-platform-feature-matrix.sh;改了平台实现路径的,还运行了./scripts/platform-feature-matrix/verify-platform-feature-matrix-change.sh origin/main HEAD.artifacts/下生成的矩阵视图插件归属 / Plugin ownership
develop-lithe第三节“插件归属与宿主零依赖”的自查命令,结果为空Args的假 Shell)shared/i18n/;插件的构建步骤、资源路径和补丁没有写进scripts/resources/、docs/ci-builds.md、Agent Note 或 SkillUI 验证 / UI evidence
workbench/visual_capture_test.go终端场景(60-terminal等)不覆盖「输出到达后选区仍在」和「PowerShell 清除后重绘」这两个状态,需要新增场景,还需要LITHE_VISUAL_BASELINE_DIR基线目录。标记 ready 前补齐。统一日志系统 / Structured logging
restoreCtrlC)把错误返回给startBackend,由 termview 现有的terminal.session.start_failed(stagespawn)记录。换页符写入被拒绝时,走现有sendInput的记录。Windows 仍使用 v1 日志,沿用现有写法reconcileSelection和绘制路径没有日志)localshell: restoring Ctrl+C: <Windows 错误>scripts/logging/)已移除,等价检查恢复前在“验证”一节写明日志门禁未完成,不记为通过界面文案 / i18n
N/A:没有新增或修改界面文案。两项 i18n 检查照常运行,均通过,见「验证」。
逻辑归属 / Logic placement
develop-lithe第三节的判断表,本 PR 改动的都是平台层可以保留的逻辑:shellkind和 Shell 发现(它们属于宿主能力terminal-shell);PSReadLine 的 Ctrl+L 行为写在了宿主里性能与内存 / Performance and memory
pwsh.exe时多查两个绝对路径。reconcileSelection每次写入的工作量是 O(1),与输出总量无关设置 / Settings
N/A:没有新增或修改设置项。默认 Shell 为「自动」时,解析结果多了 Store 版 PowerShell 7 这个候选;设置页显示的实际生效值来自同一个
localshell.DefaultShell()。插件契约 / Plugin contract
N/A:没有改动插件契约、能力版本、插件函数协议、宿主方法或通知。
发行包与资源 / Bundle and resources
./scripts/desktop/verify/verify-runtime-bundle-immutability.sh通过无用代码与重构 / Dead code and refactoring
refactor标签的 Issue,没有在本 PR 顺手处理:[Feature] 清理或接通终端未接线的 Shell 集成:DirectoryToken、WSLScript、Windows 提示符脚本与 term 提示符/目录回调在生产代码中没有调用方 #1984(Shell 集成未接线)、[Feature] 终端在界面线程上启动 Shell 进程:首次绘制时同步执行 localshell.Start 与默认 Shell 探测,应移到后台 #1988(终端在界面线程启动 Shell)验证 / Verification
以下检查都在 macOS 27.3、Apple Silicon(arm64)上本地运行。
./scripts/desktop/desktop-go.sh test ./... -count=1./scripts/desktop/desktop-go.sh test -race ./internal/term ./internal/termview ./internal/localshell./scripts/desktop/desktop-go.sh test ./internal/shellkind ./internal/workbench.agents/skills/write-stable-tests/scripts/test-stability-macos.sh --package ./internal/termview --package ./internal/term --filter <新增测试>(含verify-test-stability.sh)lineEditorNeedsFormFeed的 5 个条件(busy、kind、Args、cleared、发送本身)menu_test.go中对应的用例失败,复原后通过GOOS=windows GOARCH=arm64和GOARCH=amd64下go vet./internal/localshell ./internal/termview ./internal/termGOOS=windows go test -c(localshell、termview、term)gofmt -l改动文件./scripts/platform-feature-matrix/verify-platform-feature-matrix.sh./scripts/platform-feature-matrix/verify-platform-feature-matrix-change.sh origin/main HEADdevelop-lithe第三节插件归属自查命令node scripts/i18n/verify-app-language-localization.mjs、node scripts/i18n/generate-i18n.mjs --check./scripts/desktop/verify/verify-runtime-bundle-immutability.sh未能执行的检查和原因:
Windows 运行时测试未运行:本机没有可用的 Windows 虚拟机。
TestConPTYCtrlCInterruptsAProgramInAnInheritedCtrlCDisabledGroup、TestWindowsShellDiscoveryFindsTheStorePowerShellAlias、TestWindowsDefaultShellPrefersTheStorePowerShell、TestPowerShellIntegrationKeepsTheBanner只交叉编译过,标记 ready 后由 Windows CI 运行。Windows 原生验收未做:
CREATE_NEW_PROCESS_GROUP方式启动 Lithe 后的 Ctrl+C;功能矩阵中保持
pending。UI 无头截图未完成:见「UI 验证」,标记 ready 前补齐。
性能基线未验证:终端没有等价的基线脚本。
日志门禁未完成:旧日志使用校验脚本已移除,等价检查尚未恢复。
提交前确认 / Final checks
main(4032c5ca)创建;目标分支:main.build/、target/、dist/、.artifacts/等产物,没有凭据、个人路径和未脱敏的日志或截图