@yukikisaku/pi-show-command-list-above 0.1.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/LICENSE +21 -0
- package/README.md +35 -0
- package/index.ts +94 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 yuki-kisaku
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# pi-show-command-list-above
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Render Pi's slash-command autocomplete list above the editor.
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
Requires a Pi version whose `CustomEditor` internals match this package. It patches editor rendering for the active process and restores the original renderer on session shutdown.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
pi install npm:@yukikisaku/pi-show-command-list-above
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Start Pi normally. Slash-command autocomplete is moved above the editor; if compatible internals cannot be read, Pi keeps its standard layout.
|
|
20
|
+
|
|
21
|
+
## Configuration
|
|
22
|
+
|
|
23
|
+
No configuration.
|
|
24
|
+
|
|
25
|
+
## Uninstallation
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
pi uninstall npm:@yukikisaku/pi-show-command-list-above
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Remove any package-specific configuration described above if you no longer need it.
|
|
32
|
+
|
|
33
|
+
## License
|
|
34
|
+
|
|
35
|
+
MIT © yuki-kisaku. See [LICENSE](LICENSE).
|
package/index.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { CustomEditor, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
const PATCH_KEY = Symbol.for("pi-extension.command-list-above.patch");
|
|
4
|
+
|
|
5
|
+
type RenderFn = (this: CustomEditor, width: number) => string[];
|
|
6
|
+
|
|
7
|
+
type PatchState = {
|
|
8
|
+
originalRender: RenderFn;
|
|
9
|
+
patchedRender: RenderFn;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type AutocompleteListLike = {
|
|
13
|
+
render(width: number): string[];
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type EditorInternals = {
|
|
17
|
+
autocompleteState?: unknown;
|
|
18
|
+
autocompleteList?: AutocompleteListLike;
|
|
19
|
+
paddingX?: number;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type PatchablePrototype = {
|
|
23
|
+
render: RenderFn;
|
|
24
|
+
} & Record<PropertyKey, unknown>;
|
|
25
|
+
|
|
26
|
+
function getPatchState(proto: PatchablePrototype): PatchState | undefined {
|
|
27
|
+
return proto[PATCH_KEY] as PatchState | undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function getEditorContentWidth(editor: CustomEditor, width: number): number {
|
|
31
|
+
const internals = editor as unknown as EditorInternals;
|
|
32
|
+
const rawPadding = typeof internals.paddingX === "number" && Number.isFinite(internals.paddingX)
|
|
33
|
+
? Math.max(0, Math.floor(internals.paddingX))
|
|
34
|
+
: 0;
|
|
35
|
+
const maxPadding = Math.max(0, Math.floor((width - 1) / 2));
|
|
36
|
+
const paddingX = Math.min(rawPadding, maxPadding);
|
|
37
|
+
return Math.max(1, width - paddingX * 2);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getAutocompleteLineCount(editor: CustomEditor, width: number): number {
|
|
41
|
+
const internals = editor as unknown as EditorInternals;
|
|
42
|
+
if (!internals.autocompleteState || !internals.autocompleteList) return 0;
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
return internals.autocompleteList.render(getEditorContentWidth(editor, width)).length;
|
|
46
|
+
} catch {
|
|
47
|
+
// pi内部の実装が変わった場合は、表示を壊さず標準位置のままにする。
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function moveCommandListAbove(editor: CustomEditor, renderedLines: string[], width: number): string[] {
|
|
53
|
+
const autocompleteLineCount = getAutocompleteLineCount(editor, width);
|
|
54
|
+
if (autocompleteLineCount <= 0 || autocompleteLineCount >= renderedLines.length) {
|
|
55
|
+
return renderedLines;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const autocompleteStart = renderedLines.length - autocompleteLineCount;
|
|
59
|
+
const editorLines = renderedLines.slice(0, autocompleteStart);
|
|
60
|
+
const autocompleteLines = renderedLines.slice(autocompleteStart);
|
|
61
|
+
return [...autocompleteLines, ...editorLines];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function installCommandListAbovePatch(): void {
|
|
65
|
+
const proto = CustomEditor.prototype as unknown as PatchablePrototype;
|
|
66
|
+
if (getPatchState(proto)) return;
|
|
67
|
+
|
|
68
|
+
const originalRender = proto.render;
|
|
69
|
+
const patchedRender: RenderFn = function renderCommandListAbove(this: CustomEditor, width: number): string[] {
|
|
70
|
+
return moveCommandListAbove(this, originalRender.call(this, width), width);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
proto.render = patchedRender;
|
|
74
|
+
proto[PATCH_KEY] = { originalRender, patchedRender } satisfies PatchState;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function uninstallCommandListAbovePatch(): void {
|
|
78
|
+
const proto = CustomEditor.prototype as unknown as PatchablePrototype;
|
|
79
|
+
const state = getPatchState(proto);
|
|
80
|
+
if (!state) return;
|
|
81
|
+
|
|
82
|
+
if (proto.render === state.patchedRender) {
|
|
83
|
+
proto.render = state.originalRender;
|
|
84
|
+
}
|
|
85
|
+
delete proto[PATCH_KEY];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export default function commandListAboveExtension(pi: ExtensionAPI): void {
|
|
89
|
+
installCommandListAbovePatch();
|
|
90
|
+
|
|
91
|
+
pi.on("session_shutdown", async () => {
|
|
92
|
+
uninstallCommandListAbovePatch();
|
|
93
|
+
});
|
|
94
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yukikisaku/pi-show-command-list-above",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Render Pi's slash-command autocomplete list above the editor.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "yuki-kisaku",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/yukikisaku/pi-show-command-list-above.git"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/yukikisaku/pi-show-command-list-above#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/yukikisaku/pi-show-command-list-above/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"pi-package",
|
|
18
|
+
"pi-extension"
|
|
19
|
+
],
|
|
20
|
+
"files": [
|
|
21
|
+
"index.ts"
|
|
22
|
+
],
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=20"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@earendil-works/pi-coding-agent": "*"
|
|
31
|
+
},
|
|
32
|
+
"pi": {
|
|
33
|
+
"extensions": [
|
|
34
|
+
"./index.ts"
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
}
|