# pi-mintty-wheel-fix **Repository Path**: shadowedge/pi-mintty-wheel-fix ## Basic Information - **Project Name**: pi-mintty-wheel-fix - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-10-07 - **Last Updated**: 2026-10-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # pi-mintty-wheel-fix Fix mouse wheel scrolling in Pi's fullscreen viewport when using Git Bash / mintty. ## 问题背景 在 Windows 的 Git Bash(mintty)终端下,Pi 的全屏 `Ctrl+O` 翻页视口滚动鼠标滚轮无效,滚轮事件被误识别为光标键/分页键,进而被 Pi 当作提示历史导航而非滚动处理。 **根因**(在 mintty 3.8.3 + Node 24 + Pi 1.0.4 上实测): `TuiAltScreen.beforeTerminalStart()` 会在 `ProcessTerminal.start()` 调用 `process.stdin.setRawMode(true)` 及添加 `ENABLE_VIRTUAL_TERMINAL_INPUT` 之前,写入鼠标 DECSET 控制码 bursts(`\x1b[?1000h ?1002h ?1003h ?1004h ?1006h`)。在 Windows 上,这些写入经过 ConPTY。在 `stdin` 还处于 cooked 模式(未开启 raw mode、未开启 VT input)时,ConPTY 不会将鼠标追踪模式转发给终端,导致 mintty 无法启用鼠标报告。mintty 随即模拟 xterm 的 `alternateScroll` 行为:滚轮被转化为光标键/PgUp-PgDn,Pi 就把它当作编辑器提示历史导航,而非 transcript 滚动。 值得注意的是,写入 bursts 中同样的 `\x1b[?1004h`(focus reporting)**会**被转发,这也就是为什么只有滚轮(1000/1002/1003/1006)会失效,而其它功能正常。 上游议题:https://github.com/earendil-works/pi/issues/9656 (同一 ordering bug,Zellij 侧的修复是把写入调整到 raw mode 开启之后)。 ## 安装 ### 从 Git 仓库安装(推荐) ```bash pi install git:https://gitee.com/shadowedge/pi-mintty-wheel-fix.git ``` 指定分支、标签或 commit: ```bash pi install git:https://gitee.com/shadowedge/pi-mintty-wheel-fix.git@main ``` ### 从本地目录安装 ```bash cd /path/to/pi-mintty-wheel-fix pi install ./ ``` ### 临时试用一次 ```bash pi -e git:https://gitee.com/shadowedge/pi-mintty-wheel-fix.git ``` > 安装后无需任何配置:扩展在 `process.platform === "win32"` 且环境变量 `PI_WHEEL_FIX` 不为 `"0"` 时自动生效。 ### 卸载 ```bash pi remove git:https://gitee.com/shadowedge/pi-mintty-wheel-fix.git ``` ## 使用 扩展注册了一个 `/wheelFix` 命令。打开 Pi 的 TUI 全屏视口(`Ctrl+O`),在命令面板中输入 `/wheelFix`: ``` /wheelFix # 显示当前状态与诊断信息 /wheelFix force # 强制重新启用鼠标报告(burst 已幂等,重放安全) /wheelFix on # 开启修复 /wheelFix off # 关闭修制并关闭鼠标报告 /wheelFix reset # 清零计数器 ``` ## 工作原理 该扩展不修改 Pi 源码,因此可在 `pi` 升级后生存。它: 1. 拦截 `stdout.write`,记录 Pi 在 `setRawMode` 生效之前写入的鼠标 DECSET bursts; 2. 在 `stdin.setRawMode(true)` 完成后(`setTimeout 10ms`,确保 `ENABLE_VIRTUAL_TERMINAL_INPUT` 同步开启),将记录的 bursts 重新写入; 3. DECSET `h` 是幂等的,重放部分生效的 bursts 是安全的。 ## 配置 - `PI_WHEEL_FIX=0` — 禁用自动安装(仍可通过 `/wheelFix on` / `/wheelFix force` 手动启用)。