wezterm-pi-helper 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -0
- package/package.json +21 -0
- package/src/index.ts +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# wezterm-pi-helper
|
|
2
|
+
|
|
3
|
+
Fixes WezTerm keyboard issues when running [pi](https://github.com/mariozechner/pi) on WSL2.
|
|
4
|
+
|
|
5
|
+
## Problem
|
|
6
|
+
|
|
7
|
+
WezTerm on WSL2 for Windows has a bug where Kitty keyboard protocol flag 4 ("report alternate keys") causes shifted keys (capitals, @, #, $, etc.) to not be sent at all. This makes typing very inpractical.
|
|
8
|
+
|
|
9
|
+
## Solution
|
|
10
|
+
|
|
11
|
+
This extension monkey-patches pi's terminal handling to use Kitty protocol flag 3 instead of 7 when running in WezTerm, avoiding the buggy flag 4.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
cd ~/.pi/agent/extensions
|
|
17
|
+
npm install wezterm-pi-helper
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Or add to your `~/.pi/agent/extensions/package.json`:
|
|
21
|
+
|
|
22
|
+
```json
|
|
23
|
+
{
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"wezterm-pi-helper": "^1.0.0"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Then run `npm install`.
|
|
31
|
+
|
|
32
|
+
## How it works
|
|
33
|
+
|
|
34
|
+
The extension detects WezTerm via the `TERM_PROGRAM` environment variable. When detected, it overrides `ProcessTerminal.prototype.setupStdinBuffer` to use Kitty keyboard protocol flags 1+2 (value 3) instead of 1+2+4 (value 7).
|
|
35
|
+
|
|
36
|
+
- Flag 1: Disambiguate escape codes
|
|
37
|
+
- Flag 2: Report event types (press/repeat/release)
|
|
38
|
+
- Flag 4: Report alternate keys (causes the bug in WezTerm on WSL2)
|
|
39
|
+
|
|
40
|
+
## Why tmux works without this patch
|
|
41
|
+
|
|
42
|
+
If you've noticed pi works fine in tmux on WezTerm, that's because tmux intercepts the Kitty protocol query and handles keyboard input itself, masking the buggy WezTerm behavior.
|
|
43
|
+
|
|
44
|
+
## License
|
|
45
|
+
|
|
46
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "wezterm-pi-helper",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Fixes WezTerm keyboard issues on WSL2",
|
|
5
|
+
"main": "./src/index.ts",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"files": ["src"],
|
|
8
|
+
"keywords": ["pi-extension", "wezterm", "wsl2"],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://git.sr.ht/~manelvf/wezterm-pi-helper"
|
|
13
|
+
},
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"@mariozechner/pi-coding-agent": "*",
|
|
16
|
+
"@mariozechner/pi-tui": "*"
|
|
17
|
+
},
|
|
18
|
+
"pi": {
|
|
19
|
+
"extensions": ["./src/index.ts"]
|
|
20
|
+
}
|
|
21
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
2
|
+
import { ProcessTerminal, StdinBuffer, setKittyProtocolActive } from "@mariozechner/pi-tui";
|
|
3
|
+
|
|
4
|
+
export default function (pi: ExtensionAPI) {
|
|
5
|
+
const isWezTerm = process.env.TERM_PROGRAM === "WezTerm";
|
|
6
|
+
if (!isWezTerm) return;
|
|
7
|
+
|
|
8
|
+
// Monkey-patch setupStdinBuffer to use WezTerm-compatible Kitty flags
|
|
9
|
+
// TypeScript's 'private' is not enforced at runtime
|
|
10
|
+
(ProcessTerminal.prototype as any).setupStdinBuffer = function (this: any): void {
|
|
11
|
+
this.stdinBuffer = new StdinBuffer({ timeout: 10 });
|
|
12
|
+
|
|
13
|
+
const kittyResponsePattern = /^\x1b\[\?(\d+)u$/;
|
|
14
|
+
|
|
15
|
+
this.stdinBuffer.on("data", (sequence: string) => {
|
|
16
|
+
if (!this._kittyProtocolActive) {
|
|
17
|
+
const match = sequence.match(kittyResponsePattern);
|
|
18
|
+
if (match) {
|
|
19
|
+
this._kittyProtocolActive = true;
|
|
20
|
+
setKittyProtocolActive(true);
|
|
21
|
+
|
|
22
|
+
// WezTerm fix: use flag 3 instead of 7
|
|
23
|
+
// Flag 4 causes shifted keys to not be sent in WezTerm on WSL2
|
|
24
|
+
process.stdout.write("\x1b[>3u");
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (this.inputHandler) {
|
|
30
|
+
this.inputHandler(sequence);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
this.stdinBuffer.on("paste", (content: string) => {
|
|
35
|
+
if (this.inputHandler) {
|
|
36
|
+
this.inputHandler(`\x1b[200~${content}\x1b[201~`);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
this.stdinDataHandler = (data: string) => {
|
|
41
|
+
this.stdinBuffer!.process(data);
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
}
|