@harborppm/cli 0.118.0 → 0.120.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -1
- package/bin/harbor.mjs +9 -2
- package/dist/app.mjs +615 -79
- package/lib/args.mjs +35 -1
- package/lib/cli.mjs +159 -35
- package/lib/format.mjs +40 -1
- package/lib/paint.mjs +137 -0
- package/package.json +1 -1
package/lib/args.mjs
CHANGED
|
@@ -32,8 +32,42 @@ export function parseArgs(argv, { flags = [], options = [], repeat = [] } = {})
|
|
|
32
32
|
}
|
|
33
33
|
values[key] = repeat.includes(key) ? [...(values[key] ?? []), value] : value;
|
|
34
34
|
} else {
|
|
35
|
-
|
|
35
|
+
const near = nearest(key, [...flags, ...options, ...repeat]);
|
|
36
|
+
throw new Error(`Unknown option --${key}.${near ? ` Did you mean --${near}?` : ""}`);
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
return { positionals, values };
|
|
39
40
|
}
|
|
41
|
+
|
|
42
|
+
/** How many single-letter edits (and swaps of neighbours) turn one word into another. */
|
|
43
|
+
function editDistance(a, b) {
|
|
44
|
+
const rows = Array.from({ length: a.length + 1 }, (_, i) => [i, ...Array(b.length).fill(0)]);
|
|
45
|
+
for (let j = 1; j <= b.length; j++) rows[0][j] = j;
|
|
46
|
+
for (let i = 1; i <= a.length; i++) {
|
|
47
|
+
for (let j = 1; j <= b.length; j++) {
|
|
48
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
49
|
+
rows[i][j] = Math.min(rows[i - 1][j] + 1, rows[i][j - 1] + 1, rows[i - 1][j - 1] + cost);
|
|
50
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1])
|
|
51
|
+
rows[i][j] = Math.min(rows[i][j], rows[i - 2][j - 2] + 1);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return rows[a.length][b.length];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The option a mistyped one was most likely meant to be: within two edits
|
|
59
|
+
* (one for a short word), or the one it begins, when only one fits.
|
|
60
|
+
*/
|
|
61
|
+
export function nearest(typed, known) {
|
|
62
|
+
const word = typed.toLowerCase();
|
|
63
|
+
if (!word) return null;
|
|
64
|
+
const starts = known.filter((k) => k.startsWith(word));
|
|
65
|
+
if (starts.length === 1) return starts[0];
|
|
66
|
+
const reach = word.length <= 4 ? 1 : 2;
|
|
67
|
+
const scored = known
|
|
68
|
+
.map((k) => ({ k, d: editDistance(word, k) }))
|
|
69
|
+
.filter((x) => x.d <= reach)
|
|
70
|
+
.sort((x, y) => x.d - y.d);
|
|
71
|
+
if (!scored.length || (scored[1] && scored[1].d === scored[0].d)) return null;
|
|
72
|
+
return scored[0].k;
|
|
73
|
+
}
|
package/lib/cli.mjs
CHANGED
|
@@ -76,6 +76,7 @@ import {
|
|
|
76
76
|
convoysText,
|
|
77
77
|
convoyText,
|
|
78
78
|
saltsText,
|
|
79
|
+
wbsText,
|
|
79
80
|
heedSaltText,
|
|
80
81
|
rankText,
|
|
81
82
|
setRankText,
|
|
@@ -209,8 +210,11 @@ export const HELP = `harbor: Harbor from the terminal
|
|
|
209
210
|
the date the owner's queue
|
|
210
211
|
suggests (harbor help add)
|
|
211
212
|
harbor start TASK | submit TASK | done TASK [--confirm] [--over-limit]
|
|
212
|
-
|
|
213
|
-
or Done
|
|
213
|
+
[--comment TEXT] move a task to In play, In review
|
|
214
|
+
or Done; several keys at once
|
|
215
|
+
(harbor done RR-4 RR-7) move each
|
|
216
|
+
in turn; --comment leaves a note
|
|
217
|
+
on each as it moves
|
|
214
218
|
harbor edit TASK [--title T] [--assignee me|none|NAME]
|
|
215
219
|
[--also "NAME, NAME"|none] [--due DATE|pilot|none]
|
|
216
220
|
[--starts DATE|none]
|
|
@@ -384,6 +388,9 @@ export const HELP = `harbor: Harbor from the terminal
|
|
|
384
388
|
harbor salts PROJECT [--risk N|--task N|--put-away N]
|
|
385
389
|
old salts: what finished projects
|
|
386
390
|
like it ran into
|
|
391
|
+
harbor wbs PROJECT|PROGRAM|PORTFOLIO [--depth N] [--open]
|
|
392
|
+
the work breakdown: all the work
|
|
393
|
+
under it, numbered 1, 1.1, 1.1.2
|
|
387
394
|
harbor rank PORTFOLIO [--order "A, B, C"|--clear]
|
|
388
395
|
which ship docks first: the
|
|
389
396
|
order a portfolio's projects
|
|
@@ -414,11 +421,14 @@ export const HELP = `harbor: Harbor from the terminal
|
|
|
414
421
|
takes --status all. Lists say your board's own name for a column it
|
|
415
422
|
renamed; --json keeps Harbor's word in status and the board's in column.
|
|
416
423
|
DATE: YYYY-MM-DD, today, tomorrow, or +N for N days from today.
|
|
424
|
+
On a terminal the answers are coloured: keys, what's late, health. Piped
|
|
425
|
+
or with --json they're plain; --no-color or NO_COLOR=1 keeps them plain.
|
|
417
426
|
Changes show in Harbor's History as yours, "via Harbor CLI". These commands
|
|
418
427
|
never delete; the full-screen app can, as the website can, and asks first,
|
|
419
428
|
and so can harbor fog --sweep's x (drop it), one task at a time.
|
|
420
429
|
Practice: a new harbor starts with First voyage, a project of practice
|
|
421
|
-
tasks that tick themselves off as you try things
|
|
430
|
+
tasks that tick themselves off as you try things, from here too; harbor add
|
|
431
|
+
puts a task there while it's your only project. The brief, harbor week,
|
|
422
432
|
bridge and forecast leave it out. To look around a made-up harbor instead,
|
|
423
433
|
open harborppm.com/demo or run ssh try.harborppm.com.
|
|
424
434
|
`;
|
|
@@ -582,15 +592,25 @@ const REPEAT_WORD = { weekly: "every week", biweekly: "every two weeks", monthly
|
|
|
582
592
|
|
|
583
593
|
const WEEKDAYS = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
|
|
584
594
|
|
|
585
|
-
/** The one open project a task can go in (First voyage
|
|
586
|
-
async function onlyProject(
|
|
595
|
+
/** The one open project a task can go in (First voyage only when it is all there is), or why --project is needed. */
|
|
596
|
+
async function onlyProject(
|
|
597
|
+
client,
|
|
598
|
+
harbor,
|
|
599
|
+
say = "--project NAME",
|
|
600
|
+
{ practice: orPractice = false } = {},
|
|
601
|
+
) {
|
|
587
602
|
const r = await client.call("list_projects", {
|
|
588
603
|
harbor,
|
|
589
604
|
health: ["on-track", "at-risk", "off-track", "paused"],
|
|
590
605
|
limit: 5,
|
|
591
606
|
});
|
|
592
|
-
const
|
|
607
|
+
const all = r.projects ?? [];
|
|
608
|
+
const open = all.filter((p) => p.id !== "voyage");
|
|
593
609
|
if (open.length === 1) return open[0].name;
|
|
610
|
+
// A new harbor has First voyage alone, and its first task says to add one:
|
|
611
|
+
// the task goes there, as it does from the website's New.
|
|
612
|
+
const practice = all.find((p) => p.id === "voyage");
|
|
613
|
+
if (open.length === 0 && practice && orPractice) return practice.name;
|
|
594
614
|
if (open.length === 0)
|
|
595
615
|
throw new HarborError(
|
|
596
616
|
'This harbor has no open project yet; harbor project "NAME" --program P makes one.',
|
|
@@ -1529,6 +1549,17 @@ const DETAIL = {
|
|
|
1529
1549
|
" CONVOY is its words (a part is enough when only one matches) or its id from",
|
|
1530
1550
|
" harbor convoys --json. harbor convoys lists them.",
|
|
1531
1551
|
],
|
|
1552
|
+
wbs: [
|
|
1553
|
+
" harbor wbs NAME reads the work breakdown of a project,",
|
|
1554
|
+
" program or portfolio: one numbered line",
|
|
1555
|
+
" each (1, 1.1, 1.1.2) with its owner,",
|
|
1556
|
+
" dates and how much is done, as the",
|
|
1557
|
+
" website's Breakdown view numbers them",
|
|
1558
|
+
" harbor wbs NAME --depth N only N levels down (1: its children)",
|
|
1559
|
+
" harbor wbs NAME --open leaves finished work out (the numbers",
|
|
1560
|
+
" stay as they were)",
|
|
1561
|
+
" harbor wbs NAME --kind program when a project and a program share it",
|
|
1562
|
+
],
|
|
1532
1563
|
salts: [
|
|
1533
1564
|
" harbor salts PROJECT reads what finished projects like it",
|
|
1534
1565
|
" ran into: risks that came true,",
|
|
@@ -1987,6 +2018,8 @@ const OTHER_NAMES = {
|
|
|
1987
2018
|
ranking: "harbor rank PORTFOLIO says which ship docks first.",
|
|
1988
2019
|
salt: "harbor salts PROJECT lists its old salts.",
|
|
1989
2020
|
"old-salts": "harbor salts PROJECT lists its old salts.",
|
|
2021
|
+
breakdown: "harbor wbs NAME shows a project, program or portfolio as its work breakdown.",
|
|
2022
|
+
tree: "harbor wbs NAME shows a project, program or portfolio as its work breakdown.",
|
|
1990
2023
|
night:
|
|
1991
2024
|
"Harbor at night is the portfolio chart room's evening scene for a wall screen, a picture to look at; harbor programs and harbor reports read the same projects.",
|
|
1992
2025
|
};
|
|
@@ -2038,6 +2071,15 @@ async function harborNamed(client, key) {
|
|
|
2038
2071
|
}
|
|
2039
2072
|
|
|
2040
2073
|
const TASK_KEY = /^[A-Za-z][A-Za-z0-9]{0,9}-\d+$/;
|
|
2074
|
+
/** How many keys harbor start, submit and done take in one go. */
|
|
2075
|
+
const MANY_KEYS = 20;
|
|
2076
|
+
|
|
2077
|
+
/** First voyage's practice tasks this change ticked off, said once under the answer. */
|
|
2078
|
+
function practiceLine(r) {
|
|
2079
|
+
const ticked = Array.isArray(r?.practice) ? r.practice : [];
|
|
2080
|
+
if (!ticked.length) return "";
|
|
2081
|
+
return `First voyage: ticked off ${ticked.map((t) => `“${t}”`).join(" and ")}.`;
|
|
2082
|
+
}
|
|
2041
2083
|
|
|
2042
2084
|
/** True when every word of `words` is somewhere in `name`, any case. */
|
|
2043
2085
|
const nameHas = (name, words) =>
|
|
@@ -2559,7 +2601,11 @@ export async function run(argv, io = {}) {
|
|
|
2559
2601
|
);
|
|
2560
2602
|
// The prompt's counts are behind now; its next draw fetches new ones.
|
|
2561
2603
|
if (name === "create_task" || name === "update_task") await stalePromptCache(env);
|
|
2562
|
-
out(
|
|
2604
|
+
out(
|
|
2605
|
+
asJson
|
|
2606
|
+
? jsonText(result)
|
|
2607
|
+
: plain([show(result), practiceLine(result)].filter(Boolean).join("\n")),
|
|
2608
|
+
);
|
|
2563
2609
|
return 0;
|
|
2564
2610
|
};
|
|
2565
2611
|
let asJson = false;
|
|
@@ -3141,7 +3187,9 @@ export async function run(argv, io = {}) {
|
|
|
3141
3187
|
: await readTitles(client, harbor, titles, values);
|
|
3142
3188
|
// No --project and no #Project: the harbor's one open project, if that's all there is.
|
|
3143
3189
|
if (!values.project && !reads.every((r) => r.project))
|
|
3144
|
-
values.project = await onlyProject(client, harbor, "--project NAME or #NAME in the title"
|
|
3190
|
+
values.project = await onlyProject(client, harbor, "--project NAME or #NAME in the title", {
|
|
3191
|
+
practice: true,
|
|
3192
|
+
});
|
|
3145
3193
|
const projectOf = (r) => values.project ?? r.project?.value;
|
|
3146
3194
|
// One task as --json lists it, the same for a dry run and the real thing.
|
|
3147
3195
|
const taskEntry = (t, title) => ({
|
|
@@ -3320,6 +3368,7 @@ export async function run(argv, io = {}) {
|
|
|
3320
3368
|
...(r.pilot ? { pilot: r.pilot } : {}),
|
|
3321
3369
|
...(r.milestoneReached ? { milestoneReached: r.milestoneReached } : {}),
|
|
3322
3370
|
...(r.milestoneReopened ? { milestoneReopened: r.milestoneReopened } : {}),
|
|
3371
|
+
...(r.practice?.length ? { practice: r.practice } : {}),
|
|
3323
3372
|
},
|
|
3324
3373
|
);
|
|
3325
3374
|
const where = [...new Set(tasks.map((t) => t.project).filter(Boolean))];
|
|
@@ -3361,6 +3410,7 @@ export async function run(argv, io = {}) {
|
|
|
3361
3410
|
...(r.milestoneReopened
|
|
3362
3411
|
? [`${r.milestoneReopened} is open again: it has an open task now.`]
|
|
3363
3412
|
: []),
|
|
3413
|
+
...(practiceLine(r) ? [practiceLine(r)] : []),
|
|
3364
3414
|
].join("\n"),
|
|
3365
3415
|
)
|
|
3366
3416
|
.join("\n"),
|
|
@@ -3375,7 +3425,7 @@ export async function run(argv, io = {}) {
|
|
|
3375
3425
|
const { positionals, values, harbor } = parse(
|
|
3376
3426
|
command === "review"
|
|
3377
3427
|
? spec(["confirm", "over-limit", "mine", "done"], ["owner", "portfolio"])
|
|
3378
|
-
: spec(["confirm", "over-limit"]),
|
|
3428
|
+
: spec(["confirm", "over-limit"], ["comment"]),
|
|
3379
3429
|
);
|
|
3380
3430
|
if (command === "review") {
|
|
3381
3431
|
// The review only reads: a task key here once moved the task, so it says where that went.
|
|
@@ -3414,32 +3464,80 @@ export async function run(argv, io = {}) {
|
|
|
3414
3464
|
);
|
|
3415
3465
|
}
|
|
3416
3466
|
const status = { start: "doing", submit: "review", done: "done" }[command];
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3467
|
+
const moved = (r) =>
|
|
3468
|
+
[
|
|
3469
|
+
`${r.updated.title}: ${r.reopened ? "reopened, " : ""}${{ doing: "started", review: "in review", done: "done" }[status]}.`,
|
|
3470
|
+
r.commented ? "Your comment is on it." : "",
|
|
3471
|
+
r.queuedNext ? `Next one: ${taskLine(r.queuedNext, opts)}` : "",
|
|
3472
|
+
r.milestoneReached
|
|
3473
|
+
? `That was the last of its tasks: ${r.milestoneReached} is reached.`
|
|
3474
|
+
: "",
|
|
3475
|
+
r.milestoneReopened
|
|
3476
|
+
? `${r.milestoneReopened} is open again: one of its tasks is open.`
|
|
3477
|
+
: "",
|
|
3478
|
+
r.projectFinished
|
|
3479
|
+
? `That was the last open task in ${r.projectFinished}. Mark the project Done in the app (harbor) or on the website.`
|
|
3480
|
+
: "",
|
|
3481
|
+
]
|
|
3482
|
+
.filter(Boolean)
|
|
3483
|
+
.join("\n");
|
|
3484
|
+
const move = (task) => ({
|
|
3485
|
+
harbor,
|
|
3486
|
+
task,
|
|
3487
|
+
status,
|
|
3488
|
+
confirmed: values.confirm || undefined,
|
|
3489
|
+
overLimit: values["over-limit"] || undefined,
|
|
3490
|
+
});
|
|
3491
|
+
// --comment says why, on the task's own thread, once the move has landed:
|
|
3492
|
+
// a move that's refused leaves no comment behind.
|
|
3493
|
+
const note = values.comment === undefined ? undefined : values.comment.trim();
|
|
3494
|
+
if (note === "") throw new HarborError("--comment needs some words.");
|
|
3495
|
+
const moveOne = async (task) => {
|
|
3496
|
+
const r = await client.call("update_task", move(task));
|
|
3497
|
+
if (!note) return r;
|
|
3498
|
+
const c = await client.call("add_comment", { harbor, task, body: note });
|
|
3499
|
+
return { ...r, commented: c.commented, mentioned: c.mentioned };
|
|
3500
|
+
};
|
|
3501
|
+
// Several keys: each in turn, as if typed one after another. Only keys,
|
|
3502
|
+
// so a title typed without quotes is never read as several tasks.
|
|
3503
|
+
const keys = [...new Map(positionals.map((k) => [k.toUpperCase(), k])).values()];
|
|
3504
|
+
if (positionals.length > 1 && positionals.every((k) => TASK_KEY.test(k))) {
|
|
3505
|
+
if (keys.length > MANY_KEYS)
|
|
3506
|
+
throw new HarborError(`That's ${keys.length} tasks; ${MANY_KEYS} at a time at most.`);
|
|
3507
|
+
const results = [];
|
|
3508
|
+
for (const key of keys) {
|
|
3509
|
+
try {
|
|
3510
|
+
const r = await moveOne(key);
|
|
3511
|
+
results.push({ task: key.toUpperCase(), ...r });
|
|
3512
|
+
} catch (err) {
|
|
3513
|
+
if (!(err instanceof HarborError)) throw err;
|
|
3514
|
+
results.push({ task: key.toUpperCase(), error: hint(err.message) });
|
|
3515
|
+
}
|
|
3516
|
+
}
|
|
3517
|
+
await stalePromptCache(env);
|
|
3518
|
+
const failed = results.filter((r) => r.error).length;
|
|
3519
|
+
if (asJson) out(jsonText({ results, moved: results.length - failed, failed }));
|
|
3520
|
+
else {
|
|
3521
|
+
const lines = results.map((r) =>
|
|
3522
|
+
r.error
|
|
3523
|
+
? `${r.task}: ${r.error}`
|
|
3524
|
+
: [moved(r), practiceLine(r)].filter(Boolean).join("\n"),
|
|
3525
|
+
);
|
|
3526
|
+
if (failed && results.length > failed)
|
|
3527
|
+
lines.push(`${results.length - failed} of ${results.length} moved.`);
|
|
3528
|
+
out(plain(lines.join("\n")));
|
|
3529
|
+
}
|
|
3530
|
+
return failed ? 1 : 0;
|
|
3531
|
+
}
|
|
3532
|
+
const task = one(positionals, "task key, like RR-42");
|
|
3533
|
+
if (!note) return call("update_task", move(task), moved);
|
|
3534
|
+
const r = await moveOne(task).catch((err) => {
|
|
3535
|
+
if (err instanceof HarborError) throw new HarborError(hint(err.message));
|
|
3536
|
+
throw err;
|
|
3537
|
+
});
|
|
3538
|
+
await stalePromptCache(env);
|
|
3539
|
+
out(asJson ? jsonText(r) : plain([moved(r), practiceLine(r)].filter(Boolean).join("\n")));
|
|
3540
|
+
return 0;
|
|
3443
3541
|
}
|
|
3444
3542
|
case "edit": {
|
|
3445
3543
|
const { positionals, values, harbor } = parse(
|
|
@@ -4994,6 +5092,32 @@ export async function run(argv, io = {}) {
|
|
|
4994
5092
|
convoyText,
|
|
4995
5093
|
);
|
|
4996
5094
|
}
|
|
5095
|
+
case "wbs": {
|
|
5096
|
+
const { positionals, values, harbor } = parse(spec(["open"], ["depth", "kind", "offset"]));
|
|
5097
|
+
const of = text(positionals, "which project, program or portfolio");
|
|
5098
|
+
const depth = values.depth === undefined ? undefined : Number(values.depth);
|
|
5099
|
+
if (depth !== undefined && !(Number.isInteger(depth) && depth >= 1 && depth <= 4))
|
|
5100
|
+
throw new HarborError("--depth takes 1 to 4: how many levels under it to show.");
|
|
5101
|
+
const kind = values.kind?.trim().toLowerCase();
|
|
5102
|
+
if (kind !== undefined && !["project", "program", "portfolio"].includes(kind))
|
|
5103
|
+
throw new HarborError("--kind takes project, program or portfolio.");
|
|
5104
|
+
const offset = values.offset === undefined ? 0 : Number(values.offset);
|
|
5105
|
+
if (!(Number.isInteger(offset) && offset >= 0))
|
|
5106
|
+
throw new HarborError("--offset takes a whole number of lines to skip.");
|
|
5107
|
+
return call(
|
|
5108
|
+
"work_breakdown",
|
|
5109
|
+
{
|
|
5110
|
+
harbor,
|
|
5111
|
+
of,
|
|
5112
|
+
...(kind ? { kind } : {}),
|
|
5113
|
+
...(depth ? { depth } : {}),
|
|
5114
|
+
...(values.open ? { open: true } : {}),
|
|
5115
|
+
...(offset ? { offset } : {}),
|
|
5116
|
+
limit: 1000,
|
|
5117
|
+
},
|
|
5118
|
+
wbsText,
|
|
5119
|
+
);
|
|
5120
|
+
}
|
|
4997
5121
|
case "salts": {
|
|
4998
5122
|
const { positionals, values, harbor } = parse(spec([], ["risk", "task", "put-away"]));
|
|
4999
5123
|
const project = text(positionals, "which project");
|
package/lib/format.mjs
CHANGED
|
@@ -1630,7 +1630,9 @@ export function milestonesText(r, { done = false } = {}) {
|
|
|
1630
1630
|
? [`None ${r.program ? `in ${r.program} ` : ""}reached yet.`]
|
|
1631
1631
|
: [];
|
|
1632
1632
|
const hidden = r.reachedHidden
|
|
1633
|
-
?
|
|
1633
|
+
? r.reachedHidden === 1
|
|
1634
|
+
? "1 reached milestone not shown (--done shows it)."
|
|
1635
|
+
: `${r.reachedHidden} reached milestones not shown (--done shows them).`
|
|
1634
1636
|
: "";
|
|
1635
1637
|
if (!list.length) {
|
|
1636
1638
|
const none = r.program ? `${r.program} has no open milestones.` : "No open milestones.";
|
|
@@ -1797,6 +1799,43 @@ export function saltsText(r) {
|
|
|
1797
1799
|
return lines.join("\n");
|
|
1798
1800
|
}
|
|
1799
1801
|
|
|
1802
|
+
/**
|
|
1803
|
+
* harbor wbs: the work breakdown, one numbered line per program, project,
|
|
1804
|
+
* task and subtask, indented by level, with owner, dates and progress.
|
|
1805
|
+
*/
|
|
1806
|
+
export function wbsText(r) {
|
|
1807
|
+
const head = `${r.of.name}: work breakdown · ${r.done} of ${r.tasks} task${r.tasks === 1 ? "" : "s"} done${r.late ? ` · ${r.late} late` : ""}`;
|
|
1808
|
+
if (!r.lines.length) return `${head}\n\nNothing under it yet.`;
|
|
1809
|
+
const width = Math.max(...r.lines.map((l) => l.wbs.length + (l.level - 1) * 2));
|
|
1810
|
+
const out = [head, ""];
|
|
1811
|
+
for (const l of r.lines) {
|
|
1812
|
+
const lead = `${" ".repeat(l.level - 1)}${l.wbs}`.padEnd(width);
|
|
1813
|
+
const dates =
|
|
1814
|
+
l.start && l.end && l.start !== l.end
|
|
1815
|
+
? `${l.start} to ${l.end}`
|
|
1816
|
+
: l.end && !l.subtasks
|
|
1817
|
+
? `due ${l.end}`
|
|
1818
|
+
: l.end || (l.start ? `from ${l.start}` : null);
|
|
1819
|
+
const bits = [
|
|
1820
|
+
l.kind === "task" || l.kind === "subtask"
|
|
1821
|
+
? `${STATUS[l.status] ?? l.status}${l.subtasks ? `, ${l.done}/${l.subtasks} subtasks done` : ""}`
|
|
1822
|
+
: `${l.percent}% (${l.done}/${l.tasks})`,
|
|
1823
|
+
l.owner || null,
|
|
1824
|
+
dates,
|
|
1825
|
+
// A task on its own is late or it isn't; anything with work under it says how many.
|
|
1826
|
+
l.late
|
|
1827
|
+
? (l.kind === "task" || l.kind === "subtask") && !l.subtasks
|
|
1828
|
+
? "late"
|
|
1829
|
+
: `${l.late} late`
|
|
1830
|
+
: null,
|
|
1831
|
+
l.runsPastEnd ? "runs past its end" : null,
|
|
1832
|
+
].filter(Boolean);
|
|
1833
|
+
out.push(` ${lead} ${l.name}${l.key ? ` ${l.key}` : ""} (${bits.join(" · ")})`);
|
|
1834
|
+
}
|
|
1835
|
+
if (r.more) out.push("", "More lines: --offset to page, or --depth to stay higher up.");
|
|
1836
|
+
return out.join("\n");
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1800
1839
|
/** What harbor salts --risk, --task or --put-away did. */
|
|
1801
1840
|
export function heedSaltText(r) {
|
|
1802
1841
|
if (r.putAway)
|
package/lib/paint.mjs
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Colour for the commands' answers, on a terminal only. Harbor's lines keep
|
|
3
|
+
* one shape (`KEY Title (status · late, due … · owner · project)`), so the
|
|
4
|
+
* colour is laid over the finished text rather than threaded through every
|
|
5
|
+
* formatter: a task's key stands out, the details in brackets step back, and
|
|
6
|
+
* the few words that ask for attention (late, off track, at risk) are the
|
|
7
|
+
* only ones in a warm colour. Piped, redirected, with --json, with NO_COLOR
|
|
8
|
+
* set or with --no-color, the text is exactly what it was.
|
|
9
|
+
*
|
|
10
|
+
* The colours are the terminal's own sixteen, so they follow whatever theme
|
|
11
|
+
* the person chose, light or dark; nothing here picks a shade for them.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const ESC = "\x1b[";
|
|
15
|
+
const RESET = `${ESC}0m`;
|
|
16
|
+
const wrap = (code) => (s) => (s ? `${ESC}${code}m${s}${RESET}` : s);
|
|
17
|
+
const dim = wrap("2");
|
|
18
|
+
const bold = wrap("1");
|
|
19
|
+
const cyan = wrap("36");
|
|
20
|
+
const red = wrap("31");
|
|
21
|
+
const yellow = wrap("33");
|
|
22
|
+
const green = wrap("32");
|
|
23
|
+
|
|
24
|
+
/** Commands whose answer is data for another program, or draws itself. */
|
|
25
|
+
const PLAIN_COMMANDS = new Set(["export", "prompt", "calendar", "version"]);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Whether this run's answers are coloured. `--no-color` and NO_COLOR (any
|
|
29
|
+
* value but empty) always win; FORCE_COLOR turns it on where there's no
|
|
30
|
+
* terminal to ask, as other tools take it.
|
|
31
|
+
* @param {{ argv: string[], env?: Record<string, string | undefined>, stream?: { isTTY?: boolean } }} opts
|
|
32
|
+
*/
|
|
33
|
+
export function wantsColour({ argv, env = process.env, stream = process.stdout }) {
|
|
34
|
+
if (argv.includes("--no-color") || argv.includes("--no-colour")) return false;
|
|
35
|
+
if (argv.includes("--json") || argv.includes("--csv")) return false;
|
|
36
|
+
const command = argv.find((a) => !a.startsWith("-"));
|
|
37
|
+
if (command && PLAIN_COMMANDS.has(command)) return false;
|
|
38
|
+
if (argv.includes("--version") || argv.includes("-v")) return false;
|
|
39
|
+
if (env.NO_COLOR) return false;
|
|
40
|
+
if (env.FORCE_COLOR && env.FORCE_COLOR !== "0") return true;
|
|
41
|
+
return Boolean(stream.isTTY) && env.TERM !== "dumb";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** argv without the colour switches, which every command takes. */
|
|
45
|
+
export function withoutColourFlags(argv) {
|
|
46
|
+
return argv.filter((a) => a !== "--no-color" && a !== "--no-colour");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** One detail between the dots: the few that ask for attention keep a colour. */
|
|
50
|
+
function paintBit(bit) {
|
|
51
|
+
const t = bit.trim();
|
|
52
|
+
if (/^(late\b|\d+ late$|was due\b|off track$|overdue\b|runs past its end$)/.test(t))
|
|
53
|
+
return red(bit);
|
|
54
|
+
if (/^(at risk$|changes asked for\b)/.test(t)) return yellow(bit);
|
|
55
|
+
if (/^on track$/.test(t)) return green(bit);
|
|
56
|
+
return dim(bit);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** "a · b · c" with each part painted and the dots dimmed. */
|
|
60
|
+
function paintBits(text) {
|
|
61
|
+
return text
|
|
62
|
+
.split(" · ")
|
|
63
|
+
.map((bit) =>
|
|
64
|
+
// "5 open, 1 late": the late half is the news.
|
|
65
|
+
/, \d+ late$/.test(bit)
|
|
66
|
+
? `${dim(bit.slice(0, bit.lastIndexOf(", ") + 2))}${red(bit.slice(bit.lastIndexOf(", ") + 2))}`
|
|
67
|
+
: paintBit(bit),
|
|
68
|
+
)
|
|
69
|
+
.join(dim(" · "));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** A task key as Harbor writes one: RR-42, FV-1. */
|
|
73
|
+
const KEY = "[A-Z][A-Z0-9]{0,9}-\\d+";
|
|
74
|
+
const LEADING_KEY = new RegExp(`^(\\s*(?:(?:Added|Would add|Next one): )?)(${KEY})( )`);
|
|
75
|
+
/** The details at a line's end: two spaces, then one pair of brackets. */
|
|
76
|
+
const DETAILS = /^(.*\S)( {2})\(([^()]*(?:\([^()]*\)[^()]*)*)\)$/;
|
|
77
|
+
/** harbor help's lines: the command, a gap, what it does. */
|
|
78
|
+
const HELP_LINE = /^( {2}harbor(?: \S+)*?)( {2,})(\S.*)$/;
|
|
79
|
+
/** A line that only carries on the description above it. */
|
|
80
|
+
const HELP_MORE = /^ {20,}\S/;
|
|
81
|
+
/** A second line of details under a row: indented, parts between dots. */
|
|
82
|
+
const UNDER = /^( {4,})(\S.* · .*)$/;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* One line with colour laid over it. A line that already carries an escape
|
|
86
|
+
* (the banner draws its own) is left alone.
|
|
87
|
+
* @param {string} line
|
|
88
|
+
* @param {{ help?: boolean }} [opts]
|
|
89
|
+
*/
|
|
90
|
+
export function paintLine(line, opts = {}) {
|
|
91
|
+
if (!line || line.includes("\x1b")) return line;
|
|
92
|
+
if (opts.help) {
|
|
93
|
+
const help = HELP_LINE.exec(line);
|
|
94
|
+
if (help) return `${help[1]}${help[2]}${dim(help[3])}`;
|
|
95
|
+
if (HELP_MORE.test(line)) return dim(line);
|
|
96
|
+
return line;
|
|
97
|
+
}
|
|
98
|
+
let head = line;
|
|
99
|
+
let tail = "";
|
|
100
|
+
const details = DETAILS.exec(line);
|
|
101
|
+
if (details) {
|
|
102
|
+
head = details[1];
|
|
103
|
+
tail = `${details[2]}${dim("(")}${paintBits(details[3])}${dim(")")}`;
|
|
104
|
+
}
|
|
105
|
+
const key = LEADING_KEY.exec(head);
|
|
106
|
+
if (key) head = `${key[1]}${cyan(key[2])}${key[3]}${head.slice(key[0].length)}`;
|
|
107
|
+
else if (!tail) {
|
|
108
|
+
const under = UNDER.exec(line);
|
|
109
|
+
if (under) return `${under[1]}${paintBits(under[2])}`;
|
|
110
|
+
}
|
|
111
|
+
return `${head}${tail}`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* A whole answer, line by line. The first line of a list with a count
|
|
116
|
+
* ("Aya: 5 open, 1 late") is its heading, so it's bold.
|
|
117
|
+
* @param {string} text
|
|
118
|
+
* @param {{ help?: boolean }} [opts]
|
|
119
|
+
*/
|
|
120
|
+
export function paint(text, opts = {}) {
|
|
121
|
+
const lines = String(text).split("\n");
|
|
122
|
+
return lines
|
|
123
|
+
.map((line, i) => {
|
|
124
|
+
if (
|
|
125
|
+
!opts.help &&
|
|
126
|
+
i === 0 &&
|
|
127
|
+
lines.length > 2 &&
|
|
128
|
+
lines[1] === "" &&
|
|
129
|
+
!line.includes("\x1b") &&
|
|
130
|
+
!/^\s/.test(line) &&
|
|
131
|
+
!DETAILS.test(line)
|
|
132
|
+
)
|
|
133
|
+
return bold(line);
|
|
134
|
+
return paintLine(line, opts);
|
|
135
|
+
})
|
|
136
|
+
.join("\n");
|
|
137
|
+
}
|