proofed-cli 0.0.0-stage → 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 +280 -2
- package/bin/node-version.cjs +11 -0
- package/bin/proofed.cjs +14 -0
- package/dist/args.js +156 -0
- package/dist/cache.js +48 -0
- package/dist/cdp.js +46 -0
- package/dist/changes.js +59 -0
- package/dist/check.js +338 -0
- package/dist/children.js +33 -0
- package/dist/chrome.js +77 -0
- package/dist/clip.js +270 -0
- package/dist/doctor.js +133 -0
- package/dist/github.js +143 -0
- package/dist/help.js +122 -0
- package/dist/kane.js +75 -0
- package/dist/list.js +82 -0
- package/dist/live.js +139 -0
- package/dist/livefile.js +83 -0
- package/dist/log.js +7 -0
- package/dist/models.js +44 -0
- package/dist/pipeline.js +194 -0
- package/dist/precheck.js +111 -0
- package/dist/proofed.js +70 -0
- package/dist/recorder.js +209 -0
- package/dist/render.js +425 -0
- package/dist/report.js +328 -0
- package/dist/requests.js +58 -0
- package/dist/result.js +135 -0
- package/dist/run.js +147 -0
- package/dist/runfile.js +11 -0
- package/dist/scenarios.js +89 -0
- package/dist/serve.js +82 -0
- package/dist/server.js +24 -0
- package/dist/setuperror.js +11 -0
- package/dist/target.js +132 -0
- package/dist/which.js +28 -0
- package/package.json +44 -4
package/dist/render.js
ADDED
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
// What `proofed check` shows while it runs and when it's done. In a terminal (LiveView): a header,
|
|
2
|
+
// one line per scenario redrawn in place, then what broke. Anywhere else (PlainView), for coding
|
|
3
|
+
// agents and logs: no escape codes and no redraw, one line per event, a heartbeat at least every 30
|
|
4
|
+
// seconds, then the same details. Colour is drawn by hand; there are no runtime dependencies.
|
|
5
|
+
import { FAILED_CHECK_REASON } from "./runfile.js";
|
|
6
|
+
import { outcomeOf } from "./result.js";
|
|
7
|
+
// FORCE_COLOR=0 and NO_COLOR turn colour off, FORCE_COLOR=1 turns it on, even in a pipe.
|
|
8
|
+
export function colorOn(env, isTTY) {
|
|
9
|
+
const force = env.FORCE_COLOR;
|
|
10
|
+
if (force !== undefined && force !== "")
|
|
11
|
+
return !["0", "false"].includes(force.toLowerCase());
|
|
12
|
+
if (env.NO_COLOR)
|
|
13
|
+
return false;
|
|
14
|
+
return isTTY && env.TERM !== "dumb";
|
|
15
|
+
}
|
|
16
|
+
export function palette(on) {
|
|
17
|
+
const sgr = (open, close) => (s) => (on && s ? `\x1b[${open}m${s}\x1b[${close}m` : s);
|
|
18
|
+
return {
|
|
19
|
+
bold: sgr(1, 22),
|
|
20
|
+
dim: sgr(2, 22),
|
|
21
|
+
red: sgr(31, 39),
|
|
22
|
+
green: sgr(32, 39),
|
|
23
|
+
yellow: sgr(33, 39),
|
|
24
|
+
magenta: sgr(35, 39),
|
|
25
|
+
cyan: sgr(36, 39),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const ANSI = /\x1b\[[0-9;?]*[A-Za-z]/g;
|
|
29
|
+
const WIDE = /\p{Emoji_Presentation}|[\u1100-\u115f\u2e80-\u303e\u3041-\ua4cf\uac00-\ud7a3\uf900-\ufaff\ufe30-\ufe4f\uff00-\uff60\uffe0-\uffe6]/u;
|
|
30
|
+
const ZERO = /[\p{Mn}\p{Me}\u200b-\u200f\ufe0f]/u;
|
|
31
|
+
const charWidth = (ch) => (ZERO.test(ch) ? 0 : WIDE.test(ch) ? 2 : 1);
|
|
32
|
+
export const stripAnsi = (s) => s.replace(ANSI, "");
|
|
33
|
+
// Columns the text takes in a terminal.
|
|
34
|
+
export const textWidth = (s) => [...stripAnsi(s)].reduce((w, ch) => w + charWidth(ch), 0);
|
|
35
|
+
// Cut plain text to `max` columns, ending in … when cut.
|
|
36
|
+
export function truncate(s, max) {
|
|
37
|
+
const flat = s.replace(/[\r\n\t]+/g, " ");
|
|
38
|
+
if (textWidth(flat) <= max)
|
|
39
|
+
return flat;
|
|
40
|
+
if (max <= 0)
|
|
41
|
+
return "";
|
|
42
|
+
let out = "";
|
|
43
|
+
let w = 0;
|
|
44
|
+
for (const ch of flat) {
|
|
45
|
+
if (w + charWidth(ch) > max - 1)
|
|
46
|
+
break;
|
|
47
|
+
out += ch;
|
|
48
|
+
w += charWidth(ch);
|
|
49
|
+
}
|
|
50
|
+
return `${out}…`;
|
|
51
|
+
}
|
|
52
|
+
export const clock = (seconds) => `${Math.floor(seconds / 60)}:${String(Math.floor(seconds % 60)).padStart(2, "0")}`;
|
|
53
|
+
export const duration = (seconds) => (seconds < 60 ? `${seconds}s` : `${Math.floor(seconds / 60)}m ${seconds % 60}s`);
|
|
54
|
+
const num = (n) => (Number.isInteger(n) ? String(n) : n.toFixed(1));
|
|
55
|
+
export const credits = (n) => n === 0 ? "no credits reported" : `${num(n)} credit${n === 1 ? "" : "s"}`;
|
|
56
|
+
// "14:05" today, "Nov 14 14:05" before.
|
|
57
|
+
export function since(iso, now = Date.now()) {
|
|
58
|
+
const d = new Date(iso);
|
|
59
|
+
const hm = `${String(d.getHours()).padStart(2, "0")}:${String(d.getMinutes()).padStart(2, "0")}`;
|
|
60
|
+
return new Date(now).toDateString() === d.toDateString() ? hm : `${d.toLocaleString("en", { month: "short" })} ${d.getDate()} ${hm}`;
|
|
61
|
+
}
|
|
62
|
+
export const GLYPH = { passed: "✓", failed: "✗", not_checked: "?", error: "!" };
|
|
63
|
+
export const WORD = { passed: "passed", failed: "failed", not_checked: "not checked", error: "error" };
|
|
64
|
+
const tint = (c, o) => ({ passed: c.green, failed: c.red, not_checked: c.yellow, error: c.magenta })[o];
|
|
65
|
+
const NOT_CHECKED = {
|
|
66
|
+
nothing_asserted: 'Kane finished without asserting anything on the page. Make the scenario end in a concrete check ("Check that …").',
|
|
67
|
+
scenario_doubted: "Kane thinks the scenario text is wrong, not the app. Read what it saw, then fix the scenario or the app.",
|
|
68
|
+
};
|
|
69
|
+
// What a scenario that didn't pass needs explained, label by label.
|
|
70
|
+
export function details(d, c) {
|
|
71
|
+
if (d.outcome === "passed" || d.outcome === "would_run")
|
|
72
|
+
return [];
|
|
73
|
+
const o = d.outcome;
|
|
74
|
+
const lines = [`${tint(c, o)(GLYPH[o])} ${c.bold(d.name)} ${tint(c, o)(WORD[o])}${d.seconds !== undefined ? c.dim(` after ${clock(d.seconds)}`) : ""}`];
|
|
75
|
+
const field = (label, value) => {
|
|
76
|
+
if (!value?.trim())
|
|
77
|
+
return;
|
|
78
|
+
const [first, ...rest] = value.trim().split("\n");
|
|
79
|
+
lines.push(` ${c.dim(label.padEnd(12))}${first}`, ...rest.map((l) => ` ${" ".repeat(12)}${l}`));
|
|
80
|
+
};
|
|
81
|
+
if (d.notChecked)
|
|
82
|
+
field("Why", NOT_CHECKED[d.notChecked]);
|
|
83
|
+
if (o === "error")
|
|
84
|
+
field("Why", "Kane couldn't finish the run. It says nothing about the app; run it again.");
|
|
85
|
+
field("Kane saw", d.reason);
|
|
86
|
+
if (d.failedCheck)
|
|
87
|
+
field("Why", FAILED_CHECK_REASON);
|
|
88
|
+
field(d.failedCheck ? "Kane thinks" : "Diagnosis", d.diagnosis);
|
|
89
|
+
field(d.failedCheck ? "Next" : "Suggestion", d.suggestion);
|
|
90
|
+
field("Failed step", d.failedStep);
|
|
91
|
+
field("Page error", d.pageError);
|
|
92
|
+
field("Clip", d.clip?.mp4 ?? d.clip?.jpg);
|
|
93
|
+
field("Scenario", d.file);
|
|
94
|
+
return lines;
|
|
95
|
+
}
|
|
96
|
+
// The closing lines: details for what didn't pass, one summary line, the command to re-run.
|
|
97
|
+
export function ending(doc, c) {
|
|
98
|
+
const lines = [];
|
|
99
|
+
for (const d of doc.scenarios) {
|
|
100
|
+
const more = details(d, c);
|
|
101
|
+
if (more.length)
|
|
102
|
+
lines.push("", ...more);
|
|
103
|
+
}
|
|
104
|
+
const { passed, failed, not_checked, error } = doc.counts;
|
|
105
|
+
const parts = [
|
|
106
|
+
passed && c.green(`${passed} passed`),
|
|
107
|
+
failed && c.red(`${failed} failed`),
|
|
108
|
+
not_checked && c.yellow(`${not_checked} not checked`),
|
|
109
|
+
error && c.magenta(`${error} error${error === 1 ? "" : "s"}`),
|
|
110
|
+
].filter((p) => !!p);
|
|
111
|
+
const glyph = doc.exitCode === 1 ? c.red("✗") : doc.exitCode === 2 ? c.yellow("?") : c.green("✓");
|
|
112
|
+
const tally = parts.length ? parts.join(", ") : doc.summary;
|
|
113
|
+
// Cached passes ran nothing: zero is the whole cost, not a number Kane left out.
|
|
114
|
+
const ranNow = doc.scenarios.some((d) => !d.cached);
|
|
115
|
+
lines.push("", `${glyph} ${c.bold(tally)}${c.dim(` · ${ranNow ? credits(doc.credits) : "0 credits"} · ${duration(doc.seconds)}`)}`);
|
|
116
|
+
if (ranNow)
|
|
117
|
+
lines.push("Credits are Kane's report; balance may drop slightly more.");
|
|
118
|
+
if (parts.length && doc.exitCode !== 0)
|
|
119
|
+
lines.push(doc.summary);
|
|
120
|
+
if (doc.rerun)
|
|
121
|
+
lines.push(`Re-run what broke: ${c.bold(doc.rerun)}`);
|
|
122
|
+
return lines;
|
|
123
|
+
}
|
|
124
|
+
// "about 1 to 4 minutes per scenario, 3 at a time, so 2 to 8 minutes in all"
|
|
125
|
+
export function timing(count, concurrency) {
|
|
126
|
+
const rounds = Math.ceil(count / Math.max(1, concurrency));
|
|
127
|
+
return `about 1 to 4 minutes per scenario, ${concurrency} at a time, so ${rounds} to ${rounds * 4} minutes in all`;
|
|
128
|
+
}
|
|
129
|
+
// Where each scenario is, from the run's events.
|
|
130
|
+
export class Board {
|
|
131
|
+
rows;
|
|
132
|
+
constructor(plan) {
|
|
133
|
+
this.rows = [
|
|
134
|
+
...plan.cached.map((s) => ({ id: s.id, name: s.name, state: "cached", outcome: "passed", cachedAt: s.cachedAt })),
|
|
135
|
+
...plan.run.map((s) => ({ id: s.id, name: s.name, state: "waiting" })),
|
|
136
|
+
];
|
|
137
|
+
}
|
|
138
|
+
row(id) {
|
|
139
|
+
return this.rows.find((r) => r.id === id);
|
|
140
|
+
}
|
|
141
|
+
apply(e, now) {
|
|
142
|
+
const row = this.row(e.id);
|
|
143
|
+
if (!row)
|
|
144
|
+
return;
|
|
145
|
+
if (e.type === "started")
|
|
146
|
+
Object.assign(row, { state: "running", startedAt: now });
|
|
147
|
+
if (e.type === "step" && e.step.remark)
|
|
148
|
+
Object.assign(row, { remark: e.step.remark, retry: undefined });
|
|
149
|
+
if (e.type === "retry")
|
|
150
|
+
Object.assign(row, { retry: e.error, remark: undefined });
|
|
151
|
+
if (e.type === "finished") {
|
|
152
|
+
Object.assign(row, { state: "done", outcome: outcomeOf(e.result), credits: e.result.end?.credits_consumed ?? 0, seconds: e.result.seconds ?? 0 });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
running() {
|
|
156
|
+
return this.rows.filter((r) => r.state === "running");
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function planLines(p, c) {
|
|
160
|
+
const lines = [
|
|
161
|
+
`${c.bold("Proofed")}${p.dryRun ? " (dry run)" : ""}: ${p.dryRun ? "would check" : "checking"} ${p.run.length} of ${p.total} scenario(s), ${p.selection}${p.url ? `, at ${p.url}` : ""}.`,
|
|
162
|
+
];
|
|
163
|
+
if (p.run.length)
|
|
164
|
+
lines.push(`Estimate: about ${num(p.estimate)} Kane credits.`);
|
|
165
|
+
if (p.cached.length)
|
|
166
|
+
lines.push(`Cached passes, 0 credits: ${p.cached.map((s) => s.name).join(", ")}.`);
|
|
167
|
+
return lines;
|
|
168
|
+
}
|
|
169
|
+
export const errorLines = (doc, c) => [`${c.red("✗")} ${doc.error.message}`, ` ${c.dim("Fix")} ${doc.error.fix}`];
|
|
170
|
+
export class PlainView {
|
|
171
|
+
out;
|
|
172
|
+
err;
|
|
173
|
+
c;
|
|
174
|
+
now;
|
|
175
|
+
heartbeat;
|
|
176
|
+
board;
|
|
177
|
+
started = 0;
|
|
178
|
+
lastLine = 0;
|
|
179
|
+
timer;
|
|
180
|
+
// Progress only: the details, the summary and an error are left to the JSON document.
|
|
181
|
+
brief;
|
|
182
|
+
constructor(out, o) {
|
|
183
|
+
this.out = out;
|
|
184
|
+
this.err = o.err ?? out;
|
|
185
|
+
this.c = palette(o.color);
|
|
186
|
+
this.now = o.now ?? Date.now;
|
|
187
|
+
this.heartbeat = o.heartbeat ?? 25_000;
|
|
188
|
+
this.brief = o.brief ?? false;
|
|
189
|
+
}
|
|
190
|
+
line(s) {
|
|
191
|
+
this.out.write(`${s}\n`);
|
|
192
|
+
this.lastLine = this.now();
|
|
193
|
+
}
|
|
194
|
+
stamp(s) {
|
|
195
|
+
this.line(`[${clock(Math.round((this.now() - this.started) / 1000))}] ${s}`);
|
|
196
|
+
}
|
|
197
|
+
plan(p) {
|
|
198
|
+
this.board = new Board(p);
|
|
199
|
+
for (const l of planLines(p, this.c))
|
|
200
|
+
this.line(l);
|
|
201
|
+
if (p.run.length && !p.dryRun)
|
|
202
|
+
this.line(`Time: ${timing(p.run.length, p.concurrency)}. Do not interrupt: let it finish.`);
|
|
203
|
+
}
|
|
204
|
+
info(s) {
|
|
205
|
+
this.line(s);
|
|
206
|
+
}
|
|
207
|
+
phase(s) {
|
|
208
|
+
this.line(s);
|
|
209
|
+
}
|
|
210
|
+
start() {
|
|
211
|
+
this.started = this.lastLine = this.now();
|
|
212
|
+
this.timer = setInterval(() => this.tick(), 1000);
|
|
213
|
+
}
|
|
214
|
+
tick() {
|
|
215
|
+
if (!this.board || this.now() - this.lastLine < this.heartbeat)
|
|
216
|
+
return;
|
|
217
|
+
const at = (r) => clock(Math.round((this.now() - (r.startedAt ?? this.started)) / 1000));
|
|
218
|
+
const running = this.board.running().map((r) => `${r.id} ${at(r)}${r.remark ? ` at "${truncate(r.remark, 80)}"` : ""}`);
|
|
219
|
+
const waiting = this.board.rows.filter((r) => r.state === "waiting").map((r) => r.id);
|
|
220
|
+
this.stamp(`still running: ${running.join("; ") || "starting Chrome"}${waiting.length ? `. Waiting: ${waiting.join(", ")}` : ""}`);
|
|
221
|
+
}
|
|
222
|
+
event(e) {
|
|
223
|
+
const row = this.board?.row(e.id);
|
|
224
|
+
this.board?.apply(e, this.now());
|
|
225
|
+
if (!row)
|
|
226
|
+
return;
|
|
227
|
+
if (e.type === "started")
|
|
228
|
+
this.stamp(`started ${row.id}: ${row.name}`);
|
|
229
|
+
if (e.type === "retry")
|
|
230
|
+
this.stamp(`retrying ${row.id}: ${truncate(e.error, 160)}`);
|
|
231
|
+
if (e.type === "finished" && row.outcome) {
|
|
232
|
+
this.stamp(`${tint(this.c, row.outcome)(WORD[row.outcome])} ${row.id}: ${row.name} (${clock(row.seconds ?? 0)}, ${credits(row.credits ?? 0)})`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
done(doc) {
|
|
236
|
+
this.close();
|
|
237
|
+
if (!this.brief)
|
|
238
|
+
for (const l of ending(doc, this.c))
|
|
239
|
+
this.line(l);
|
|
240
|
+
}
|
|
241
|
+
fail(doc) {
|
|
242
|
+
this.close();
|
|
243
|
+
if (!this.brief)
|
|
244
|
+
for (const l of errorLines(doc, this.c))
|
|
245
|
+
this.err.write(`${l}\n`);
|
|
246
|
+
}
|
|
247
|
+
log(s) {
|
|
248
|
+
this.err.write(`${s}\n`);
|
|
249
|
+
}
|
|
250
|
+
close() {
|
|
251
|
+
clearInterval(this.timer);
|
|
252
|
+
this.timer = undefined;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
const SPINNER = "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏";
|
|
256
|
+
const HIDE = "\x1b[?25l";
|
|
257
|
+
const SHOW = "\x1b[?25h";
|
|
258
|
+
export class LiveView {
|
|
259
|
+
out;
|
|
260
|
+
err;
|
|
261
|
+
c;
|
|
262
|
+
now;
|
|
263
|
+
board;
|
|
264
|
+
phaseText;
|
|
265
|
+
phaseAt = 0;
|
|
266
|
+
// Columns of each line last drawn, to know how many rows to go back up after a resize.
|
|
267
|
+
drawn = [];
|
|
268
|
+
timer;
|
|
269
|
+
hidden = false;
|
|
270
|
+
settled = false;
|
|
271
|
+
// The scenario rows show from start() on: a build that fails before it has no rows to leave behind.
|
|
272
|
+
started = false;
|
|
273
|
+
// After stop() nothing is drawn again: a late resize would otherwise erase the closing lines.
|
|
274
|
+
closed = false;
|
|
275
|
+
constructor(out, o) {
|
|
276
|
+
this.out = out;
|
|
277
|
+
this.err = o.err ?? out;
|
|
278
|
+
this.c = palette(o.color);
|
|
279
|
+
this.now = o.now ?? Date.now;
|
|
280
|
+
}
|
|
281
|
+
width() {
|
|
282
|
+
return Math.max(20, this.out.columns || 80);
|
|
283
|
+
}
|
|
284
|
+
plan(p) {
|
|
285
|
+
this.board = new Board(p);
|
|
286
|
+
const c = this.c;
|
|
287
|
+
const parts = [
|
|
288
|
+
`${p.dryRun ? "dry run: " : ""}${p.run.length} of ${p.total} scenario${p.total === 1 ? "" : "s"}`,
|
|
289
|
+
...(p.run.length ? [`~${num(p.estimate)} credits`] : []),
|
|
290
|
+
p.selection,
|
|
291
|
+
...(p.url ? [p.url] : []),
|
|
292
|
+
];
|
|
293
|
+
this.print(`${c.bold("proofed")} ${truncate(parts.join(" · "), this.width() - 10)}`);
|
|
294
|
+
if (p.run.length && !p.dryRun)
|
|
295
|
+
this.print(c.dim(truncate(timing(p.run.length, p.concurrency), this.width() - 1)));
|
|
296
|
+
}
|
|
297
|
+
// Also ends a phase: what it printed is its outcome.
|
|
298
|
+
info(s) {
|
|
299
|
+
this.phaseText = undefined;
|
|
300
|
+
this.print(this.c.dim(truncate(s, this.width() - 1)));
|
|
301
|
+
}
|
|
302
|
+
phase(s) {
|
|
303
|
+
this.phaseText = s;
|
|
304
|
+
this.phaseAt = this.now();
|
|
305
|
+
this.animate();
|
|
306
|
+
}
|
|
307
|
+
start() {
|
|
308
|
+
this.phaseText = undefined;
|
|
309
|
+
this.started = true;
|
|
310
|
+
this.animate();
|
|
311
|
+
}
|
|
312
|
+
event(e) {
|
|
313
|
+
this.board?.apply(e, this.now());
|
|
314
|
+
if (e.type === "finished")
|
|
315
|
+
this.draw();
|
|
316
|
+
}
|
|
317
|
+
done(doc) {
|
|
318
|
+
this.settled = true;
|
|
319
|
+
this.draw();
|
|
320
|
+
this.stop();
|
|
321
|
+
for (const l of ending(doc, this.c))
|
|
322
|
+
this.out.write(`${l}\n`);
|
|
323
|
+
}
|
|
324
|
+
fail(doc) {
|
|
325
|
+
this.phaseText = undefined;
|
|
326
|
+
this.draw();
|
|
327
|
+
this.stop();
|
|
328
|
+
for (const l of errorLines(doc, this.c))
|
|
329
|
+
this.err.write(`${l}\n`);
|
|
330
|
+
}
|
|
331
|
+
log(s) {
|
|
332
|
+
this.erase();
|
|
333
|
+
this.err.write(`${this.c.dim(s)}\n`);
|
|
334
|
+
this.draw();
|
|
335
|
+
}
|
|
336
|
+
close() {
|
|
337
|
+
this.stop();
|
|
338
|
+
}
|
|
339
|
+
// A line above the live block.
|
|
340
|
+
print(s) {
|
|
341
|
+
this.erase();
|
|
342
|
+
this.out.write(`${s}\n`);
|
|
343
|
+
this.draw();
|
|
344
|
+
}
|
|
345
|
+
animate() {
|
|
346
|
+
if (!this.hidden) {
|
|
347
|
+
this.out.write(HIDE);
|
|
348
|
+
this.hidden = true;
|
|
349
|
+
}
|
|
350
|
+
this.timer ??= setInterval(() => this.draw(), 80);
|
|
351
|
+
this.draw();
|
|
352
|
+
}
|
|
353
|
+
stop() {
|
|
354
|
+
clearInterval(this.timer);
|
|
355
|
+
this.timer = undefined;
|
|
356
|
+
if (this.hidden)
|
|
357
|
+
this.out.write(SHOW);
|
|
358
|
+
this.hidden = false;
|
|
359
|
+
this.closed = true;
|
|
360
|
+
this.drawn = [];
|
|
361
|
+
}
|
|
362
|
+
// Back to the top of the block and clear to the end of the screen. A line drawn wider than the
|
|
363
|
+
// terminal is now (it shrank) has wrapped, so it takes more than one row.
|
|
364
|
+
erase() {
|
|
365
|
+
const cols = this.out.columns || 80;
|
|
366
|
+
const up = this.drawn.reduce((n, w) => n + Math.max(1, Math.ceil(w / cols)), 0);
|
|
367
|
+
if (up)
|
|
368
|
+
this.out.write(`\x1b[${up}F\x1b[J`);
|
|
369
|
+
this.drawn = [];
|
|
370
|
+
}
|
|
371
|
+
draw() {
|
|
372
|
+
if (this.closed)
|
|
373
|
+
return;
|
|
374
|
+
const lines = this.lines();
|
|
375
|
+
this.erase();
|
|
376
|
+
if (!lines.length)
|
|
377
|
+
return;
|
|
378
|
+
this.out.write(`${lines.join("\n")}\n`);
|
|
379
|
+
this.drawn = lines.map(textWidth);
|
|
380
|
+
}
|
|
381
|
+
lines() {
|
|
382
|
+
const c = this.c;
|
|
383
|
+
const w = this.width() - 1;
|
|
384
|
+
const spin = SPINNER[Math.floor(this.now() / 80) % SPINNER.length];
|
|
385
|
+
if (this.phaseText !== undefined) {
|
|
386
|
+
const t = clock(Math.round((this.now() - this.phaseAt) / 1000));
|
|
387
|
+
return [`${c.cyan(spin)} ${truncate(this.phaseText, w - t.length - 4)} ${c.dim(t)}`];
|
|
388
|
+
}
|
|
389
|
+
if (!this.board || (!this.started && !this.settled))
|
|
390
|
+
return [];
|
|
391
|
+
let rows = this.board.rows;
|
|
392
|
+
// Taller than the terminal: redrawing would scroll. The running ones stay, the rest are counted.
|
|
393
|
+
const room = Math.max(3, (this.out.rows || 24) - 2);
|
|
394
|
+
let rest = "";
|
|
395
|
+
if (rows.length > room) {
|
|
396
|
+
const keep = rows.filter((r) => r.state === "running").slice(0, room - 1);
|
|
397
|
+
const other = rows.filter((r) => !keep.includes(r));
|
|
398
|
+
const n = (s) => other.filter((r) => r.state === s).length;
|
|
399
|
+
rest = c.dim(truncate(` … ${n("done") + n("cached")} done, ${n("waiting")} waiting`, w));
|
|
400
|
+
rows = keep;
|
|
401
|
+
}
|
|
402
|
+
return [...rows.map((r) => this.rowLine(r, w, spin)), ...(rest ? [rest] : [])];
|
|
403
|
+
}
|
|
404
|
+
rowLine(r, w, spin) {
|
|
405
|
+
const c = this.c;
|
|
406
|
+
const name = (room) => truncate(r.name, Math.max(8, Math.min(room, Math.floor(w * 0.5))));
|
|
407
|
+
if (r.state === "waiting")
|
|
408
|
+
return c.dim(truncate(`· ${r.name} waiting`, w));
|
|
409
|
+
if (r.state === "cached") {
|
|
410
|
+
const n = name(w - 2);
|
|
411
|
+
return `${c.green("✓")} ${n} ${c.dim(truncate(`cached, unchanged since ${since(r.cachedAt ?? "", this.now())}`, w - 4 - textWidth(n)))}`;
|
|
412
|
+
}
|
|
413
|
+
if (r.state === "done" && r.outcome) {
|
|
414
|
+
const n = name(w - 2);
|
|
415
|
+
const tail = truncate(`${clock(r.seconds ?? 0)} · ${credits(r.credits ?? 0)}`, w - 4 - textWidth(n));
|
|
416
|
+
return `${tint(c, r.outcome)(GLYPH[r.outcome])} ${n} ${c.dim(tail)}`;
|
|
417
|
+
}
|
|
418
|
+
const t = clock(Math.round((this.now() - (r.startedAt ?? this.now())) / 1000));
|
|
419
|
+
const n = name(w - 4 - t.length);
|
|
420
|
+
const room = w - 2 - textWidth(n) - 2 - t.length - 2;
|
|
421
|
+
const said = r.retry ? `retrying: ${r.retry}` : (r.remark ?? "starting Chrome");
|
|
422
|
+
const remark = room >= 6 ? ` ${(r.retry ? c.yellow : c.dim)(truncate(said, room))}` : "";
|
|
423
|
+
return `${c.cyan(spin)} ${c.bold(n)} ${t}${remark}`;
|
|
424
|
+
}
|
|
425
|
+
}
|