pi-odd-worktree 3.15.1 → 3.16.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 +48 -25
- package/extensions/odd-worktree-tools.ts +64 -211
- package/lib/shell-api/api.ts +523 -0
- package/lib/shell-api/arm.ts +83 -0
- package/lib/shell-api/bus.ts +1389 -0
- package/lib/shell-api/capture.ts +1340 -0
- package/lib/shell-api/card-style-line.ts +112 -0
- package/lib/shell-api/card-style-rows.ts +390 -0
- package/lib/shell-api/card-style-transform.ts +862 -0
- package/lib/shell-api/card-style-wiring.ts +477 -0
- package/lib/shell-api/card-styles.ts +153 -0
- package/lib/shell-api/config.ts +71 -0
- package/lib/shell-api/extension.ts +247 -0
- package/lib/shell-api/hook.ts +322 -0
- package/lib/shell-api/index.ts +88 -0
- package/lib/shell-api/message-design-adoption.ts +549 -0
- package/lib/shell-api/message-design-rows.ts +313 -0
- package/lib/shell-api/message-design-wiring.ts +369 -0
- package/lib/shell-api/message-designs.ts +746 -0
- package/lib/shell-api/notices.ts +137 -0
- package/lib/shell-api/plugin-lines.ts +877 -0
- package/lib/shell-api/presence.ts +258 -0
- package/lib/shell-api/repaint.ts +351 -0
- package/lib/shell-api/row-labels.ts +146 -0
- package/lib/shell-api/row-names.ts +273 -0
- package/lib/shell-api/row-origin.ts +144 -0
- package/lib/shell-api/rows.ts +591 -0
- package/lib/shell-api/section-panel.ts +378 -0
- package/lib/shell-api/section-pointer.ts +164 -0
- package/lib/shell-api/sections-preview.ts +275 -0
- package/lib/shell-api/sections-rows.ts +133 -0
- package/lib/shell-api/sidebar-render.ts +705 -0
- package/lib/shell-api/sidebar.ts +1126 -0
- package/lib/shell-api/store.ts +279 -0
- package/lib/shell-api/tool-design-adoption.ts +263 -0
- package/lib/shell-api/tool-design-rows.ts +307 -0
- package/lib/shell-api/tool-design-wiring.ts +481 -0
- package/lib/shell-api/tool-designs.ts +1411 -0
- package/lib/shell-api/transform-pipeline.ts +351 -0
- package/lib/shell-api/types.ts +803 -0
- package/lib/shell-api/visibility.ts +154 -0
- package/package.json +3 -2
- package/tools/files-bridge.test.js +81 -66
- package/tools/fixtures/load-extension.js +40 -18
- package/tools/issues-command.test.js +4 -7
- package/tools/issues-section.test.js +71 -81
- package/tools/odd-rail-wiring.test.js +16 -10
- package/tools/package-surface.test.js +42 -13
- package/tools/prs-command.test.js +11 -6
- package/tools/shell-api/api.test.ts +484 -0
- package/tools/shell-api/apply-on-move.test.ts +529 -0
- package/tools/shell-api/arm.test.ts +220 -0
- package/tools/shell-api/bridge-ready.test.ts +309 -0
- package/tools/shell-api/bus.test.ts +194 -0
- package/tools/shell-api/button-rows.test.ts +435 -0
- package/tools/shell-api/capture.test.ts +583 -0
- package/tools/shell-api/card-style-rows.test.ts +493 -0
- package/tools/shell-api/card-style-transform.test.ts +379 -0
- package/tools/shell-api/card-style-wiring.test.ts +258 -0
- package/tools/shell-api/card-styles-e2e.test.ts +502 -0
- package/tools/shell-api/card-styles.test.ts +324 -0
- package/tools/shell-api/card-transcript-path.test.ts +178 -0
- package/tools/shell-api/compatibility-regression.test.mjs +64 -0
- package/tools/shell-api/config.test.ts +93 -0
- package/tools/shell-api/docs-coverage.test.ts +82 -0
- package/tools/shell-api/e2e.test.ts +562 -0
- package/tools/shell-api/example-bash-identity.test.ts +372 -0
- package/tools/shell-api/example-bash-matrix.test.ts +856 -0
- package/tools/shell-api/example-designs.test.ts +737 -0
- package/tools/shell-api/example-neon-transform.test.ts +283 -0
- package/tools/shell-api/example-plain-style.test.ts +1225 -0
- package/tools/shell-api/extension.test.ts +157 -0
- package/tools/shell-api/fake-events.ts +58 -0
- package/tools/shell-api/fake-host.ts +211 -0
- package/tools/shell-api/fake-sidebar.ts +516 -0
- package/tools/shell-api/fake-transcript.ts +486 -0
- package/tools/shell-api/frame-telemetry.test.ts +317 -0
- package/tools/shell-api/hook.test.ts +196 -0
- package/tools/shell-api/manifest.test.ts +47 -0
- package/tools/shell-api/message-design-adoption.test.ts +611 -0
- package/tools/shell-api/message-design-follows.test.ts +361 -0
- package/tools/shell-api/message-design-pi-release.test.mjs +157 -0
- package/tools/shell-api/message-design-regressions.test.mjs +162 -0
- package/tools/shell-api/message-design-rows.test.ts +266 -0
- package/tools/shell-api/message-design-wiring.test.ts +362 -0
- package/tools/shell-api/message-designs.test.ts +339 -0
- package/tools/shell-api/new-category.test.ts +1101 -0
- package/tools/shell-api/notices.test.ts +292 -0
- package/tools/shell-api/plugin-integration-lines.test.ts +827 -0
- package/tools/shell-api/presence.test.ts +396 -0
- package/tools/shell-api/rail-part-hits.test.ts +281 -0
- package/tools/shell-api/rail-surfaces.test.ts +402 -0
- package/tools/shell-api/rail-width.test.ts +406 -0
- package/tools/shell-api/regression.test.ts +434 -0
- package/tools/shell-api/repaint-api.test.ts +200 -0
- package/tools/shell-api/reserved-categories.test.ts +250 -0
- package/tools/shell-api/row-labels.test.ts +261 -0
- package/tools/shell-api/row-names.test.ts +407 -0
- package/tools/shell-api/row-origin.test.ts +395 -0
- package/tools/shell-api/row-placement-regression.test.ts +797 -0
- package/tools/shell-api/row-placement.test.ts +410 -0
- package/tools/shell-api/section-interaction.test.ts +364 -0
- package/tools/shell-api/section-panel.test.ts +430 -0
- package/tools/shell-api/section-placement-rail.test.ts +390 -0
- package/tools/shell-api/section-placement.test.ts +386 -0
- package/tools/shell-api/sections-preview.test.ts +312 -0
- package/tools/shell-api/sections-rows.test.ts +293 -0
- package/tools/shell-api/sidebar-backend.test.ts +477 -0
- package/tools/shell-api/sidebar-e2e.test.ts +317 -0
- package/tools/shell-api/sidebar-hover.test.ts +276 -0
- package/tools/shell-api/sidebar-independent.test.ts +291 -0
- package/tools/shell-api/sidebar-render.test.ts +281 -0
- package/tools/shell-api/sidebar-sections.test.ts +247 -0
- package/tools/shell-api/store.test.ts +192 -0
- package/tools/shell-api/surface-repaint-cost.test.ts +520 -0
- package/tools/shell-api/tool-design-card-style.test.ts +308 -0
- package/tools/shell-api/tool-design-chain.test.ts +471 -0
- package/tools/shell-api/tool-design-cost.test.ts +591 -0
- package/tools/shell-api/tool-design-rows.test.ts +627 -0
- package/tools/shell-api/tool-design-scopes-audit.test.ts +212 -0
- package/tools/shell-api/tool-designs.test.ts +2412 -0
- package/tools/shell-api/transform-pipeline.test.ts +376 -0
- package/tools/shell-api/transforms-bus.test.ts +233 -0
- package/tools/shell-api/verifier-width-regressions.test.ts +147 -0
- package/tools/shell-api-rpc.test.js +189 -0
- package/tools/user-prompt-card.test.js +8 -9
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The section's row model and its drawing (N10, N11): a section body is no longer bare text.
|
|
3
|
+
*
|
|
4
|
+
* Two things are proven here, and they are different claims:
|
|
5
|
+
*
|
|
6
|
+
* 1. **A plain string row is byte-identical.** The bytes the plugin wrote are the bytes the rail
|
|
7
|
+
* frames — no padding, no indent, no ANSI — so no existing plugin changes appearance (N10).
|
|
8
|
+
* 2. **The fallback drawing is the host's drawing.** `renderPanelHeader` / `renderPanelRow` /
|
|
9
|
+
* `paintHoverable` / `clipPanelText` / `fitPanelLine` live in gentle-shell's
|
|
10
|
+
* `lib/shell-panel.ts` and `lib/shell-hover.ts`, which this package cannot import (Pi loads each
|
|
11
|
+
* extension in its own jiti module graph). The reference implementations at the bottom of this
|
|
12
|
+
* file are transcribed from those sources, and every case below compares our output to theirs
|
|
13
|
+
* byte for byte — that is what "byte-identical fallback" means, and it is a stronger claim than
|
|
14
|
+
* "looks similar".
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import assert from "node:assert/strict";
|
|
18
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
19
|
+
import { tmpdir } from "node:os";
|
|
20
|
+
import { join } from "node:path";
|
|
21
|
+
import test from "node:test";
|
|
22
|
+
|
|
23
|
+
import { registerSection, resetBusForTests, resetSectionsForTests } from "../../lib/shell-api/bus.ts";
|
|
24
|
+
import {
|
|
25
|
+
getPanelReport,
|
|
26
|
+
resetSectionPanelForTests,
|
|
27
|
+
setSectionTheme,
|
|
28
|
+
} from "../../lib/shell-api/section-panel.ts";
|
|
29
|
+
import {
|
|
30
|
+
SIDEBAR_RAIL_KEY,
|
|
31
|
+
disableSidebarBackend,
|
|
32
|
+
installSidebarBackend,
|
|
33
|
+
resetSidebarStateForTests,
|
|
34
|
+
} from "../../lib/shell-api/sidebar.ts";
|
|
35
|
+
import {
|
|
36
|
+
getSectionFailures,
|
|
37
|
+
installSectionRail,
|
|
38
|
+
resetSectionFailuresForTests,
|
|
39
|
+
} from "../../lib/shell-api/sidebar-render.ts";
|
|
40
|
+
import { resetStoreStateForTests } from "../../lib/shell-api/store.ts";
|
|
41
|
+
import type { SectionRow, SidebarSection } from "../../lib/shell-api/types.ts";
|
|
42
|
+
import {
|
|
43
|
+
cardBody,
|
|
44
|
+
cardTitles,
|
|
45
|
+
fakeState,
|
|
46
|
+
fakeTui,
|
|
47
|
+
registerNativeFooter,
|
|
48
|
+
renderSidebar,
|
|
49
|
+
resetSidebar,
|
|
50
|
+
} from "./fake-sidebar.ts";
|
|
51
|
+
|
|
52
|
+
let configHome: string;
|
|
53
|
+
let previousConfigHome: string | undefined;
|
|
54
|
+
|
|
55
|
+
test.before(() => {
|
|
56
|
+
configHome = mkdtempSync(join(tmpdir(), "gsb-panel-"));
|
|
57
|
+
previousConfigHome = process.env.GENTLE_PI_CONFIG_HOME;
|
|
58
|
+
process.env.GENTLE_PI_CONFIG_HOME = configHome;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test.after(() => {
|
|
62
|
+
if (previousConfigHome === undefined) delete process.env.GENTLE_PI_CONFIG_HOME;
|
|
63
|
+
else process.env.GENTLE_PI_CONFIG_HOME = previousConfigHome;
|
|
64
|
+
rmSync(configHome, { recursive: true, force: true });
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test.beforeEach(() => {
|
|
68
|
+
rmSync(join(configHome, "gentle-shell-bridge"), { recursive: true, force: true });
|
|
69
|
+
resetBusForTests();
|
|
70
|
+
resetSectionsForTests();
|
|
71
|
+
resetSidebar();
|
|
72
|
+
resetSidebarStateForTests();
|
|
73
|
+
resetSectionFailuresForTests();
|
|
74
|
+
resetStoreStateForTests();
|
|
75
|
+
resetSectionPanelForTests();
|
|
76
|
+
disableSidebarBackend();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const section = (id: string, extra: Partial<SidebarSection> = {}): SidebarSection => ({
|
|
80
|
+
id,
|
|
81
|
+
title: id.toUpperCase(),
|
|
82
|
+
lines: () => [`body ${id}`],
|
|
83
|
+
...extra,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
/** Native host first, then the bridge's interception and the section renderer. */
|
|
87
|
+
function arm(): void {
|
|
88
|
+
registerNativeFooter();
|
|
89
|
+
installSidebarBackend(() => fakeTui());
|
|
90
|
+
installSectionRail();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const rail = () => fakeState().parts.get(SIDEBAR_RAIL_KEY);
|
|
94
|
+
/** The rows the bridge contributes for one frame, native rows excluded. */
|
|
95
|
+
const contributed = (width = 40): string[] => (rail()?.render(width) ?? []).slice(3);
|
|
96
|
+
|
|
97
|
+
test("a plain string row reaches the rail byte for byte, even with a theme in force", () => {
|
|
98
|
+
const theme = fakeTheme();
|
|
99
|
+
setSectionTheme(theme);
|
|
100
|
+
const written = "track Blue in Green";
|
|
101
|
+
registerSection(section("music", { title: "MUSIC", lines: () => [written] }));
|
|
102
|
+
arm();
|
|
103
|
+
|
|
104
|
+
assert.deepEqual(contributed(), [
|
|
105
|
+
referenceHeader(theme, 40, { title: "MUSIC", open: true }),
|
|
106
|
+
written,
|
|
107
|
+
]);
|
|
108
|
+
assert.ok(
|
|
109
|
+
!contributed()[1].includes("\u001b"),
|
|
110
|
+
"a string row carries no styling the plugin did not write",
|
|
111
|
+
);
|
|
112
|
+
assert.deepEqual(cardBody("MUSIC"), [written]);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("a structured row renders glyph, label and meta in the host's roles", () => {
|
|
116
|
+
const theme = fakeTheme();
|
|
117
|
+
setSectionTheme(theme);
|
|
118
|
+
const row: SectionRow = {
|
|
119
|
+
glyph: "♪",
|
|
120
|
+
label: "Blue in Green",
|
|
121
|
+
meta: "5:37",
|
|
122
|
+
tone: "accent",
|
|
123
|
+
};
|
|
124
|
+
registerSection(section("music", { title: "MUSIC", lines: () => [row] }));
|
|
125
|
+
arm();
|
|
126
|
+
|
|
127
|
+
const [header, body] = contributed();
|
|
128
|
+
assert.deepEqual(theme.calls, [
|
|
129
|
+
["muted", "▾"],
|
|
130
|
+
// The host paints the uppercased title through `theme.bold` first
|
|
131
|
+
// (`lib/shell-panel.ts:71-72`), then the role.
|
|
132
|
+
["text", "\u001b[1mMUSIC\u001b[22m"],
|
|
133
|
+
["accent", "♪"],
|
|
134
|
+
["accent", "Blue in Green"],
|
|
135
|
+
["muted", "5:37"],
|
|
136
|
+
]);
|
|
137
|
+
assert.equal(body, referenceRow(40, `${theme.fg("accent", "♪")} ${theme.fg("accent", "Blue in Green")}`, theme.fg("muted", "5:37")));
|
|
138
|
+
assert.equal(header, referenceHeader(theme, 40, { title: "MUSIC", open: true }));
|
|
139
|
+
|
|
140
|
+
// The host's own composition: the row is indented under the header and its secondary text is
|
|
141
|
+
// dimmer than its label, which is the field the report said was missing.
|
|
142
|
+
const plain = stripSgr(body);
|
|
143
|
+
assert.ok(plain.startsWith(" ♪ Blue in Green"), `row is indented: ${JSON.stringify(plain)}`);
|
|
144
|
+
assert.ok(plain.endsWith("5:37"), `meta is right-aligned: ${JSON.stringify(plain)}`);
|
|
145
|
+
assert.equal(plain.length, 40, "the host's fitPanelLine pads the row to the width");
|
|
146
|
+
assert.notEqual(
|
|
147
|
+
roleOf(body, "5:37"),
|
|
148
|
+
roleOf(body, "Blue in Green"),
|
|
149
|
+
"the meta is painted in a different role than the label",
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("a host that publishes its own builders is used, and reported as the source", () => {
|
|
154
|
+
setSectionTheme(fakeTheme());
|
|
155
|
+
registerSection(section("music"));
|
|
156
|
+
// The rail part is one of the objects this package is handed (`sidebar.ts` looks for the
|
|
157
|
+
// builders on it), so publishing them here is how a host that HAS `lib/shell-panel.ts` in its
|
|
158
|
+
// own module graph reaches this drawing.
|
|
159
|
+
const railPart = registerNativeFooter() as unknown as Record<string, unknown>;
|
|
160
|
+
railPart.renderPanelHeader = (_theme: unknown, _width: number, header: { title: string }) =>
|
|
161
|
+
`HOST HEADER ${header.title.toUpperCase()}`;
|
|
162
|
+
railPart.renderPanelRow = (_width: number, left: string) => `HOST ROW ${left}`;
|
|
163
|
+
installSidebarBackend(() => fakeTui());
|
|
164
|
+
installSectionRail();
|
|
165
|
+
|
|
166
|
+
assert.deepEqual(contributed(), [
|
|
167
|
+
"HOST HEADER MUSIC",
|
|
168
|
+
// A plain string row stays the bytes the author wrote, even when the host draws structured rows.
|
|
169
|
+
"body music",
|
|
170
|
+
]);
|
|
171
|
+
const report = getPanelReport();
|
|
172
|
+
assert.equal(report.source, "host", "the report names the drawing that was used");
|
|
173
|
+
assert.deepEqual(report.missing, [], "and nothing is reported missing");
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("the fallback drawing equals the host's builders in every case we can compare", () => {
|
|
177
|
+
const theme = fakeTheme();
|
|
178
|
+
setSectionTheme(theme);
|
|
179
|
+
registerSection(
|
|
180
|
+
section("wide", {
|
|
181
|
+
title: "Wide Section",
|
|
182
|
+
meta: () => "2/6",
|
|
183
|
+
lines: () => [
|
|
184
|
+
{ glyph: "▸", label: "a plain row", meta: "1" },
|
|
185
|
+
{ label: "no glyph, no meta" },
|
|
186
|
+
{ glyph: "✗", label: "failed", meta: "3", tone: "error" },
|
|
187
|
+
{ label: "a row whose text is long enough that the host has to clip it", meta: "99" },
|
|
188
|
+
],
|
|
189
|
+
}),
|
|
190
|
+
);
|
|
191
|
+
arm();
|
|
192
|
+
|
|
193
|
+
const width = 40;
|
|
194
|
+
const rows = contributed(width);
|
|
195
|
+
assert.equal(
|
|
196
|
+
rows[0],
|
|
197
|
+
referenceHeader(theme, width, { title: "Wide Section", count: "2/6", open: true }),
|
|
198
|
+
);
|
|
199
|
+
const cases: Array<[SectionRow, string]> = [
|
|
200
|
+
[{ glyph: "▸", label: "a plain row", meta: "1" }, referenceRow(width, `${theme.fg("muted", "▸")} ${theme.fg("text", "a plain row")}`, theme.fg("muted", "1"))],
|
|
201
|
+
[{ label: "no glyph, no meta" }, referenceRow(width, theme.fg("text", "no glyph, no meta"))],
|
|
202
|
+
[
|
|
203
|
+
{ glyph: "✗", label: "failed", meta: "3", tone: "error" },
|
|
204
|
+
referenceRow(width, `${theme.fg("error", "✗")} ${theme.fg("error", "failed")}`, theme.fg("muted", "3")),
|
|
205
|
+
],
|
|
206
|
+
[
|
|
207
|
+
{ label: "a row whose text is long enough that the host has to clip it", meta: "99" },
|
|
208
|
+
referenceRow(
|
|
209
|
+
width,
|
|
210
|
+
theme.fg("text", "a row whose text is long enough that the host has to clip it"),
|
|
211
|
+
theme.fg("muted", "99"),
|
|
212
|
+
),
|
|
213
|
+
],
|
|
214
|
+
];
|
|
215
|
+
cases.forEach(([row, expected], index) => {
|
|
216
|
+
assert.equal(
|
|
217
|
+
rows[index + 1],
|
|
218
|
+
expected,
|
|
219
|
+
`row ${JSON.stringify(row.label)} matches the host's renderPanelRow`,
|
|
220
|
+
);
|
|
221
|
+
});
|
|
222
|
+
assert.ok(
|
|
223
|
+
stripSgr(rows[4]).includes("…"),
|
|
224
|
+
"a row that cannot fit is clipped with the host's ellipsis, not silently cut",
|
|
225
|
+
);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test("a hovered row paints with the host's hover role, and only for a row that acts", () => {
|
|
229
|
+
const theme = fakeTheme();
|
|
230
|
+
setSectionTheme(theme);
|
|
231
|
+
const calls: string[] = [];
|
|
232
|
+
registerSection(
|
|
233
|
+
section("music", {
|
|
234
|
+
title: "MUSIC",
|
|
235
|
+
lines: () => [
|
|
236
|
+
{ label: "play", meta: "enter", onClick: () => calls.push("play") },
|
|
237
|
+
{ label: "inert" },
|
|
238
|
+
],
|
|
239
|
+
}),
|
|
240
|
+
);
|
|
241
|
+
arm();
|
|
242
|
+
contributed(40);
|
|
243
|
+
theme.calls.length = 0;
|
|
244
|
+
|
|
245
|
+
assert.deepEqual(
|
|
246
|
+
rail()?.handleMouse?.({ type: "move", button: "none", x: 4, y: 4, width: 40, height: 20 }),
|
|
247
|
+
{ handled: true, render: true },
|
|
248
|
+
"the clickable row answers a hover",
|
|
249
|
+
);
|
|
250
|
+
contributed(40);
|
|
251
|
+
|
|
252
|
+
const hoveredRow = contributed(40)[1];
|
|
253
|
+
assert.equal(roleOf(hoveredRow, "play"), "warning", "the label takes the host's hover role");
|
|
254
|
+
assert.equal(
|
|
255
|
+
hoveredRow,
|
|
256
|
+
referenceRow(40, `${paintHoverable(theme, undefined, "play", true, "text")}`, paintHoverable(theme, undefined, "enter", true, "muted")),
|
|
257
|
+
"and it is drawn exactly as the host draws a hovered panel row",
|
|
258
|
+
);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test("a row whose tone is not one of the host's roles is rejected, never coerced", () => {
|
|
262
|
+
registerSection(
|
|
263
|
+
section("bad", {
|
|
264
|
+
title: "BAD",
|
|
265
|
+
lines: () => [{ label: "row", tone: "hotpink" as unknown as "text" }],
|
|
266
|
+
}),
|
|
267
|
+
);
|
|
268
|
+
arm();
|
|
269
|
+
|
|
270
|
+
assert.deepEqual(cardTitles(), ["FOOTER", "BAD"]);
|
|
271
|
+
assert.deepEqual(cardBody("BAD"), [], "the body is dropped");
|
|
272
|
+
const failure = getSectionFailures().find((entry) => entry.sectionId === "bad");
|
|
273
|
+
assert.equal(failure?.phase, "lines");
|
|
274
|
+
assert.match(failure?.message ?? "", /tone/u);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
test("a row with no usable label is rejected, never coerced", () => {
|
|
278
|
+
registerSection(
|
|
279
|
+
section("nob", {
|
|
280
|
+
title: "NOB",
|
|
281
|
+
lines: () => [{ meta: "x" } as unknown as SectionRow],
|
|
282
|
+
}),
|
|
283
|
+
);
|
|
284
|
+
arm();
|
|
285
|
+
|
|
286
|
+
assert.deepEqual(cardBody("NOB"), []);
|
|
287
|
+
assert.match(
|
|
288
|
+
getSectionFailures().find((entry) => entry.sectionId === "nob")?.message ?? "",
|
|
289
|
+
/label/u,
|
|
290
|
+
);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
test("a collapsed section still gets its header, from the section's own caret", () => {
|
|
294
|
+
const theme = fakeTheme();
|
|
295
|
+
setSectionTheme(theme);
|
|
296
|
+
registerSection(section("music", { title: "MUSIC" }));
|
|
297
|
+
arm();
|
|
298
|
+
|
|
299
|
+
contributed(40);
|
|
300
|
+
rail()?.handleMouse?.({ type: "click", button: "left", x: 4, y: 3, width: 40, height: 20 });
|
|
301
|
+
const rows = contributed(40);
|
|
302
|
+
|
|
303
|
+
assert.equal(rows.length, 1, "a collapsed section is its header alone");
|
|
304
|
+
assert.deepEqual(cardTitles(), ["FOOTER", "MUSIC"]);
|
|
305
|
+
assert.equal(rows[0], referenceHeader(theme, 40, { title: "MUSIC", open: false }));
|
|
306
|
+
assert.ok(stripSgr(rows[0]).startsWith("▸ MUSIC"), "the caret says it is collapsed");
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
// ---------------------------------------------------------------------------------------------
|
|
310
|
+
// helpers
|
|
311
|
+
// ---------------------------------------------------------------------------------------------
|
|
312
|
+
|
|
313
|
+
const ROLE_SGR: Record<string, number> = {
|
|
314
|
+
text: 37,
|
|
315
|
+
muted: 90,
|
|
316
|
+
dim: 2,
|
|
317
|
+
accent: 95,
|
|
318
|
+
success: 32,
|
|
319
|
+
error: 31,
|
|
320
|
+
warning: 33,
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
interface FakeTheme {
|
|
324
|
+
calls: Array<[string, string]>;
|
|
325
|
+
fg(role: string, text: string): string;
|
|
326
|
+
bold(text: string): string;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function fakeTheme(): FakeTheme {
|
|
330
|
+
const calls: Array<[string, string]> = [];
|
|
331
|
+
return {
|
|
332
|
+
calls,
|
|
333
|
+
fg(role, text) {
|
|
334
|
+
calls.push([role, text]);
|
|
335
|
+
return `\u001b[${ROLE_SGR[role] ?? 0}m${text}\u001b[39m`;
|
|
336
|
+
},
|
|
337
|
+
bold(text) {
|
|
338
|
+
return `\u001b[1m${text}\u001b[22m`;
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** The role a piece of text was painted in, read back out of the rendered bytes. */
|
|
344
|
+
function roleOf(row: string, text: string): string {
|
|
345
|
+
const pattern = new RegExp(`\\u001b\\[(\\d+)m${text.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&")}`, "u");
|
|
346
|
+
const match = pattern.exec(row);
|
|
347
|
+
assert.ok(match !== null, `${JSON.stringify(text)} is painted in ${JSON.stringify(row)}`);
|
|
348
|
+
const code = Number(match[1]);
|
|
349
|
+
const role = Object.keys(ROLE_SGR).find((name) => ROLE_SGR[name] === code);
|
|
350
|
+
assert.ok(role !== undefined, `code ${code} maps to a role`);
|
|
351
|
+
return role;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function stripSgr(text: string): string {
|
|
355
|
+
return text.replace(/\u001b\[[0-9;]*m/gu, "");
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** Visible columns of a plain-or-ANSI row, code point by code point (`visibleWidth`, ASCII here). */
|
|
359
|
+
function plainWidth(text: string): number {
|
|
360
|
+
return [...stripSgr(text)].length;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// The reference implementations below are transcribed from gentle-shell, read-only:
|
|
364
|
+
// `lib/shell-panel.ts:44-80` (`clipPanelText`, `fitPanelLine`, `renderPanelHeader`,
|
|
365
|
+
// `renderPanelRow`) and `lib/shell-hover.ts:33-38` (`HOVER_ROLE`, `paintHoverable`). They are
|
|
366
|
+
// verbatim apart from the width function, which is pi-tui's `visibleWidth` in the host and a
|
|
367
|
+
// code-point count here — identical for the ASCII rows these cases use.
|
|
368
|
+
|
|
369
|
+
function referenceClip(text: string, width: number): string {
|
|
370
|
+
if (width <= 0) return "";
|
|
371
|
+
if (plainWidth(text) <= width) return text;
|
|
372
|
+
let clipped = "";
|
|
373
|
+
for (const unit of text.match(/\u001b\[[0-9;]*m|[\s\S]/gu) ?? []) {
|
|
374
|
+
if (unit.startsWith("\u001b[")) {
|
|
375
|
+
clipped += unit;
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
if (plainWidth(clipped + unit) > width - 1) break;
|
|
379
|
+
clipped += unit;
|
|
380
|
+
}
|
|
381
|
+
return `${clipped}…`;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function referenceFit(left: string, right: string, width: number): string {
|
|
385
|
+
const target = Math.max(0, Math.floor(width));
|
|
386
|
+
const rightWidth = plainWidth(right);
|
|
387
|
+
const shownRight = rightWidth + 1 <= target ? right : "";
|
|
388
|
+
const room = target - plainWidth(shownRight) - (shownRight ? 1 : 0);
|
|
389
|
+
const shownLeft = referenceClip(left, room);
|
|
390
|
+
return `${shownLeft}${" ".repeat(Math.max(0, target - plainWidth(shownLeft) - plainWidth(shownRight)))}${shownRight}`;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function paintHoverable(
|
|
394
|
+
theme: FakeTheme | undefined,
|
|
395
|
+
_: unknown,
|
|
396
|
+
text: string,
|
|
397
|
+
hovered: boolean,
|
|
398
|
+
idleRole?: string,
|
|
399
|
+
): string {
|
|
400
|
+
if (theme === undefined) return text;
|
|
401
|
+
if (hovered) return theme.fg("warning", text);
|
|
402
|
+
return idleRole === undefined ? text : theme.fg(idleRole, text);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function referenceHeader(
|
|
406
|
+
theme: FakeTheme,
|
|
407
|
+
width: number,
|
|
408
|
+
header: { title: string; count?: string; open: boolean; hovered?: boolean },
|
|
409
|
+
): string {
|
|
410
|
+
const glyph = paintHoverable(theme, undefined, header.open ? "▾" : "▸", header.hovered ?? false, "muted");
|
|
411
|
+
const name = header.title.toUpperCase();
|
|
412
|
+
const title = theme.fg(header.hovered === true ? "warning" : "text", theme.bold(name));
|
|
413
|
+
const count = header.count === undefined ? "" : theme.fg("muted", header.count);
|
|
414
|
+
return referenceFit(`${glyph} ${title}`, count, width);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function referenceRow(width: number, left: string, right = ""): string {
|
|
418
|
+
return referenceFit(`${" ".repeat(2)}${left}`, right, width);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
test("the reference drawing is itself usable: the fixtures above are the host's shape", () => {
|
|
422
|
+
// A cheap guard on the transcription: if a fixture stops looking like `▾ NAME … count`, the
|
|
423
|
+
// comparisons above would compare two wrong things and still pass.
|
|
424
|
+
const theme = fakeTheme();
|
|
425
|
+
const row = referenceHeader(theme, 20, { title: "music", count: "2", open: true });
|
|
426
|
+
assert.equal(plainWidth(row), 20);
|
|
427
|
+
assert.ok(stripSgr(row).startsWith("▾ MUSIC"));
|
|
428
|
+
assert.ok(stripSgr(row).endsWith("2"));
|
|
429
|
+
assert.equal(renderSidebar(40).length >= 0, true);
|
|
430
|
+
});
|