@ftrdotdev/pi-tui 0.8.0 → 0.9.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/CHANGELOG.md +225 -0
- package/README.md +5 -0
- package/package.json +18 -15
- package/src/activity-service.test.ts +97 -0
- package/src/activity.test.ts +1 -1
- package/src/activity.ts +38 -0
- package/src/chrome/budget.test.ts +345 -0
- package/src/chrome/budget.ts +220 -0
- package/src/chrome/declarations.ts +303 -0
- package/src/chrome/facts.test.ts +165 -0
- package/src/chrome/facts.ts +267 -0
- package/src/chrome/frame.ts +45 -0
- package/src/chrome/laws.test.ts +231 -0
- package/src/chrome/port.test.ts +164 -0
- package/src/chrome/port.ts +67 -0
- package/src/chrome/service-provider.test.ts +383 -0
- package/src/chrome/service-provider.ts +55 -0
- package/src/commands/git-execution.test.ts +5 -2
- package/src/commands/git-execution.ts +27 -15
- package/src/commands/git-status.test.ts +47 -15
- package/src/commands/git-status.ts +83 -31
- package/src/components/bordered-box.test.ts +12 -15
- package/src/components/bordered-box.ts +11 -7
- package/src/components/define-component.ts +1 -1
- package/src/components/index.ts +7 -0
- package/src/components/row-list.test.ts +310 -0
- package/src/components/row-list.ts +272 -0
- package/src/config.test.ts +118 -3
- package/src/config.ts +46 -40
- package/src/frame/box-frame.test.ts +53 -7
- package/src/harness-policy.test.ts +47 -0
- package/src/icons.test.ts +19 -0
- package/src/icons.ts +50 -31
- package/src/index.test.ts +135 -0
- package/src/index.ts +118 -119
- package/src/layers.test.ts +94 -0
- package/src/layers.ts +92 -0
- package/src/runtime-service.test.ts +218 -0
- package/src/runtime-service.ts +103 -0
- package/src/runtime.test.ts +165 -66
- package/src/runtime.ts +127 -93
- package/src/session-lifecycle-service.test.ts +95 -0
- package/src/session-lifecycle.test.ts +77 -0
- package/src/session-lifecycle.ts +21 -0
- package/src/state.test.ts +132 -3
- package/src/state.ts +43 -13
- package/src/telemetry-service.test.ts +250 -0
- package/src/telemetry.test.ts +322 -0
- package/src/telemetry.ts +130 -23
- package/src/ui/editor-tint.test.ts +58 -45
- package/src/ui/editor-tint.ts +1 -1
- package/src/ui/editor.ts +117 -53
- package/src/ui/footer.test.ts +349 -120
- package/src/ui/footer.ts +147 -124
- package/src/ui/header.test.ts +203 -223
- package/src/ui/header.ts +32 -96
- package/src/ui/preview.test.ts +73 -70
- package/src/ui/preview.ts +48 -33
- package/src/ui/render-helpers.test.ts +82 -13
- package/src/ui/render-helpers.ts +110 -122
- package/src/ui/settings-command.test.ts +70 -11
- package/src/ui/settings-command.ts +30 -45
- package/src/ui/theme-color.test.ts +4 -3
- package/src/usage-totals-service.test.ts +230 -0
- package/src/usage-totals-service.ts +59 -0
- package/src/utils.test.ts +46 -50
- package/src/utils.ts +41 -239
- package/src/vim/editor-host.test.ts +201 -75
- package/src/vim/editor-state.ts +2 -2
- package/src/vim/mode-indicator.test.ts +6 -5
- package/src/vim/mode-indicator.ts +13 -9
- package/src/vim/selection-render.ts +8 -4
- package/src/vim/text-model.test.ts +52 -14
- package/src/vim/text-model.ts +1 -1
- package/src/vim/vim-router.test.ts +3 -0
- package/src/vim/vim-router.ts +1 -1
package/src/ui/header.test.ts
CHANGED
|
@@ -1,138 +1,114 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// Each test is its own entry point: it builds a fresh layer for one scenario and
|
|
2
|
+
// runs its effects inside it, so providing there is the pattern the rule allows.
|
|
3
|
+
/* oxlint-disable effecttsgo/strict-effect-provide */
|
|
4
|
+
import { assert, it, vi } from "@effect/vitest";
|
|
5
|
+
import { themeDouble } from "@ftrdotdev/pi-test-kit";
|
|
6
|
+
import { headerCtxDouble, stubChromePort } from "../../test-support/doubles.ts";
|
|
7
|
+
import { Effect } from "effect";
|
|
4
8
|
import { VERSION, type Theme } from "@earendil-works/pi-coding-agent";
|
|
9
|
+
import { visibleWidth } from "@earendil-works/pi-tui";
|
|
10
|
+
import type { ChromePort } from "../chrome/port.ts";
|
|
5
11
|
import { HeaderRenderService, installHeader, resetScreenClearMemory } from "./header.ts";
|
|
6
12
|
|
|
7
|
-
// Pixel parity: the header
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
// frozen tables — deterministic.
|
|
12
|
-
const plainTheme = {
|
|
13
|
-
fg: (_color: string, text: string) => text,
|
|
14
|
-
bg: (_color: string, text: string) => text,
|
|
15
|
-
bold: (text: string) => `*${text}*`,
|
|
16
|
-
style: (text: string) => text,
|
|
17
|
-
} as unknown as Theme;
|
|
13
|
+
// Pixel parity: the header renders byte-identically through makeBorderedBox.
|
|
14
|
+
// The header is deterministic (no Random draw, no tips panel), so the table
|
|
15
|
+
// needs no seed.
|
|
16
|
+
const plainTheme = themeDouble({ bold: (text) => `*${text}*` });
|
|
18
17
|
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
{ name: "settings" },
|
|
23
|
-
{ name: "model" },
|
|
24
|
-
{ name: "preview" },
|
|
25
|
-
],
|
|
26
|
-
getThinkingLevel: () => "off",
|
|
27
|
-
} as never;
|
|
18
|
+
const REAL_PROCESS = process;
|
|
19
|
+
const REAL_STDOUT = process.stdout;
|
|
20
|
+
const REAL_IS_TTY = Object.getOwnPropertyDescriptor(process.stdout, "isTTY");
|
|
28
21
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
cwd: "/projects/pi-mono/packages/tui",
|
|
32
|
-
ui: { theme: plainTheme },
|
|
33
|
-
} as never;
|
|
22
|
+
/** A port whose only meaningful fact for the header is its theme. */
|
|
23
|
+
const headerPort = (theme: Theme): ChromePort => stubChromePort({ theme: () => theme });
|
|
34
24
|
|
|
35
|
-
const
|
|
25
|
+
const WIDTHS = [24, 30, 40, 60, 80, 100, 120];
|
|
26
|
+
const FROZEN_VERSION = "v1.5.0";
|
|
36
27
|
|
|
37
28
|
const EXPECTED: Record<string, string[]> = {
|
|
38
|
-
20: ["Pi v0.84.4"],
|
|
39
29
|
24: [
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"\u2502/projects/pi-mono/p\u001b[0m...\u001b[0m\u2502",
|
|
51
|
-
"\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f",
|
|
30
|
+
"╭─── Pi v1.5.0 ────────╮",
|
|
31
|
+
"│ │",
|
|
32
|
+
"│ │",
|
|
33
|
+
"│ █████████ │",
|
|
34
|
+
"│ ███ ███ │",
|
|
35
|
+
"│ ██████ ███ │",
|
|
36
|
+
"│ ███ ███ │",
|
|
37
|
+
"│ │",
|
|
38
|
+
"│*Let's make some Pi\u001b[0m...\u001b[0m│",
|
|
39
|
+
"╰──────────────────────╯",
|
|
52
40
|
],
|
|
53
41
|
30: [
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"\u2502/projects/pi-mono/package\u001b[0m...\u001b[0m\u2502",
|
|
65
|
-
"\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f",
|
|
42
|
+
"╭─── Pi v1.5.0 ──────────────╮",
|
|
43
|
+
"│ │",
|
|
44
|
+
"│ │",
|
|
45
|
+
"│ █████████ │",
|
|
46
|
+
"│ ███ ███ │",
|
|
47
|
+
"│ ██████ ███ │",
|
|
48
|
+
"│ ███ ███ │",
|
|
49
|
+
"│ │",
|
|
50
|
+
"│ *Let's make some Pi(e)* │",
|
|
51
|
+
"╰────────────────────────────╯",
|
|
66
52
|
],
|
|
67
53
|
40: [
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"\u2502 /projects/pi-mono/packages/tui \u2502",
|
|
79
|
-
"\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f",
|
|
54
|
+
"╭─── Pi v1.5.0 ────────────────────────╮",
|
|
55
|
+
"│ │",
|
|
56
|
+
"│ │",
|
|
57
|
+
"│ █████████ │",
|
|
58
|
+
"│ ███ ███ │",
|
|
59
|
+
"│ ██████ ███ │",
|
|
60
|
+
"│ ███ ███ │",
|
|
61
|
+
"│ │",
|
|
62
|
+
"│ *Let's make some Pi(e)* │",
|
|
63
|
+
"╰──────────────────────────────────────╯",
|
|
80
64
|
],
|
|
81
65
|
60: [
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"\u2502 /projects/pi-mono/packages/tui \u2502 \u2502",
|
|
93
|
-
"\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f",
|
|
66
|
+
"╭─── Pi v1.5.0 ────────────────────────────────────────────╮",
|
|
67
|
+
"│ │",
|
|
68
|
+
"│ │",
|
|
69
|
+
"│ █████████ │",
|
|
70
|
+
"│ ███ ███ │",
|
|
71
|
+
"│ ██████ ███ │",
|
|
72
|
+
"│ ███ ███ │",
|
|
73
|
+
"│ │",
|
|
74
|
+
"│ *Let's make some Pi(e)* │",
|
|
75
|
+
"╰──────────────────────────────────────────────────────────╯",
|
|
94
76
|
],
|
|
95
77
|
80: [
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"
|
|
99
|
-
"
|
|
100
|
-
"
|
|
101
|
-
"
|
|
102
|
-
"
|
|
103
|
-
"
|
|
104
|
-
"
|
|
105
|
-
"
|
|
106
|
-
"\u2502 /projects/pi-mono/packages/tui \u2502 \u2502",
|
|
107
|
-
"\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f",
|
|
78
|
+
"╭─── Pi v1.5.0 ────────────────────────────────────────────────────────────────╮",
|
|
79
|
+
"│ │",
|
|
80
|
+
"│ │",
|
|
81
|
+
"│ █████████ │",
|
|
82
|
+
"│ ███ ███ │",
|
|
83
|
+
"│ ██████ ███ │",
|
|
84
|
+
"│ ███ ███ │",
|
|
85
|
+
"│ │",
|
|
86
|
+
"│ *Let's make some Pi(e)* │",
|
|
87
|
+
"╰──────────────────────────────────────────────────────────────────────────────╯",
|
|
108
88
|
],
|
|
109
89
|
100: [
|
|
110
|
-
"
|
|
111
|
-
"
|
|
112
|
-
"
|
|
113
|
-
"
|
|
114
|
-
"
|
|
115
|
-
"
|
|
116
|
-
"
|
|
117
|
-
"
|
|
118
|
-
"
|
|
119
|
-
"
|
|
120
|
-
"\u2502 /projects/pi-mono/packages/tui \u2502 \u2502",
|
|
121
|
-
"\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f",
|
|
90
|
+
"╭─── Pi v1.5.0 ────────────────────────────────────────────────────────────────────────────────────╮",
|
|
91
|
+
"│ │",
|
|
92
|
+
"│ │",
|
|
93
|
+
"│ █████████ │",
|
|
94
|
+
"│ ███ ███ │",
|
|
95
|
+
"│ ██████ ███ │",
|
|
96
|
+
"│ ███ ███ │",
|
|
97
|
+
"│ │",
|
|
98
|
+
"│ *Let's make some Pi(e)* │",
|
|
99
|
+
"╰──────────────────────────────────────────────────────────────────────────────────────────────────╯",
|
|
122
100
|
],
|
|
123
101
|
120: [
|
|
124
|
-
"
|
|
125
|
-
"
|
|
126
|
-
"
|
|
127
|
-
"
|
|
128
|
-
"
|
|
129
|
-
"
|
|
130
|
-
"
|
|
131
|
-
"
|
|
132
|
-
"
|
|
133
|
-
"
|
|
134
|
-
"\u2502 /projects/pi-mono/packages/tui \u2502 \u2502",
|
|
135
|
-
"\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f",
|
|
102
|
+
"╭─── Pi v1.5.0 ────────────────────────────────────────────────────────────────────────────────────────────────────────╮",
|
|
103
|
+
"│ │",
|
|
104
|
+
"│ │",
|
|
105
|
+
"│ █████████ │",
|
|
106
|
+
"│ ███ ███ │",
|
|
107
|
+
"│ ██████ ███ │",
|
|
108
|
+
"│ ███ ███ │",
|
|
109
|
+
"│ │",
|
|
110
|
+
"│ *Let's make some Pi(e)* │",
|
|
111
|
+
"╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯",
|
|
136
112
|
],
|
|
137
113
|
};
|
|
138
114
|
|
|
@@ -140,7 +116,6 @@ const EXPECTED: Record<string, string[]> = {
|
|
|
140
116
|
// dependency bump does not break pixel parity. A version of a different length
|
|
141
117
|
// changes the top-border padding, so restore each boxed row to its frozen width
|
|
142
118
|
// by adding or removing trailing dashes before the closing corner.
|
|
143
|
-
const FROZEN_VERSION = "v0.84.4";
|
|
144
119
|
for (const [width, lines] of Object.entries(EXPECTED)) {
|
|
145
120
|
EXPECTED[width] = lines.map((line) => {
|
|
146
121
|
if (!line.includes(FROZEN_VERSION)) return line;
|
|
@@ -152,85 +127,87 @@ for (const [width, lines] of Object.entries(EXPECTED)) {
|
|
|
152
127
|
});
|
|
153
128
|
}
|
|
154
129
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
Effect.runSync(
|
|
130
|
+
for (const width of WIDTHS) {
|
|
131
|
+
it.effect(`renders the boxed header identically at width ${width}`, () =>
|
|
158
132
|
Effect.gen(function* () {
|
|
159
133
|
const svc = yield* HeaderRenderService;
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
.pipe(Random.withSeed(TIPS_SEED)),
|
|
134
|
+
const rendered = yield* svc.render(width);
|
|
135
|
+
assert.deepStrictEqual(rendered, EXPECTED[String(width)]);
|
|
136
|
+
}).pipe(Effect.provide(HeaderRenderService.make(headerPort(plainTheme)))),
|
|
164
137
|
);
|
|
165
|
-
|
|
166
|
-
for (const width of Object.keys(EXPECTED)) {
|
|
167
|
-
it(`renders the boxed header identically at width ${width}`, () => {
|
|
168
|
-
assert.deepStrictEqual(renderHeader(Number(width)), EXPECTED[width]);
|
|
169
|
-
});
|
|
170
138
|
}
|
|
171
139
|
|
|
172
|
-
it("header
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
],
|
|
181
|
-
getThinkingLevel: () => thinking,
|
|
182
|
-
} as never;
|
|
183
|
-
const mutableCtx = {
|
|
184
|
-
model: { provider: "anthropic", id: "claude-sonnet-4" },
|
|
185
|
-
cwd: "/projects/pi-mono/packages/tui",
|
|
186
|
-
ui: { theme: plainTheme },
|
|
187
|
-
} as never;
|
|
140
|
+
it.effect("the header renders no fact other than its version", () =>
|
|
141
|
+
Effect.gen(function* () {
|
|
142
|
+
// Arrange: the layer with a model name and a cwd the footer owns.
|
|
143
|
+
const svc = yield* HeaderRenderService;
|
|
144
|
+
|
|
145
|
+
// Act: render at 80.
|
|
146
|
+
const lines = yield* svc.render(80);
|
|
147
|
+
const joined = lines.join("\n");
|
|
188
148
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
);
|
|
149
|
+
// Assert: none of the footer's facts appear, and the version does.
|
|
150
|
+
assert.ok(!joined.includes("anthropic"));
|
|
151
|
+
assert.ok(!joined.includes("claude-sonnet-4"));
|
|
152
|
+
assert.ok(!joined.includes("/projects/pi-mono"));
|
|
153
|
+
assert.ok(!joined.includes("thinking"));
|
|
154
|
+
assert.ok(!joined.includes("/scoped-models"));
|
|
155
|
+
assert.ok(joined.includes(`Pi v${VERSION}`));
|
|
156
|
+
}).pipe(Effect.provide(HeaderRenderService.make(headerPort(plainTheme)))),
|
|
157
|
+
);
|
|
199
158
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
159
|
+
it.effect("the header renders from the port's theme", () => {
|
|
160
|
+
// Arrange: a marker theme that labels accent and bold text.
|
|
161
|
+
const markerTheme = themeDouble({
|
|
162
|
+
fg: (color, text) => `${color}:${text}`,
|
|
163
|
+
bold: (text) => `*${text}*`,
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
return Effect.gen(function* () {
|
|
167
|
+
const svc = yield* HeaderRenderService;
|
|
204
168
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
// commands. The left cells re-read live inputs per run.
|
|
208
|
-
// Row shape: rail │ LEFT cell │ tips cell │ rail — the tips cell is the
|
|
209
|
-
// second split part after the rail-separated LEFT cell.
|
|
210
|
-
const tipsCells = (lines: string[]) =>
|
|
211
|
-
lines.map((line) => {
|
|
212
|
-
const parts = line.split("│");
|
|
213
|
-
const cell = parts.length >= 3 ? parts[2] : undefined;
|
|
214
|
-
return cell?.trim() ?? "";
|
|
215
|
-
});
|
|
216
|
-
assert.deepStrictEqual(tipsCells(second), tipsCells(first));
|
|
217
|
-
assert.deepStrictEqual(tipsCells(first).slice(6, 10), [
|
|
218
|
-
"/tui",
|
|
219
|
-
"/copy",
|
|
220
|
-
"/logout",
|
|
221
|
-
"/scoped-models",
|
|
222
|
-
]);
|
|
169
|
+
// Act: render at 60.
|
|
170
|
+
const lines = yield* svc.render(60);
|
|
223
171
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
172
|
+
// Assert: the title carries the port theme's bold marker; the footer's
|
|
173
|
+
// model fact stays absent.
|
|
174
|
+
assert.ok(lines[8]!.includes("*Let's make some Pi(e)*"));
|
|
175
|
+
assert.ok(lines[0]!.includes("accent:"));
|
|
176
|
+
assert.ok(!lines.join("\n").includes("anthropic"));
|
|
177
|
+
}).pipe(Effect.provide(HeaderRenderService.make(headerPort(markerTheme))));
|
|
228
178
|
});
|
|
229
179
|
|
|
180
|
+
it.effect("the header box is 10 rows at every width at or above 24", () =>
|
|
181
|
+
Effect.gen(function* () {
|
|
182
|
+
const svc = yield* HeaderRenderService;
|
|
183
|
+
|
|
184
|
+
for (const width of WIDTHS) {
|
|
185
|
+
if (width < 24) continue;
|
|
186
|
+
const lines = yield* svc.render(width);
|
|
187
|
+
assert.strictEqual(lines.length, 10, `width ${width}: row count`);
|
|
188
|
+
assert.ok(lines[0]!.startsWith("╭─"), `width ${width}: top border`);
|
|
189
|
+
assert.ok(lines[0]!.includes(`Pi v${VERSION}`), `width ${width}: version label`);
|
|
190
|
+
assert.ok(lines[lines.length - 1]!.startsWith("\u2570"), `width ${width}: bottom border`);
|
|
191
|
+
for (const line of lines) {
|
|
192
|
+
assert.strictEqual(visibleWidth(line), width, `width ${width}: line width`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}).pipe(Effect.provide(HeaderRenderService.make(headerPort(plainTheme)))),
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
it.effect("the header is deterministic without a seed", () =>
|
|
199
|
+
Effect.gen(function* () {
|
|
200
|
+
const svc = yield* HeaderRenderService;
|
|
201
|
+
const first = yield* svc.render(80);
|
|
202
|
+
const second = yield* svc.render(80);
|
|
203
|
+
assert.deepStrictEqual(first, second);
|
|
204
|
+
}).pipe(Effect.provide(HeaderRenderService.make(headerPort(plainTheme)))),
|
|
205
|
+
);
|
|
206
|
+
|
|
230
207
|
it("installHeader registers a closure component at mount and unregisters on cleanup", () => {
|
|
231
208
|
let captured: ((tui: unknown, theme: unknown) => unknown) | undefined;
|
|
232
209
|
let unregistered = false;
|
|
233
|
-
const mountCtx = {
|
|
210
|
+
const mountCtx = headerCtxDouble({
|
|
234
211
|
model: { provider: "anthropic", id: "claude-sonnet-4" },
|
|
235
212
|
cwd: "/projects/pi-mono/packages/tui",
|
|
236
213
|
ui: {
|
|
@@ -240,9 +217,9 @@ it("installHeader registers a closure component at mount and unregisters on clea
|
|
|
240
217
|
if (factory === undefined) unregistered = true;
|
|
241
218
|
},
|
|
242
219
|
},
|
|
243
|
-
}
|
|
220
|
+
});
|
|
244
221
|
|
|
245
|
-
const cleanup = installHeader(
|
|
222
|
+
const cleanup = installHeader(mountCtx, headerPort(plainTheme));
|
|
246
223
|
|
|
247
224
|
assert.strictEqual(typeof captured, "function");
|
|
248
225
|
const componentA = captured!({ mode: "fullscreen" }, plainTheme) as {
|
|
@@ -250,27 +227,16 @@ it("installHeader registers a closure component at mount and unregisters on clea
|
|
|
250
227
|
};
|
|
251
228
|
const linesA = componentA.render(80);
|
|
252
229
|
|
|
253
|
-
// Re-mount swaps the slot to a fresh component; both render the
|
|
230
|
+
// Re-mount swaps the slot to a fresh component; both render the same box.
|
|
254
231
|
const componentB = captured!({ mode: "fullscreen" }, plainTheme) as {
|
|
255
232
|
render: (width: number) => string[];
|
|
256
233
|
};
|
|
257
234
|
assert.notStrictEqual(componentA, componentB);
|
|
258
235
|
const linesB = componentB.render(80);
|
|
259
236
|
|
|
260
|
-
// The seam
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
// empty rail rows.
|
|
264
|
-
const expected80 = EXPECTED[80]!;
|
|
265
|
-
for (const [label, lines] of [
|
|
266
|
-
["first mount", linesA],
|
|
267
|
-
["remount", linesB],
|
|
268
|
-
] as const) {
|
|
269
|
-
assert.strictEqual(lines.length, expected80.length, `${label}: line count`);
|
|
270
|
-
for (const i of [0, 1, 2, 3, 4, 5, 10, 11]) {
|
|
271
|
-
assert.deepStrictEqual(lines[i], expected80[i], `${label}: row ${i}`);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
237
|
+
// The seam is deterministic: the remount renders the frozen table exactly.
|
|
238
|
+
assert.deepStrictEqual(linesA, EXPECTED[80]);
|
|
239
|
+
assert.deepStrictEqual(linesB, EXPECTED[80]);
|
|
274
240
|
|
|
275
241
|
cleanup();
|
|
276
242
|
assert.strictEqual(unregistered, true);
|
|
@@ -281,7 +247,7 @@ it("installHeader registers a closure component at mount and unregisters on clea
|
|
|
281
247
|
const captureMountCtx = (
|
|
282
248
|
onFactory: (factory: ((tui: unknown, theme: unknown) => unknown) | undefined) => void,
|
|
283
249
|
) =>
|
|
284
|
-
({
|
|
250
|
+
headerCtxDouble({
|
|
285
251
|
model: { provider: "anthropic", id: "claude-sonnet-4" },
|
|
286
252
|
cwd: "/projects/pi-mono/packages/tui",
|
|
287
253
|
ui: {
|
|
@@ -290,34 +256,48 @@ const captureMountCtx = (
|
|
|
290
256
|
onFactory(factory);
|
|
291
257
|
},
|
|
292
258
|
},
|
|
293
|
-
})
|
|
259
|
+
});
|
|
294
260
|
|
|
295
261
|
it("clears the screen once per process, and only in regular mode", () => {
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
262
|
+
const written: unknown[] = [];
|
|
263
|
+
const fakeStdout = {
|
|
264
|
+
isTTY: true,
|
|
265
|
+
write: (chunk: unknown) => {
|
|
266
|
+
written.push(chunk);
|
|
267
|
+
return true;
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
vi.stubGlobal(
|
|
271
|
+
"process",
|
|
272
|
+
Object.create(process, { stdout: { value: fakeStdout, configurable: true } }),
|
|
273
|
+
);
|
|
305
274
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
275
|
+
resetScreenClearMemory();
|
|
276
|
+
let captured: ((tui: unknown, theme: unknown) => unknown) | undefined;
|
|
277
|
+
const mountCtx = captureMountCtx((factory) => {
|
|
278
|
+
captured = factory;
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
installHeader(mountCtx, headerPort(plainTheme));
|
|
282
|
+
captured!({ mode: "fullscreen" }, plainTheme);
|
|
283
|
+
assert.strictEqual(written.length, 0, "fullscreen must not clear");
|
|
309
284
|
|
|
310
|
-
|
|
311
|
-
|
|
285
|
+
captured!({ mode: "regular" }, plainTheme);
|
|
286
|
+
assert.deepStrictEqual(written[0], "\x1b[2J\x1b[H");
|
|
287
|
+
|
|
288
|
+
// A reload re-mounts in regular mode while pi-tui still holds the
|
|
289
|
+
// previous lines. The once guard must keep it from writing escape codes
|
|
290
|
+
// behind the renderer's back (the blank-widget regression).
|
|
291
|
+
captured!({ mode: "regular" }, plainTheme);
|
|
292
|
+
assert.strictEqual(written.length, 1, "re-mount must not clear again");
|
|
293
|
+
|
|
294
|
+
resetScreenClearMemory();
|
|
295
|
+
});
|
|
312
296
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
write.mockRestore();
|
|
320
|
-
Object.defineProperty(process.stdout, "isTTY", { value: originalIsTTY, configurable: true });
|
|
321
|
-
resetScreenClearMemory();
|
|
322
|
-
}
|
|
297
|
+
it("the faked terminal does not outlive the test that made it", () => {
|
|
298
|
+
assert.strictEqual(process, REAL_PROCESS);
|
|
299
|
+
assert.strictEqual(process.stdout, REAL_STDOUT);
|
|
300
|
+
assert.deepStrictEqual(Object.getOwnPropertyDescriptor(process.stdout, "isTTY"), REAL_IS_TTY);
|
|
301
|
+
// oxlint-disable-next-line typescript/unbound-method -- identity check only.
|
|
302
|
+
assert.strictEqual(vi.isMockFunction(process.stdout.write), false);
|
|
323
303
|
});
|