@ftrdotdev/pi-tui 0.7.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 +50 -42
- 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
|
@@ -1,5 +1,10 @@
|
|
|
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 */
|
|
1
4
|
import { assert, it } from "@effect/vitest";
|
|
5
|
+
import { PROPERTY_RUNS } from "@ftrdotdev/pi-test-kit";
|
|
2
6
|
import { Duration, Effect, Layer } from "effect";
|
|
7
|
+
import { porcelainLineArbitrary, porcelainLinesArbitrary } from "../../test-support/generators.ts";
|
|
3
8
|
import type { StubEntry } from "./git-execution.ts";
|
|
4
9
|
import { GitExecutionService } from "./git-execution.ts";
|
|
5
10
|
import {
|
|
@@ -11,6 +16,8 @@ import {
|
|
|
11
16
|
parseBranchLine,
|
|
12
17
|
parseFileLines,
|
|
13
18
|
parseStashCount,
|
|
19
|
+
withCounts,
|
|
20
|
+
withStatus,
|
|
14
21
|
} from "./git-status.ts";
|
|
15
22
|
|
|
16
23
|
const PRIMARY_ARGS = ["status", "--porcelain=v1", "--branch", "--show-stash"];
|
|
@@ -95,28 +102,28 @@ it("parseBranchLine detects detached HEAD", () => {
|
|
|
95
102
|
it("parseFileLines counts worktree-modified lines", () => {
|
|
96
103
|
assert.deepStrictEqual(
|
|
97
104
|
parseFileLines([" M a.txt", "MM b.txt"]),
|
|
98
|
-
|
|
105
|
+
withCounts(FileCounts.empty(), { modified: 2, staged: 1 }),
|
|
99
106
|
);
|
|
100
107
|
});
|
|
101
108
|
|
|
102
109
|
it("parseFileLines counts staged additions and staged deletions", () => {
|
|
103
110
|
assert.deepStrictEqual(
|
|
104
111
|
parseFileLines(["A s.txt", "D e.txt"]),
|
|
105
|
-
|
|
112
|
+
withCounts(FileCounts.empty(), { staged: 1, deleted: 1 }),
|
|
106
113
|
);
|
|
107
114
|
});
|
|
108
115
|
|
|
109
116
|
it("parseFileLines counts untracked and renamed files", () => {
|
|
110
117
|
assert.deepStrictEqual(
|
|
111
118
|
parseFileLines(["?? u.txt", "R d.txt -> renamed.txt"]),
|
|
112
|
-
|
|
119
|
+
withCounts(FileCounts.empty(), { untracked: 1, renamed: 1 }),
|
|
113
120
|
);
|
|
114
121
|
});
|
|
115
122
|
|
|
116
123
|
it("parseFileLines counts conflicted files (UU)", () => {
|
|
117
124
|
assert.deepStrictEqual(
|
|
118
125
|
parseFileLines(["UU c.txt"]),
|
|
119
|
-
|
|
126
|
+
withCounts(FileCounts.empty(), { conflicted: 1 }),
|
|
120
127
|
);
|
|
121
128
|
});
|
|
122
129
|
|
|
@@ -131,8 +138,7 @@ it("parseFileLines counts the full captured matrix", () => {
|
|
|
131
138
|
"UU c.txt",
|
|
132
139
|
"?? d.txt",
|
|
133
140
|
]),
|
|
134
|
-
FileCounts.
|
|
135
|
-
...FileCounts.empty(),
|
|
141
|
+
withCounts(FileCounts.empty(), {
|
|
136
142
|
modified: 2,
|
|
137
143
|
staged: 2,
|
|
138
144
|
deleted: 1,
|
|
@@ -143,17 +149,10 @@ it("parseFileLines counts the full captured matrix", () => {
|
|
|
143
149
|
);
|
|
144
150
|
});
|
|
145
151
|
|
|
146
|
-
it("parseFileLines ignores the branch header and empty lines", () => {
|
|
147
|
-
assert.deepStrictEqual(
|
|
148
|
-
parseFileLines(["## main", "", " M a.txt"]),
|
|
149
|
-
FileCounts.make({ ...FileCounts.empty(), modified: 1 }),
|
|
150
|
-
);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
152
|
it("parseFileLines counts a worktree deletion as deleted, not modified", () => {
|
|
154
153
|
assert.deepStrictEqual(
|
|
155
154
|
parseFileLines([" D d.txt"]),
|
|
156
|
-
|
|
155
|
+
withCounts(FileCounts.empty(), { deleted: 1 }),
|
|
157
156
|
);
|
|
158
157
|
});
|
|
159
158
|
|
|
@@ -174,7 +173,7 @@ it.effect("read returns a full status for a clean repository", () =>
|
|
|
174
173
|
{ command: "git", args: PRIMARY_ARGS, stdout: "## main\n", exitCode: 0 },
|
|
175
174
|
{ command: "git", args: ["stash", "list"], stdout: "", exitCode: 0 },
|
|
176
175
|
]);
|
|
177
|
-
assert.deepStrictEqual(result,
|
|
176
|
+
assert.deepStrictEqual(result, withStatus(GitStatus.empty(), { branch: "main" }));
|
|
178
177
|
}),
|
|
179
178
|
);
|
|
180
179
|
|
|
@@ -377,3 +376,36 @@ it.effect("read degrades the detached tag to null when describe fails", () =>
|
|
|
377
376
|
assert.strictEqual(result.commit?.oid, "0502eea0d67bf502c9f910af4c61fbb5c89d474c");
|
|
378
377
|
}),
|
|
379
378
|
);
|
|
379
|
+
|
|
380
|
+
it.prop(
|
|
381
|
+
"a branch header never changes the counts",
|
|
382
|
+
{ porcelain: porcelainLinesArbitrary },
|
|
383
|
+
({ porcelain }) => {
|
|
384
|
+
const counts = parseFileLines(porcelain.lines);
|
|
385
|
+
assert.deepStrictEqual(parseFileLines([...porcelain.headers, ...porcelain.lines]), counts);
|
|
386
|
+
assert.deepStrictEqual(parseFileLines([...porcelain.lines, ""]), counts);
|
|
387
|
+
},
|
|
388
|
+
{ arbitrary: { runs: PROPERTY_RUNS } },
|
|
389
|
+
);
|
|
390
|
+
|
|
391
|
+
it.prop(
|
|
392
|
+
"a status line contributes at most two counts",
|
|
393
|
+
{ line: porcelainLineArbitrary },
|
|
394
|
+
({ line }) => {
|
|
395
|
+
const counts = parseFileLines([line]);
|
|
396
|
+
const fields = [
|
|
397
|
+
counts.modified,
|
|
398
|
+
counts.untracked,
|
|
399
|
+
counts.staged,
|
|
400
|
+
counts.conflicted,
|
|
401
|
+
counts.renamed,
|
|
402
|
+
counts.deleted,
|
|
403
|
+
];
|
|
404
|
+
assert.isAtMost(
|
|
405
|
+
fields.reduce((total, value) => total + value, 0),
|
|
406
|
+
2,
|
|
407
|
+
);
|
|
408
|
+
for (const value of fields) assert.isAtMost(value, 1);
|
|
409
|
+
},
|
|
410
|
+
{ arbitrary: { runs: PROPERTY_RUNS } },
|
|
411
|
+
);
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
type CommandResult,
|
|
5
5
|
type GitExecutionError,
|
|
6
6
|
} from "./git-execution.ts";
|
|
7
|
+
import { isNonEmptyString } from "../utils.ts";
|
|
7
8
|
|
|
8
9
|
// ---------------------------------------------------------------------------
|
|
9
10
|
// Domain records
|
|
@@ -13,7 +14,9 @@ import {
|
|
|
13
14
|
* Detached-HEAD commit information: the full oid, the detached flag, and the
|
|
14
15
|
* exact-matching tag when one exists (each degraded to `null` on read failure).
|
|
15
16
|
*/
|
|
16
|
-
export class GitCommitInfo extends Schema.Class<GitCommitInfo>(
|
|
17
|
+
export class GitCommitInfo extends Schema.Class<GitCommitInfo, { readonly brand: unique symbol }>(
|
|
18
|
+
"@ftrdotdev/pi-tui/git/GitCommitInfo",
|
|
19
|
+
)({
|
|
17
20
|
oid: Schema.NullOr(Schema.String),
|
|
18
21
|
detached: Schema.Boolean,
|
|
19
22
|
tag: Schema.NullOr(Schema.String),
|
|
@@ -23,7 +26,9 @@ export class GitCommitInfo extends Schema.Class<GitCommitInfo>("tui/git/GitCommi
|
|
|
23
26
|
* The git status record the footer consumes: branch, ahead/behind counts,
|
|
24
27
|
* working-tree counts, stash count, and detached-HEAD commit info.
|
|
25
28
|
*/
|
|
26
|
-
export class GitStatus extends Schema.Class<GitStatus>(
|
|
29
|
+
export class GitStatus extends Schema.Class<GitStatus, { readonly brand: unique symbol }>(
|
|
30
|
+
"@ftrdotdev/pi-tui/git/GitStatus",
|
|
31
|
+
)({
|
|
27
32
|
branch: Schema.optional(Schema.String),
|
|
28
33
|
ahead: Schema.Finite,
|
|
29
34
|
behind: Schema.Finite,
|
|
@@ -55,7 +60,9 @@ export class GitStatus extends Schema.Class<GitStatus>("tui/git/GitStatus")({
|
|
|
55
60
|
}
|
|
56
61
|
|
|
57
62
|
/** A parsed `## ...` branch header from porcelain v1 output. */
|
|
58
|
-
export class ParsedBranch extends Schema.Class<ParsedBranch>(
|
|
63
|
+
export class ParsedBranch extends Schema.Class<ParsedBranch, { readonly brand: unique symbol }>(
|
|
64
|
+
"@ftrdotdev/pi-tui/git/ParsedBranch",
|
|
65
|
+
)({
|
|
59
66
|
detached: Schema.Boolean,
|
|
60
67
|
name: Schema.optional(Schema.String), // undefined when detached
|
|
61
68
|
ahead: Schema.Finite,
|
|
@@ -82,8 +89,8 @@ export function parseBranchLine(line: string): ParsedBranch {
|
|
|
82
89
|
return ParsedBranch.make({
|
|
83
90
|
detached: false,
|
|
84
91
|
name: nameMatch?.[1] ?? undefined,
|
|
85
|
-
ahead: aheadMatch ? Number(aheadMatch[1]) : 0,
|
|
86
|
-
behind: behindMatch ? Number(behindMatch[1]) : 0,
|
|
92
|
+
ahead: aheadMatch !== null ? Number(aheadMatch[1]) : 0,
|
|
93
|
+
behind: behindMatch !== null ? Number(behindMatch[1]) : 0,
|
|
87
94
|
});
|
|
88
95
|
}
|
|
89
96
|
|
|
@@ -93,7 +100,9 @@ export function parseBranchLine(line: string): ParsedBranch {
|
|
|
93
100
|
* Porcelain v1 file-status counters with the footer's counting semantics:
|
|
94
101
|
* each status line increments one or two of the six buckets.
|
|
95
102
|
*/
|
|
96
|
-
export class FileCounts extends Schema.Class<FileCounts>(
|
|
103
|
+
export class FileCounts extends Schema.Class<FileCounts, { readonly brand: unique symbol }>(
|
|
104
|
+
"@ftrdotdev/pi-tui/git/FileCounts",
|
|
105
|
+
)({
|
|
97
106
|
modified: Schema.mutableKey(Schema.Finite),
|
|
98
107
|
untracked: Schema.mutableKey(Schema.Finite),
|
|
99
108
|
staged: Schema.mutableKey(Schema.Finite),
|
|
@@ -114,10 +123,50 @@ export class FileCounts extends Schema.Class<FileCounts>("tui/git/FileCounts")({
|
|
|
114
123
|
}
|
|
115
124
|
}
|
|
116
125
|
|
|
126
|
+
/** The `FileCounts` buckets a caller may replace. */
|
|
127
|
+
export type CountsChange = Partial<
|
|
128
|
+
Pick<FileCounts, "modified" | "untracked" | "staged" | "conflicted" | "renamed" | "deleted">
|
|
129
|
+
>;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* A copy of `counts` with the given buckets replaced. Fields are named
|
|
133
|
+
* explicitly: spreading the `Schema.Class` instance would drop its prototype.
|
|
134
|
+
* Exported for callers that assemble counts outside `parseFileLines`.
|
|
135
|
+
*/
|
|
136
|
+
export const withCounts = (counts: FileCounts, change: CountsChange): FileCounts =>
|
|
137
|
+
FileCounts.make({
|
|
138
|
+
modified: change.modified ?? counts.modified,
|
|
139
|
+
untracked: change.untracked ?? counts.untracked,
|
|
140
|
+
staged: change.staged ?? counts.staged,
|
|
141
|
+
conflicted: change.conflicted ?? counts.conflicted,
|
|
142
|
+
renamed: change.renamed ?? counts.renamed,
|
|
143
|
+
deleted: change.deleted ?? counts.deleted,
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
/** The `GitStatus` fields a caller may replace. */
|
|
147
|
+
export type StatusChange = CountsChange &
|
|
148
|
+
Partial<Pick<GitStatus, "branch" | "ahead" | "behind" | "stashed" | "commit">>;
|
|
149
|
+
|
|
117
150
|
/**
|
|
118
|
-
*
|
|
119
|
-
*
|
|
151
|
+
* A copy of `status` with the given fields replaced. Fields are named
|
|
152
|
+
* explicitly: spreading the `Schema.Class` instance would drop its prototype.
|
|
153
|
+
* An `undefined` change value keeps the current field, so no field is cleared.
|
|
120
154
|
*/
|
|
155
|
+
export const withStatus = (status: GitStatus, change: StatusChange): GitStatus =>
|
|
156
|
+
GitStatus.make({
|
|
157
|
+
branch: change.branch ?? status.branch,
|
|
158
|
+
ahead: change.ahead ?? status.ahead,
|
|
159
|
+
behind: change.behind ?? status.behind,
|
|
160
|
+
modified: change.modified ?? status.modified,
|
|
161
|
+
untracked: change.untracked ?? status.untracked,
|
|
162
|
+
staged: change.staged ?? status.staged,
|
|
163
|
+
stashed: change.stashed ?? status.stashed,
|
|
164
|
+
conflicted: change.conflicted ?? status.conflicted,
|
|
165
|
+
renamed: change.renamed ?? status.renamed,
|
|
166
|
+
deleted: change.deleted ?? status.deleted,
|
|
167
|
+
commit: change.commit ?? status.commit,
|
|
168
|
+
});
|
|
169
|
+
|
|
121
170
|
export function parseFileLines(lines: ReadonlyArray<string>): FileCounts {
|
|
122
171
|
const counts = FileCounts.empty();
|
|
123
172
|
for (const line of lines) {
|
|
@@ -154,7 +203,10 @@ export function parseStashCount(output: string): number {
|
|
|
154
203
|
* output. (A non-zero exit with empty stdout is the silent not-a-repository
|
|
155
204
|
* case and returns the empty status instead of this error.)
|
|
156
205
|
*/
|
|
157
|
-
export class GitStatusError extends Schema.TaggedError<
|
|
206
|
+
export class GitStatusError extends Schema.TaggedError<
|
|
207
|
+
GitStatusError,
|
|
208
|
+
{ readonly brand: unique symbol }
|
|
209
|
+
>()("GitStatusError", {
|
|
158
210
|
cwd: Schema.String,
|
|
159
211
|
command: Schema.String,
|
|
160
212
|
exitCode: Schema.Int,
|
|
@@ -205,7 +257,7 @@ export class GitStatusService extends Context.Service<
|
|
|
205
257
|
options?: GitStatusOptions,
|
|
206
258
|
) => Effect.Effect<GitStatus, GitError, GitExecutionService>;
|
|
207
259
|
}
|
|
208
|
-
>()("tui/git/GitStatusService") {
|
|
260
|
+
>()("@ftrdotdev/pi-tui/commands/git-status/GitStatusService") {
|
|
209
261
|
/** The status service over the execution service. */
|
|
210
262
|
static readonly layer = Layer.effect(
|
|
211
263
|
GitStatusService,
|
|
@@ -229,7 +281,7 @@ export class GitStatusService extends Context.Service<
|
|
|
229
281
|
// Not a repository / no output: silent empty status.
|
|
230
282
|
return TerminalOutcome.make({ status: GitStatus.empty() });
|
|
231
283
|
}
|
|
232
|
-
return yield*
|
|
284
|
+
return yield* GitStatusError.make({
|
|
233
285
|
cwd,
|
|
234
286
|
command: PRIMARY_COMMAND,
|
|
235
287
|
exitCode: primary.exitCode,
|
|
@@ -240,16 +292,14 @@ export class GitStatusService extends Context.Service<
|
|
|
240
292
|
let status = GitStatus.empty();
|
|
241
293
|
const lines = primary.stdout.split("\n");
|
|
242
294
|
const branchLine = lines.find((line) => line.startsWith("## "));
|
|
243
|
-
if (branchLine) {
|
|
295
|
+
if (isNonEmptyString(branchLine)) {
|
|
244
296
|
const parsed = parseBranchLine(branchLine);
|
|
245
297
|
if (parsed.detached) {
|
|
246
|
-
status =
|
|
247
|
-
...status,
|
|
298
|
+
status = withStatus(status, {
|
|
248
299
|
commit: GitCommitInfo.make({ oid: null, detached: true, tag: null }),
|
|
249
300
|
});
|
|
250
301
|
} else {
|
|
251
|
-
status =
|
|
252
|
-
...status,
|
|
302
|
+
status = withStatus(status, {
|
|
253
303
|
branch: parsed.name,
|
|
254
304
|
ahead: parsed.ahead,
|
|
255
305
|
behind: parsed.behind,
|
|
@@ -258,9 +308,13 @@ export class GitStatusService extends Context.Service<
|
|
|
258
308
|
}
|
|
259
309
|
const counts = parseFileLines(lines);
|
|
260
310
|
return ContinueOutcome.make({
|
|
261
|
-
status:
|
|
262
|
-
|
|
263
|
-
|
|
311
|
+
status: withStatus(status, {
|
|
312
|
+
modified: counts.modified,
|
|
313
|
+
untracked: counts.untracked,
|
|
314
|
+
staged: counts.staged,
|
|
315
|
+
conflicted: counts.conflicted,
|
|
316
|
+
renamed: counts.renamed,
|
|
317
|
+
deleted: counts.deleted,
|
|
264
318
|
}),
|
|
265
319
|
});
|
|
266
320
|
});
|
|
@@ -295,19 +349,17 @@ export class GitStatusService extends Context.Service<
|
|
|
295
349
|
const outcome = yield* interpretPrimary(primary, cwd);
|
|
296
350
|
return yield* Match.value(outcome).pipe(
|
|
297
351
|
Match.tags({
|
|
298
|
-
Continue: ()
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
if (!base.commit?.detached) return base;
|
|
352
|
+
Continue: Effect.fnUntraced(function* () {
|
|
353
|
+
const stashed = yield* readStash(cwd);
|
|
354
|
+
const base = withStatus(outcome.status, { stashed });
|
|
355
|
+
if (!(base.commit?.detached ?? false)) return base;
|
|
303
356
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
}),
|
|
357
|
+
const oid = yield* readCommitOid(cwd);
|
|
358
|
+
const tag = (options.readTag ?? false) ? yield* readCommitTag(cwd) : null;
|
|
359
|
+
return withStatus(base, {
|
|
360
|
+
commit: GitCommitInfo.make({ oid, detached: true, tag }),
|
|
361
|
+
});
|
|
362
|
+
}),
|
|
311
363
|
Terminal: () => Effect.succeed(outcome.status),
|
|
312
364
|
}),
|
|
313
365
|
Match.exhaustive,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assert, it } from "@effect/vitest";
|
|
2
|
-
import
|
|
2
|
+
import { themeDouble } from "@ftrdotdev/pi-test-kit";
|
|
3
3
|
import type { Component } from "@earendil-works/pi-tui";
|
|
4
4
|
import { makeBorderedBox } from "./bordered-box.ts";
|
|
5
5
|
|
|
@@ -10,25 +10,22 @@ const lines = (content: string[]): Component => ({
|
|
|
10
10
|
});
|
|
11
11
|
|
|
12
12
|
// Identity theme for structural assertions.
|
|
13
|
-
const plainTheme =
|
|
14
|
-
fg: (_color: string, text: string) => text,
|
|
15
|
-
bg: (_color: string, text: string) => text,
|
|
16
|
-
bold: (text: string) => text,
|
|
17
|
-
style: (text: string) => text,
|
|
18
|
-
} as unknown as Theme;
|
|
13
|
+
const plainTheme = themeDouble();
|
|
19
14
|
|
|
20
15
|
// Marker theme for color and background assertions.
|
|
21
|
-
const markerTheme = {
|
|
22
|
-
fg: (color
|
|
23
|
-
bg: (color
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
const markerTheme = themeDouble({
|
|
17
|
+
fg: (color, text) => `<${color}>${text}</${color}>`,
|
|
18
|
+
bg: (color, text) => `[${color}]${text}[/${color}]`,
|
|
19
|
+
style: (text, options) => {
|
|
20
|
+
// Only token strings are marked; a concrete terminal color stays unmarked.
|
|
21
|
+
const fg = typeof options.fg === "string" ? options.fg : undefined;
|
|
22
|
+
const bg = typeof options.bg === "string" ? options.bg : undefined;
|
|
26
23
|
let out = text;
|
|
27
|
-
if (
|
|
28
|
-
if (
|
|
24
|
+
if (fg !== undefined) out = `<${fg}>${out}</${fg}>`;
|
|
25
|
+
if (bg !== undefined) out = `[${bg}]${out}[/${bg}]`;
|
|
29
26
|
return out;
|
|
30
27
|
},
|
|
31
|
-
}
|
|
28
|
+
});
|
|
32
29
|
|
|
33
30
|
it("renders top and bottom borders with the content rail-wrapped between them", () => {
|
|
34
31
|
const out = makeBorderedBox(lines(["hi"]), plainTheme).render(12);
|
|
@@ -65,22 +65,26 @@ export const makeBorderedBox = (
|
|
|
65
65
|
const computeLines = (width: number): string[] => {
|
|
66
66
|
const label = typeof options.label === "function" ? options.label(theme) : options.label;
|
|
67
67
|
const frame = buildBoxFrame(width, {
|
|
68
|
-
label,
|
|
69
|
-
|
|
70
|
-
labelSuffix: options.labelSuffix,
|
|
68
|
+
...(label === undefined ? {} : { label, labelWidth: visibleWidth(label) }),
|
|
69
|
+
...(options.labelSuffix === undefined ? {} : { labelSuffix: options.labelSuffix }),
|
|
71
70
|
paddingX: options.paddingX ?? 1,
|
|
72
71
|
});
|
|
73
|
-
if (
|
|
72
|
+
if (frame === null) return [];
|
|
74
73
|
|
|
75
74
|
// Border chrome carries the foreground token and the background in one
|
|
76
75
|
// `theme.style()` call. Body content styles itself, so it only needs the
|
|
77
76
|
// background wrapper; the wrapper also covers the embedded label, which
|
|
78
77
|
// `composeBorderLine` passes through raw (already pre-themed by callers).
|
|
79
|
-
const
|
|
78
|
+
const background = options.bg;
|
|
79
|
+
const paint = (s: string) =>
|
|
80
|
+
theme.style(s, {
|
|
81
|
+
fg: options.color ?? "accent",
|
|
82
|
+
...(background === undefined ? {} : { bg: background }),
|
|
83
|
+
});
|
|
80
84
|
const bg =
|
|
81
|
-
|
|
85
|
+
background === undefined
|
|
82
86
|
? (s: string) => s
|
|
83
|
-
: (s: string) => theme.style(s, { bg:
|
|
87
|
+
: (s: string) => theme.style(s, { bg: background });
|
|
84
88
|
const pad = frame.padLeft;
|
|
85
89
|
|
|
86
90
|
const top = bg(composeBorderLine(frame, "top", paint));
|
|
@@ -6,7 +6,7 @@ import type { Component } from "@earendil-works/pi-tui";
|
|
|
6
6
|
* optional lifecycle hooks.
|
|
7
7
|
*/
|
|
8
8
|
export interface ComponentMethods {
|
|
9
|
-
readonly render: (width: number) => string[];
|
|
9
|
+
readonly render: (width: number) => readonly string[];
|
|
10
10
|
readonly invalidate: () => void;
|
|
11
11
|
readonly handleInput?: (data: string) => void;
|
|
12
12
|
readonly dispose?: () => void;
|
package/src/components/index.ts
CHANGED
|
@@ -16,6 +16,13 @@
|
|
|
16
16
|
*/
|
|
17
17
|
export { makeBorderedBox, type BorderedBoxOptions } from "./bordered-box.ts";
|
|
18
18
|
export { defineComponent, type ComponentMethods } from "./define-component.ts";
|
|
19
|
+
export {
|
|
20
|
+
makeRowList,
|
|
21
|
+
SELECTION_MARKER,
|
|
22
|
+
type SelectableRow,
|
|
23
|
+
type RowList,
|
|
24
|
+
type RowListOptions,
|
|
25
|
+
} from "./row-list.ts";
|
|
19
26
|
export {
|
|
20
27
|
buildBoxFrame,
|
|
21
28
|
composeBorderLine,
|