@osdlc/wayfinder 0.7.1 → 0.7.2
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 +23 -0
- package/README.md +210 -182
- package/SECURITY.md +39 -1
- package/bin/way.js +14 -9
- package/dist/args.d.ts +16 -16
- package/dist/args.js +19 -19
- package/dist/cache.js +3 -4
- package/dist/clean-command.d.ts +18 -18
- package/dist/clean-command.js +35 -36
- package/dist/cli.d.ts +19 -20
- package/dist/cli.js +76 -69
- package/dist/config-command.d.ts +15 -14
- package/dist/config-command.js +63 -59
- package/dist/config.d.ts +135 -130
- package/dist/config.js +156 -149
- package/dist/devlink.d.ts +6 -2
- package/dist/devlink.js +7 -2
- package/dist/guide.js +5 -4
- package/dist/origin-owner.d.ts +7 -2
- package/dist/origin-owner.js +20 -4
- package/dist/providers-command.d.ts +1 -1
- package/dist/providers-command.js +11 -23
- package/dist/serve.d.ts +43 -42
- package/dist/serve.js +251 -258
- package/dist/terminal-text.d.ts +57 -0
- package/dist/terminal-text.js +91 -0
- package/dist/tools.d.ts +4 -4
- package/dist/tools.js +4 -4
- package/dist/trust-command.d.ts +6 -7
- package/dist/trust-command.js +48 -50
- package/dist/trust-store.d.ts +1 -1
- package/dist/tui.d.ts +65 -66
- package/dist/tui.js +124 -130
- package/dist/web/main.js +371 -386
- package/dist/web/page.html +6 -5
- package/dist/web/styles.css +258 -271
- package/package.json +7 -7
package/dist/tui.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The terminal UI
|
|
2
|
+
* The terminal UI: browse every task in a repository, and run one.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* something to paste.
|
|
4
|
+
* Unlike the page, Enter runs the selected task in this shell and hands it the
|
|
5
|
+
* terminal. The page can only give you a command to paste.
|
|
7
6
|
*
|
|
8
|
-
*
|
|
9
|
-
* toolkit would
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* to
|
|
14
|
-
* the
|
|
15
|
-
* point of it, and that job is outside the seam by design.
|
|
7
|
+
* No dependencies: raw mode, ANSI, and one frame string per keystroke. A TUI
|
|
8
|
+
* toolkit would weigh more than the code it saves, and this has to keep
|
|
9
|
+
* working from a checkout whose node_modules is what you are trying to repair.
|
|
10
|
+
* The CLI sends its output through `CliIo` so `main()` can be tested without
|
|
11
|
+
* a real stream. This file writes to `process.stdout` directly, because its
|
|
12
|
+
* job is to control the terminal: raw mode, the alternate screen, and handing
|
|
13
|
+
* the terminal to a spawned task.
|
|
16
14
|
*
|
|
17
|
-
* Collection is
|
|
18
|
-
*
|
|
15
|
+
* Collection is async, which is what most of the state handling below is for:
|
|
16
|
+
* keystrokes arrive during a refresh, and a row can be stale.
|
|
19
17
|
*/
|
|
20
18
|
import { spawnRunner, streamRunner } from '@osdlc/command-seam';
|
|
21
19
|
import { tasks as allTasks, } from '@osdlc/system-model/detect';
|
|
@@ -29,6 +27,7 @@ import { collectAndCache, freshStates, fromStore, makeProject, orderedCatalog, r
|
|
|
29
27
|
import { loadConfig } from "./config.js";
|
|
30
28
|
import { appTrustStore } from "./trust-store.js";
|
|
31
29
|
import { groupOf, runnerLabel } from "./groups.js";
|
|
30
|
+
import { terminalSafe } from "./terminal-text.js";
|
|
32
31
|
// ---------------------------------------------------------------- ansi
|
|
33
32
|
const ALT_ON = '\x1b[?1049h';
|
|
34
33
|
const ALT_OFF = '\x1b[?1049l';
|
|
@@ -50,7 +49,9 @@ const hit = sgr('1;33');
|
|
|
50
49
|
/**
|
|
51
50
|
* Compose chunks into one line of exactly `width` columns. Truncation happens
|
|
52
51
|
* on the PLAIN text — measuring a string that already carries escape sequences
|
|
53
|
-
* counts the escapes as columns and wraps the line.
|
|
52
|
+
* counts the escapes as columns and wraps the line. Every chunk's text goes
|
|
53
|
+
* through {@link terminalSafe} first, so repository text never writes a
|
|
54
|
+
* control sequence; only `paint` adds escapes.
|
|
54
55
|
*/
|
|
55
56
|
function line(chunks, width) {
|
|
56
57
|
let used = 0;
|
|
@@ -58,7 +59,7 @@ function line(chunks, width) {
|
|
|
58
59
|
for (const chunk of chunks) {
|
|
59
60
|
if (used >= width)
|
|
60
61
|
break;
|
|
61
|
-
let text = chunk.text;
|
|
62
|
+
let text = terminalSafe(chunk.text);
|
|
62
63
|
if (used + text.length > width)
|
|
63
64
|
text = text.slice(0, Math.max(0, width - used - 1)) + '…';
|
|
64
65
|
used += text.length;
|
|
@@ -71,10 +72,10 @@ const ALL = 'all';
|
|
|
71
72
|
/**
|
|
72
73
|
* The module singleton.
|
|
73
74
|
*
|
|
74
|
-
* Exported for one reason
|
|
75
|
-
* the selection rule
|
|
76
|
-
*
|
|
77
|
-
* { recompute}. Nothing outside a test writes to it.
|
|
75
|
+
* Exported for one reason. `runTui` takes over a real terminal and never
|
|
76
|
+
* returns, so the selection rule (the selection must survive a refresh that
|
|
77
|
+
* reorders or drops rows under the cursor) can only be tested through this
|
|
78
|
+
* and {@link recompute}. Nothing outside a test writes to it.
|
|
78
79
|
*/
|
|
79
80
|
export const state = {
|
|
80
81
|
catalog: null,
|
|
@@ -106,7 +107,7 @@ export const state = {
|
|
|
106
107
|
function reportFor(runner) {
|
|
107
108
|
return state.catalog?.reports.find((r) => r.runner === runner);
|
|
108
109
|
}
|
|
109
|
-
/** How many runners
|
|
110
|
+
/** How many runners were not collected for lack of trust; 0 when trust is not the reason. */
|
|
110
111
|
function withheldForTrust() {
|
|
111
112
|
if (state.gate?.reason !== 'untrusted')
|
|
112
113
|
return 0;
|
|
@@ -126,15 +127,15 @@ function staleRunners() {
|
|
|
126
127
|
/**
|
|
127
128
|
* What the status line says about the rows on screen, in three states.
|
|
128
129
|
*
|
|
129
|
-
* Fresh says
|
|
130
|
-
* there is nothing
|
|
130
|
+
* Fresh says nothing. A line that is always shown is a line nobody reads,
|
|
131
|
+
* and there is nothing to report.
|
|
131
132
|
*
|
|
132
|
-
* Stale
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
133
|
+
* Stale and slow is kept apart from ordinary stale because it is the case the
|
|
134
|
+
* cache exists for. A runner measured at several seconds in this repository
|
|
135
|
+
* is why the screen would otherwise be empty. Showing it the same way as a
|
|
136
|
+
* 200ms refresh would hide the one warning that matters. Slowness is
|
|
137
|
+
* measured, never assumed: a runner that is quick here is not called slow
|
|
138
|
+
* because it is slow elsewhere.
|
|
138
139
|
*/
|
|
139
140
|
export function refreshNote(rows, loading) {
|
|
140
141
|
const stale = rows.filter((r) => r.state === 'stale');
|
|
@@ -146,8 +147,7 @@ export function refreshNote(rows, loading) {
|
|
|
146
147
|
const slow = stale.filter((r) => r.slow);
|
|
147
148
|
if (!loading) {
|
|
148
149
|
// The refresh is over and these rows are still what the store held: it
|
|
149
|
-
// failed, or it has not been asked for yet.
|
|
150
|
-
// describe work nobody is doing.
|
|
150
|
+
// failed, or it has not been asked for yet. "re-probing" would be untrue.
|
|
151
151
|
return {
|
|
152
152
|
slow: slow.length > 0,
|
|
153
153
|
text: `cached rows: ${stale.map((r) => `${r.runner} ${humanAge(r.ageMs)}`).join(', ')} — ^r to re-probe`,
|
|
@@ -235,10 +235,10 @@ function chainChunks(row) {
|
|
|
235
235
|
/**
|
|
236
236
|
* The whole screen as one string.
|
|
237
237
|
*
|
|
238
|
-
* Exported
|
|
239
|
-
*
|
|
240
|
-
* them
|
|
241
|
-
*
|
|
238
|
+
* Exported with {@link state} and {@link recompute} so tests can check the
|
|
239
|
+
* three cache states in the rendered lines, not only in the helper that
|
|
240
|
+
* builds them. The user reads the status line, and a correct note placed in
|
|
241
|
+
* the wrong line helps nobody.
|
|
242
242
|
*/
|
|
243
243
|
export function frame(width, height) {
|
|
244
244
|
const out = [];
|
|
@@ -250,10 +250,10 @@ export function frame(width, height) {
|
|
|
250
250
|
const count = name === ALL
|
|
251
251
|
? (state.catalog?.reports ?? []).reduce((n, r) => n + r.tasks.length, 0)
|
|
252
252
|
: (reportFor(name)?.tasks.length ?? 0);
|
|
253
|
-
// Marked
|
|
254
|
-
//
|
|
255
|
-
//
|
|
256
|
-
//
|
|
253
|
+
// Marked on the tab, not per row. All of a runner's rows are the same age,
|
|
254
|
+
// so a per-row mark would repeat one fact many times, and the row
|
|
255
|
+
// renderer would have to know about the cache. A leading `~` reads as
|
|
256
|
+
// "about" and still shows under NO_COLOR.
|
|
257
257
|
const stale = name === ALL ? staleRunners().length > 0 : cacheFor(name)?.state === 'stale';
|
|
258
258
|
// A bar between groups: tasks, then dependencies, tools and git hooks.
|
|
259
259
|
const prev = tabs()[tabs().indexOf(name) - 1];
|
|
@@ -285,16 +285,16 @@ export function frame(width, height) {
|
|
|
285
285
|
...(state.loading && refreshNote(state.cache, true) === null
|
|
286
286
|
? [{ text: ' refreshing', paint: yellow }]
|
|
287
287
|
: []),
|
|
288
|
-
// The cache's three states. Fresh returns null and
|
|
289
|
-
//
|
|
290
|
-
// refresh note
|
|
288
|
+
// The cache's three states. Fresh returns null and shows nothing.
|
|
289
|
+
// Stale and slow is red, so it stands apart from an ordinary
|
|
290
|
+
// refresh note.
|
|
291
291
|
...(() => {
|
|
292
292
|
const note = refreshNote(state.cache, state.loading);
|
|
293
293
|
return note === null ? [] : [{ text: ` ${note.text}`, paint: note.slow ? red : yellow }];
|
|
294
294
|
})(),
|
|
295
295
|
...(state.message ? [{ text: ` ${state.message}`, paint: yellow }] : []),
|
|
296
|
-
// A note beside the counts, not a modal
|
|
297
|
-
// look at what is already collected
|
|
296
|
+
// A note beside the counts, not a modal, since you may only want to
|
|
297
|
+
// look at what is already collected.
|
|
298
298
|
...(state.confirmingTrust
|
|
299
299
|
? [{ text: ' trust this repository? y/n', paint: yellow }]
|
|
300
300
|
: withheldForTrust() > 0
|
|
@@ -309,9 +309,8 @@ export function frame(width, height) {
|
|
|
309
309
|
.filter((r) => r.status === 'error')
|
|
310
310
|
.map((r) => ({ text: ` ${r.runner} failed`, paint: red })),
|
|
311
311
|
], width));
|
|
312
|
-
// 4a. the settings screen, which
|
|
313
|
-
// a
|
|
314
|
-
// one, so nothing below it renders.
|
|
312
|
+
// 4a. the settings screen, which replaces the list while it is open. It is
|
|
313
|
+
// a separate view, not an overlay, so nothing below it renders.
|
|
315
314
|
if (state.settings !== null) {
|
|
316
315
|
const room = Math.max(1, height - out.length - 2);
|
|
317
316
|
for (let i = 0; i < room; i++) {
|
|
@@ -324,9 +323,9 @@ export function frame(width, height) {
|
|
|
324
323
|
out.push(line([{ text: `reading only — edit with \`${BIN} config set\` esc back`, paint: dim }], width));
|
|
325
324
|
return HOME + out.join('\r\n') + CLEAR_BELOW;
|
|
326
325
|
}
|
|
327
|
-
// 4. the list,
|
|
328
|
-
//
|
|
329
|
-
// arguments are
|
|
326
|
+
// 4. the list, in the rows left over. The entry line takes one more row
|
|
327
|
+
// than the key hints it replaces, so the list gives up a row while
|
|
328
|
+
// arguments are typed, and the bottom line stays on screen.
|
|
330
329
|
const listHeight = Math.max(1, height - out.length - (state.entering ? 5 : 4));
|
|
331
330
|
clampScroll(at, listHeight);
|
|
332
331
|
for (let i = 0; i < listHeight; i++) {
|
|
@@ -341,7 +340,7 @@ export function frame(width, height) {
|
|
|
341
340
|
...chainChunks(row),
|
|
342
341
|
], width));
|
|
343
342
|
}
|
|
344
|
-
// 5. what Enter would run
|
|
343
|
+
// 5. what Enter would run, always on screen
|
|
345
344
|
const current = state.rows[at];
|
|
346
345
|
out.push(line([{ text: '-'.repeat(width), paint: dim }], width));
|
|
347
346
|
if (current) {
|
|
@@ -362,10 +361,10 @@ export function frame(width, height) {
|
|
|
362
361
|
out.push(line([{ text: state.query ? 'no match' : 'nothing collected', paint: dim }], width));
|
|
363
362
|
out.push(line([], width));
|
|
364
363
|
}
|
|
365
|
-
// 6. keys
|
|
366
|
-
//
|
|
367
|
-
//
|
|
368
|
-
//
|
|
364
|
+
// 6. keys, or the entry line in their place while arguments are typed. It
|
|
365
|
+
// replaces the key hints rather than sitting above them, because the only
|
|
366
|
+
// keys that matter while typing are the two this line names, and an extra
|
|
367
|
+
// row would push the list up.
|
|
369
368
|
if (state.entering) {
|
|
370
369
|
const { task, text } = state.entering;
|
|
371
370
|
const shape = paramShape(task.parameters);
|
|
@@ -399,10 +398,10 @@ function clampScroll(at, listHeight) {
|
|
|
399
398
|
* Rebuild the visible rows and re-anchor the selection onto a task that is
|
|
400
399
|
* still there.
|
|
401
400
|
*
|
|
402
|
-
* Split out of {@link draw} so it can be
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
*
|
|
401
|
+
* Split out of {@link draw} so it can be tested without a terminal. This is
|
|
402
|
+
* why selection is held by task id: a refresh reorders and drops rows, and an
|
|
403
|
+
* index would silently point at a different task, so the same keystroke
|
|
404
|
+
* would run the wrong command.
|
|
406
405
|
*/
|
|
407
406
|
export function recompute() {
|
|
408
407
|
state.rows = visibleRows();
|
|
@@ -415,15 +414,13 @@ function draw() {
|
|
|
415
414
|
process.stdout.write(frame(process.stdout.columns || 100, process.stdout.rows || 30));
|
|
416
415
|
}
|
|
417
416
|
/**
|
|
418
|
-
* The settings screen, as text
|
|
419
|
-
* config schema's
|
|
420
|
-
* same way.
|
|
417
|
+
* The settings screen, as text: the same four sections the page shows, in
|
|
418
|
+
* the config schema's key order, so both describe a project the same way.
|
|
421
419
|
*
|
|
422
|
-
*
|
|
423
|
-
* server to POST to and a pointer to click with
|
|
424
|
-
*
|
|
425
|
-
*
|
|
426
|
-
* this line points at.
|
|
420
|
+
* Read only, and it says so on screen. The page can edit because it has a
|
|
421
|
+
* server to POST to and a pointer to click with. Editing here would need an
|
|
422
|
+
* input mode per field, which is more than showing the configuration needs.
|
|
423
|
+
* The screen points to `way config set` for edits.
|
|
427
424
|
*/
|
|
428
425
|
async function settingsLines() {
|
|
429
426
|
const loaded = await loadConfig(state.root, state.env, state.home);
|
|
@@ -482,10 +479,14 @@ async function settingsLines() {
|
|
|
482
479
|
*/
|
|
483
480
|
function copy(task) {
|
|
484
481
|
const dir = /^[\w.\-/@+]+$/.test(task.cwd) ? task.cwd : `'${task.cwd.replace(/'/g, "'\\''")}'`;
|
|
485
|
-
|
|
482
|
+
// The text shown, so a control character in it cannot reach the paste.
|
|
483
|
+
const text = terminalSafe(task.cwd === '.' ? task.display : `cd ${dir} && ${task.display}`);
|
|
486
484
|
const bin = process.platform === 'darwin' ? 'pbcopy' : 'xclip';
|
|
487
485
|
const args = process.platform === 'darwin' ? [] : ['-selection', 'clipboard'];
|
|
488
|
-
const res = spawnRunner(bin
|
|
486
|
+
const res = spawnRunner(bin, { absolutePathOnly: true }).run(args, {
|
|
487
|
+
input: text,
|
|
488
|
+
cwd: state.root,
|
|
489
|
+
});
|
|
489
490
|
return res.exitCode === 0;
|
|
490
491
|
}
|
|
491
492
|
let restored = false;
|
|
@@ -499,60 +500,56 @@ function restoreTerminal() {
|
|
|
499
500
|
process.stdout.write(SHOW + ALT_OFF);
|
|
500
501
|
}
|
|
501
502
|
/**
|
|
502
|
-
* Hand the terminal to the selected task and
|
|
503
|
-
*
|
|
504
|
-
* runs.
|
|
503
|
+
* Hand the terminal to the selected task and exit when it finishes. It
|
|
504
|
+
* streams through `@osdlc/command-seam`, so the task has the terminal while
|
|
505
|
+
* it runs.
|
|
505
506
|
*
|
|
506
|
-
* `argv` is spawned
|
|
507
|
-
*
|
|
507
|
+
* `argv` is spawned without a shell. Running `display` would be wrong: for a
|
|
508
|
+
* recipe with parameters it has `<placeholders>`, which a shell reads as
|
|
508
509
|
* redirections.
|
|
509
510
|
*/
|
|
510
511
|
function runAndExit(task, args = []) {
|
|
511
512
|
// Abandon any in-flight probe before the terminal changes hands.
|
|
512
513
|
state.inFlight?.abort();
|
|
513
514
|
restoreTerminal();
|
|
514
|
-
//
|
|
515
|
-
// differ, and printing the placeholder form
|
|
516
|
-
// include it would be a lie about what just happened.
|
|
515
|
+
// Print what actually runs, not `display`. For a task with parameters they
|
|
516
|
+
// differ, and printing the placeholder form would misstate what ran.
|
|
517
517
|
let argv;
|
|
518
518
|
try {
|
|
519
519
|
argv = runArgv(state.project, task, args);
|
|
520
520
|
}
|
|
521
521
|
catch (err) {
|
|
522
|
-
process.stderr.write(`${APP}: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
522
|
+
process.stderr.write(`${APP}: ${terminalSafe(err instanceof Error ? err.message : String(err))}\n`);
|
|
523
523
|
process.exit(1);
|
|
524
524
|
}
|
|
525
|
-
process.stdout.write(`${dim('$')} ${bold(argv.join(' '))}\n`);
|
|
526
|
-
//
|
|
527
|
-
//
|
|
528
|
-
// placeholders again would read as a complaint about a command that was
|
|
529
|
-
// complete.
|
|
525
|
+
process.stdout.write(`${dim('$')} ${bold(terminalSafe(argv.join(' ')))}\n`);
|
|
526
|
+
// Show the parameters only when none were given. A task run with its
|
|
527
|
+
// arguments has just shown them on the line above.
|
|
530
528
|
if (task.parameters.length > 0 && args.length === 0) {
|
|
531
|
-
process.stdout.write(`${dim(` takes ${paramShape(task.parameters)}`)}\n`);
|
|
529
|
+
process.stdout.write(`${dim(` takes ${terminalSafe(paramShape(task.parameters))}`)}\n`);
|
|
532
530
|
}
|
|
533
531
|
const [binary, ...rest] = argv;
|
|
534
532
|
const res = streamRunner(binary).run(rest, {
|
|
535
533
|
cwd: task.cwd === '.' ? state.root : `${state.root}/${task.cwd}`,
|
|
536
534
|
quiet: true,
|
|
537
535
|
});
|
|
538
|
-
//
|
|
539
|
-
//
|
|
540
|
-
//
|
|
541
|
-
// unexplained failure into one the user can act on.
|
|
536
|
+
// The spawn never started: no such binary, or no such directory. The row may
|
|
537
|
+
// be out of date. It came from the store, and its task may have been
|
|
538
|
+
// renamed or deleted since. Saying so gives the user something to act on.
|
|
542
539
|
if (res.reason === 'spawn') {
|
|
543
|
-
process.stderr.write(`${APP}: ${binary}: ${res.error ?? 'could not start'}\n
|
|
540
|
+
process.stderr.write(terminalSafe(`${APP}: ${binary}: ${res.error ?? 'could not start'}`) + '\n');
|
|
544
541
|
const from = cacheFor(task.runner);
|
|
545
542
|
if (from !== undefined && from.state === 'stale') {
|
|
546
|
-
process.stderr.write(`${APP}: that row came from a cached listing of ${task.runner} taken ${humanAge(from.ageMs)}` +
|
|
543
|
+
process.stderr.write(`${APP}: that row came from a cached listing of ${terminalSafe(task.runner)} taken ${humanAge(from.ageMs)}` +
|
|
547
544
|
` — the task may no longer exist; start ${BIN} again to re-probe\n`);
|
|
548
545
|
}
|
|
549
546
|
}
|
|
550
547
|
process.exit(res.exitCode);
|
|
551
548
|
}
|
|
552
549
|
/**
|
|
553
|
-
* Re-probe
|
|
554
|
-
*
|
|
555
|
-
*
|
|
550
|
+
* Re-probe, with three protections: one probe in flight at a time, a
|
|
551
|
+
* generation number so an older result is discarded, and an abort signal so
|
|
552
|
+
* an abandoned probe stops.
|
|
556
553
|
*/
|
|
557
554
|
async function refresh() {
|
|
558
555
|
if (state.loading)
|
|
@@ -564,10 +561,9 @@ async function refresh() {
|
|
|
564
561
|
state.message = '';
|
|
565
562
|
draw();
|
|
566
563
|
try {
|
|
567
|
-
//
|
|
568
|
-
//
|
|
569
|
-
//
|
|
570
|
-
// store on the way out, so the next start still paints instantly.
|
|
564
|
+
// Always a real probe, never a cache read. ^r means "ask again", and an
|
|
565
|
+
// answer from the store would look the same as doing nothing. The probe
|
|
566
|
+
// writes the store, so the next start still shows rows at once.
|
|
571
567
|
const collected = await collectAndCache(state.project, state.root, { ...state.options, signal: controller.signal }, state.store);
|
|
572
568
|
if (generation !== state.generation)
|
|
573
569
|
return; // a newer refresh won
|
|
@@ -590,9 +586,8 @@ async function refresh() {
|
|
|
590
586
|
/**
|
|
591
587
|
* Grant trust, then re-probe in place so the runners appear where the note was.
|
|
592
588
|
*
|
|
593
|
-
* The hint is dropped at the same time
|
|
594
|
-
* repository, which they just did
|
|
595
|
-
* would be instructing them to repeat themselves.
|
|
589
|
+
* The hint is dropped at the same time. It tells the user to trust the
|
|
590
|
+
* repository, which they just did.
|
|
596
591
|
*/
|
|
597
592
|
async function grantTrust() {
|
|
598
593
|
try {
|
|
@@ -602,8 +597,8 @@ async function grantTrust() {
|
|
|
602
597
|
}).trust(state.root);
|
|
603
598
|
}
|
|
604
599
|
catch (err) {
|
|
605
|
-
// Never silent
|
|
606
|
-
//
|
|
600
|
+
// Never silent. If the grant failed, the user must know why the runners
|
|
601
|
+
// are still hidden.
|
|
607
602
|
state.message = `trust failed: ${err instanceof Error ? err.message : String(err)}`;
|
|
608
603
|
return;
|
|
609
604
|
}
|
|
@@ -615,11 +610,11 @@ async function grantTrust() {
|
|
|
615
610
|
state.message = state.projectToolsPending
|
|
616
611
|
? `trusted — re-probing; the project's tools load the next time ${BIN} starts with execution allowed`
|
|
617
612
|
: 'trusted — re-probing';
|
|
618
|
-
// A probe started before the grant
|
|
619
|
-
// `refresh`
|
|
620
|
-
// announced and never
|
|
621
|
-
// the generation synchronously, so the abandoned
|
|
622
|
-
//
|
|
613
|
+
// A probe started before the grant runs with the old settings, and
|
|
614
|
+
// `refresh` ignores a call while one is running, so the grant would be
|
|
615
|
+
// announced and never used. Abandon that probe first. `refresh` increases
|
|
616
|
+
// the generation synchronously, so the abandoned probe cannot overwrite
|
|
617
|
+
// the new result or its state.
|
|
623
618
|
state.inFlight?.abort();
|
|
624
619
|
state.inFlight = null;
|
|
625
620
|
state.loading = false;
|
|
@@ -636,9 +631,9 @@ function cycleRunner(step) {
|
|
|
636
631
|
/**
|
|
637
632
|
* One keystroke.
|
|
638
633
|
*
|
|
639
|
-
* Exported for the same reason `state` is
|
|
640
|
-
* never returns, so the keys that
|
|
641
|
-
*
|
|
634
|
+
* Exported for the same reason `state` is. `runTui` takes over a real
|
|
635
|
+
* terminal and never returns, so tests reach the keys that touch disk
|
|
636
|
+
* (settings, trust) only through this.
|
|
642
637
|
*/
|
|
643
638
|
export function handle(key) {
|
|
644
639
|
const listHeight = Math.max(1, (process.stdout.rows || 30) - 7);
|
|
@@ -646,9 +641,8 @@ export function handle(key) {
|
|
|
646
641
|
select(cursor() + n);
|
|
647
642
|
state.message = '';
|
|
648
643
|
};
|
|
649
|
-
// The
|
|
650
|
-
//
|
|
651
|
-
// also do its usual job in the same breath.
|
|
644
|
+
// The trust prompt takes exactly one keystroke. `y` grants. Any other key
|
|
645
|
+
// cancels and is consumed, so it does not also do its usual job.
|
|
652
646
|
if (state.confirmingTrust) {
|
|
653
647
|
state.confirmingTrust = false;
|
|
654
648
|
state.message = '';
|
|
@@ -656,17 +650,16 @@ export function handle(key) {
|
|
|
656
650
|
void grantTrust().finally(draw);
|
|
657
651
|
return;
|
|
658
652
|
}
|
|
659
|
-
// The settings screen
|
|
660
|
-
//
|
|
661
|
-
// screen.
|
|
653
|
+
// The settings screen takes all keys while it is open, as the entry line
|
|
654
|
+
// does, because the keys below act on a list that is not on screen.
|
|
662
655
|
if (state.settings !== null) {
|
|
663
656
|
if (key === '\x1b' || key === '\x03' || key === ',' || key === 'q')
|
|
664
657
|
state.settings = null;
|
|
665
658
|
return;
|
|
666
659
|
}
|
|
667
|
-
//
|
|
668
|
-
//
|
|
669
|
-
//
|
|
660
|
+
// While arguments are typed, every key is text or one of the two that end
|
|
661
|
+
// it. This comes before the switch so ^y, tab and the arrows cannot act on
|
|
662
|
+
// a list the user is no longer looking at.
|
|
670
663
|
if (state.entering) {
|
|
671
664
|
const entering = state.entering;
|
|
672
665
|
if (key === '\x1b' || key === '\x03') {
|
|
@@ -701,9 +694,9 @@ export function handle(key) {
|
|
|
701
694
|
const row = state.rows[cursor()];
|
|
702
695
|
if (!row)
|
|
703
696
|
break;
|
|
704
|
-
// A
|
|
697
|
+
// A recipe with parameters asks for its arguments first. Running it here
|
|
705
698
|
// would spawn the command without them and hand over the terminal, so
|
|
706
|
-
// the mistake could not
|
|
699
|
+
// the mistake could not be reported.
|
|
707
700
|
if (row.task.parameters.length > 0)
|
|
708
701
|
state.entering = { task: row.task, text: '' };
|
|
709
702
|
else
|
|
@@ -725,9 +718,9 @@ export function handle(key) {
|
|
|
725
718
|
state.selectedId = null;
|
|
726
719
|
break;
|
|
727
720
|
case ',':
|
|
728
|
-
// Loaded on open, not on every frame
|
|
729
|
-
//
|
|
730
|
-
// unhandled rejection instead of a
|
|
721
|
+
// Loaded on open, not on every frame, because it reads from disk. A
|
|
722
|
+
// config that will not parse throws, and without the catch that would
|
|
723
|
+
// be an unhandled rejection instead of a message.
|
|
731
724
|
void settingsLines()
|
|
732
725
|
.then((lines) => {
|
|
733
726
|
state.settings = lines;
|
|
@@ -826,13 +819,14 @@ export async function runTui({ project, projectToolsPending, root, options, runn
|
|
|
826
819
|
}
|
|
827
820
|
draw();
|
|
828
821
|
});
|
|
829
|
-
//
|
|
830
|
-
// full probe, so
|
|
831
|
-
// tasks at once
|
|
832
|
-
//
|
|
822
|
+
// Show the store, then refresh. The first frame costs a few file hashes
|
|
823
|
+
// rather than a full probe, so even when the slowest runner takes seconds
|
|
824
|
+
// the tasks show at once, marked as cached, instead of an empty frame. When
|
|
825
|
+
// the probe finishes, the rows update in place.
|
|
833
826
|
const stored = await readCachedCatalog(project, root, options, state.store);
|
|
834
|
-
//
|
|
835
|
-
//
|
|
827
|
+
// Shown only when something came from the store. With execution off, an
|
|
828
|
+
// empty store still returns withheld reports, which would look like an
|
|
829
|
+
// empty answer.
|
|
836
830
|
if (stored.catalog !== null && fromStore(stored)) {
|
|
837
831
|
state.catalog = orderedCatalog(stored.catalog, runnerOrder);
|
|
838
832
|
state.cache = stored.runners;
|