@xynogen/pix-pretty 1.34.0 → 1.34.1
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/package.json +1 -1
- package/src/index.ts +12 -0
- package/src/ordered-widgets.ts +90 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -9,13 +9,25 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
12
|
+
import { once } from "@xynogen/pix-runtime/once";
|
|
12
13
|
import { registerFffCommands } from "./commands/fff.ts";
|
|
13
14
|
import { fffState } from "./fff.ts";
|
|
14
15
|
import { clearHighlightCache } from "./highlight.ts";
|
|
15
16
|
import { initIconMode } from "./icon-persist.ts";
|
|
17
|
+
import { installOrderedWidgets } from "./ordered-widgets.ts";
|
|
16
18
|
import type { PiPrettyApi } from "./types.ts";
|
|
17
19
|
|
|
18
20
|
export default function piPrettyExtension(pi: ExtensionAPI): void {
|
|
21
|
+
once(pi, "pix-pretty-widgets", () => {
|
|
22
|
+
let restore: (() => void) | undefined;
|
|
23
|
+
pi.on("session_start", (_event, ctx) => {
|
|
24
|
+
if (ctx.mode === "tui") restore = installOrderedWidgets(ctx.ui);
|
|
25
|
+
});
|
|
26
|
+
pi.on("session_shutdown", () => {
|
|
27
|
+
restore?.();
|
|
28
|
+
restore = undefined;
|
|
29
|
+
});
|
|
30
|
+
});
|
|
19
31
|
const prettyPi = pi as unknown as PiPrettyApi;
|
|
20
32
|
clearHighlightCache();
|
|
21
33
|
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { ExtensionUIContext, Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { type Component, Container, Text, type TUI } from "@earendil-works/pi-tui";
|
|
3
|
+
|
|
4
|
+
type Widget = Component & { dispose?(): void };
|
|
5
|
+
type Content = string[] | ((tui: TUI, theme: Theme) => Widget) | undefined;
|
|
6
|
+
type Options = { placement?: "aboveEditor" | "belowEditor" };
|
|
7
|
+
|
|
8
|
+
const ORDER = [
|
|
9
|
+
"pix-transient-error",
|
|
10
|
+
"welcome",
|
|
11
|
+
"pi-lens-lsp",
|
|
12
|
+
"pix-proc:procs",
|
|
13
|
+
"pix-aria2:progress",
|
|
14
|
+
"agents",
|
|
15
|
+
"pix-btw-live",
|
|
16
|
+
"voice-stt",
|
|
17
|
+
];
|
|
18
|
+
const GROUP = "pix-ordered-widgets";
|
|
19
|
+
|
|
20
|
+
/** Keep Pix widgets in one host slot; Pi moves individually updated slots to the end. */
|
|
21
|
+
export function installOrderedWidgets(ui: Pick<ExtensionUIContext, "setWidget">): () => void {
|
|
22
|
+
const original = ui.setWidget as (key: string, content: Content, options?: Options) => void;
|
|
23
|
+
const below = new Set<string>();
|
|
24
|
+
const widgets = new Map<string, Widget>();
|
|
25
|
+
let environment: { tui: TUI; theme: Theme } | undefined;
|
|
26
|
+
|
|
27
|
+
const clear = () => {
|
|
28
|
+
const children = [...widgets.values()];
|
|
29
|
+
widgets.clear();
|
|
30
|
+
environment = undefined;
|
|
31
|
+
for (const child of children) child.dispose?.();
|
|
32
|
+
};
|
|
33
|
+
const setWidget = (key: string, content: Content, options?: Options) => {
|
|
34
|
+
if (!ORDER.includes(key)) {
|
|
35
|
+
original.call(ui, key, content, options);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const previous = widgets.get(key);
|
|
39
|
+
widgets.delete(key);
|
|
40
|
+
previous?.dispose?.();
|
|
41
|
+
if (below.delete(key)) original.call(ui, key, undefined);
|
|
42
|
+
|
|
43
|
+
if (content !== undefined && options?.placement !== "belowEditor") {
|
|
44
|
+
if (!environment) {
|
|
45
|
+
original.call(
|
|
46
|
+
ui,
|
|
47
|
+
GROUP,
|
|
48
|
+
(tui: TUI, theme: Theme) => {
|
|
49
|
+
environment = { tui, theme };
|
|
50
|
+
return {
|
|
51
|
+
render: (width: number) =>
|
|
52
|
+
ORDER.flatMap((name) => widgets.get(name)?.render(width) ?? []),
|
|
53
|
+
invalidate: () => {
|
|
54
|
+
for (const widget of widgets.values()) widget.invalidate();
|
|
55
|
+
},
|
|
56
|
+
dispose: clear,
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
{ placement: "aboveEditor" },
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
if (environment) {
|
|
63
|
+
let widget: Widget;
|
|
64
|
+
if (Array.isArray(content)) {
|
|
65
|
+
const container = new Container();
|
|
66
|
+
for (const line of content.slice(0, 10)) container.addChild(new Text(line, 1, 0));
|
|
67
|
+
if (content.length > 10) {
|
|
68
|
+
container.addChild(
|
|
69
|
+
new Text(environment.theme.fg("muted", "... (widget truncated)"), 1, 0),
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
widget = container;
|
|
73
|
+
} else {
|
|
74
|
+
widget = content(environment.tui, environment.theme);
|
|
75
|
+
}
|
|
76
|
+
widgets.set(key, widget);
|
|
77
|
+
}
|
|
78
|
+
} else if (options?.placement === "belowEditor") {
|
|
79
|
+
original.call(ui, key, content, options);
|
|
80
|
+
if (content !== undefined) below.add(key);
|
|
81
|
+
}
|
|
82
|
+
if (widgets.size === 0 && environment) original.call(ui, GROUP, undefined);
|
|
83
|
+
environment?.tui.requestRender();
|
|
84
|
+
};
|
|
85
|
+
ui.setWidget = setWidget;
|
|
86
|
+
return () => {
|
|
87
|
+
if (ui.setWidget === setWidget) ui.setWidget = original;
|
|
88
|
+
if (environment) original.call(ui, GROUP, undefined);
|
|
89
|
+
};
|
|
90
|
+
}
|