@awebai/oats 0.58.0 → 0.60.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/bin/oats.mjs +1 -1
- package/docs/desktop-cli-api.md +80 -8
- package/docs/desktop.md +30 -3
- package/docs/execution-targets.md +18 -2
- package/docs/implementation.md +3 -0
- package/docs/integrations.md +2 -2
- package/docs/knowledge.md +4 -4
- package/docs/official-catalog.md +4 -4
- package/docs/packages.md +14 -14
- package/docs/release-notes/v0.59.0.md +288 -0
- package/docs/release-notes/v0.60.0.md +104 -0
- package/docs/servers.md +4 -1
- package/docs/souls-and-instances.md +21 -0
- package/docs/tui.md +753 -119
- package/docs/workspaces.md +2 -2
- package/lib/core.mjs +258 -57
- package/lib/read-ahead-worker.mjs +119 -0
- package/lib/read-ahead.mjs +115 -0
- package/lib/retire-state.mjs +33 -0
- package/lib/servers.mjs +9 -1
- package/lib/session-input.mjs +53 -26
- package/package-catalog.json +3 -3
- package/package.json +1 -1
- package/packages/client/capability-catalog.mjs +93 -0
- package/packages/client/capability-facts.mjs +59 -0
- package/packages/client/capability-rows.mjs +121 -0
- package/packages/client/catalog-messages.mjs +12 -0
- package/packages/client/cli-locator.mjs +2 -2
- package/packages/client/deployment-data.mjs +4 -0
- package/packages/client/deployment-panel.mjs +3 -0
- package/packages/client/instance-acts.mjs +23 -8
- package/packages/client/instance-presentation.mjs +3 -2
- package/packages/client/instance-tree.mjs +84 -39
- package/packages/client/lifecycle-confirmation.mjs +9 -3
- package/packages/client/remote-roster.mjs +4 -1
- package/packages/client/retire-in-flight.mjs +65 -0
- package/packages/client/retire-state.mjs +30 -0
- package/packages/client/soul-catalog.mjs +8 -0
- package/packages/client/soul-facts.mjs +7 -0
- package/packages/client/spawn-apply.mjs +13 -4
- package/packages/client/spawn-messages.mjs +8 -0
- package/packages/client/subsequence-score.mjs +15 -0
- package/packages/tui/README.md +23 -10
- package/packages/tui/lib/actions.mjs +63 -5
- package/packages/tui/lib/client.mjs +17 -1
- package/packages/tui/lib/config.mjs +7 -2
- package/packages/tui/lib/main.mjs +364 -82
- package/packages/tui/lib/model.mjs +614 -57
- package/packages/tui/lib/panel.mjs +436 -125
- package/packages/tui/lib/read.mjs +52 -26
- package/packages/tui/lib/store.mjs +1025 -65
- package/packages/tui/lib/term/keys.mjs +9 -2
- package/packages/tui/lib/term/text.mjs +4 -0
- package/packages/tui/lib/term/through.mjs +12 -1
- package/packages/tui/lib/views/capabilities.mjs +239 -0
- package/packages/tui/lib/views/frame.mjs +433 -99
- package/packages/tui/lib/views/help.mjs +61 -15
- package/packages/tui/lib/views/instances.mjs +43 -25
- package/packages/tui/lib/views/palette.mjs +66 -0
- package/packages/tui/lib/views/souls.mjs +270 -0
- package/packages/tui/lib/views/spawn.mjs +301 -0
- package/packages/tui/lib/views/split.mjs +29 -0
- package/skills/oats-getting-started/SKILL.md +2 -2
|
@@ -35,11 +35,16 @@ const GRAPHEMES = new Intl.Segmenter("en", { granularity: "grapheme" });
|
|
|
35
35
|
|
|
36
36
|
const named = (name, ctrl = false, alt = false, shift = false) => ({ name, ctrl, alt, shift });
|
|
37
37
|
|
|
38
|
-
/**
|
|
38
|
+
/** Control with one of \ ] ^ _: the C0 bytes 0x1c..0x1f, in that order. */
|
|
39
|
+
const CTRL_PUNCTUATION = "\\]^_";
|
|
40
|
+
|
|
41
|
+
/** The key of a C0 byte or DEL, or null for a byte that is no key (NUL). 0x1c..0x1f are Control
|
|
42
|
+
* with \ ] ^ _ (the leader, `C-\` by default, is one of them: docs/tui.md, "The leader"). */
|
|
39
43
|
function c0Key(b) {
|
|
40
44
|
if (b === 0x0d || b === 0x0a) return named("enter");
|
|
41
45
|
if (b === 0x09) return named("tab");
|
|
42
46
|
if (b === 0x7f || b === 0x08) return named("backspace");
|
|
47
|
+
if (b >= 0x1c && b <= 0x1f) return named(CTRL_PUNCTUATION[b - 0x1c], true);
|
|
43
48
|
return b >= 0x01 && b <= 0x1a ? named(String.fromCharCode(b + 0x60), true) : null;
|
|
44
49
|
}
|
|
45
50
|
|
|
@@ -325,6 +330,7 @@ export function keyId(event) {
|
|
|
325
330
|
/** The names that take every modifier: the keys read by `modified` from a CSI or an SS3. */
|
|
326
331
|
const MODIFIED_NAMES = new Set([...Object.values(LETTER_KEYS), ...Object.values(TILDE_KEYS)]);
|
|
327
332
|
const NAMED_ID = /^(ctrl\+)?(alt\+)?(shift\+)?([a-z][a-z0-9]*)$/;
|
|
333
|
+
const CTRL_PUNCTUATION_ID = /^ctrl\+(?:alt\+)?[\\\]^_]$/;
|
|
328
334
|
/** What no text event holds: a control character (C0, DEL, C1) or half a surrogate pair. */
|
|
329
335
|
const NOT_TEXT = /[\p{Cc}\p{Cs}]/u;
|
|
330
336
|
/** The characters that, after an ESC, begin a sequence (CSI, SS3, OSC, DCS, SOS, PM, APC): Alt
|
|
@@ -349,13 +355,14 @@ const oneCodePoint = (text) => text.length === (text.codePointAt(0) > 0xffff ? 2
|
|
|
349
355
|
* enter, backspace: bare or `alt+`. escape: bare
|
|
350
356
|
* tab: bare, `alt+tab`, and `shift+tab` with any of `ctrl+`, `alt+` before it
|
|
351
357
|
* ctrl `ctrl+` or `ctrl+alt+` and a letter a..z whose C0 byte is a key of its own:
|
|
352
|
-
* not h, i, j or m, which arrive as Backspace, Tab and Enter */
|
|
358
|
+
* not h, i, j or m, which arrive as Backspace, Tab and Enter; or one of \ ] ^ _ */
|
|
353
359
|
export function isKeyId(id) {
|
|
354
360
|
if (typeof id !== "string" || id === "" || NOT_TEXT.test(id)) return false;
|
|
355
361
|
if (id === "space" || id === "alt+space") return true;
|
|
356
362
|
if (id === " " || id === "alt+ ") return false;
|
|
357
363
|
if (oneGrapheme(id)) return true;
|
|
358
364
|
if (id.startsWith("alt+") && id.length > 4 && oneCodePoint(id.slice(4))) return !INTRODUCERS.includes(id.slice(4));
|
|
365
|
+
if (CTRL_PUNCTUATION_ID.test(id)) return true;
|
|
359
366
|
const match = NAMED_ID.exec(id);
|
|
360
367
|
if (!match) return false;
|
|
361
368
|
const [, ctrl, alt, shift, name] = match;
|
|
@@ -47,6 +47,10 @@ export function shown(value) {
|
|
|
47
47
|
return line === null ? EMPTY : line === DETAIL_WITHHELD ? WITHHELD : make(line);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
/** The ellipsis in words the TUI or the shared home wrote ("Retiring…", "Setting up worktree…", "Starting …"): in ASCII
|
|
51
|
+
* three full stops, as the cut mark is. Only for their own words: text from anywhere else is shown as it came. */
|
|
52
|
+
export const ownEllipsis = (string, ascii) => (ascii ? string.replaceAll("\u2026", "...") : string);
|
|
53
|
+
|
|
50
54
|
/** The cut mark, the screen's own (term/screen.mjs): one cell, or three in ASCII. */
|
|
51
55
|
const cutMark = (ascii) => (ascii ? "..." : "\u2026");
|
|
52
56
|
const widthOf = (graphemes) => graphemes.reduce((sum, g) => sum + g.width, 0);
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// back from a terminal and name in the footer. It began as the kernel's `--detach-key` grammar
|
|
9
9
|
// (lib/session-viewer.mjs) and keeps its set and its spelling, so a tui.json written for PR 4 means
|
|
10
10
|
// the same key; it is not tied to the kernel's, which never sees this key any more.
|
|
11
|
-
import { ESC_TIMEOUT_MS, PASTE_LIMIT, PASTE_PAUSE_MS } from "./keys.mjs";
|
|
11
|
+
import { ESC_TIMEOUT_MS, PASTE_LIMIT, PASTE_PAUSE_MS, createKeyParser, keyId } from "./keys.mjs";
|
|
12
12
|
|
|
13
13
|
/** The keys that can be the back key: Control with a letter other than h, i and m (Backspace on
|
|
14
14
|
* some terminals, Tab, Enter), or one of \ ] ^ _; Meta with a lowercase letter or a digit; or F1
|
|
@@ -49,6 +49,17 @@ export function backKeySequences(key) {
|
|
|
49
49
|
return forms.map(escaped);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
/** The key id the key parser (term/keys.mjs) reads a back key's bytes as: what the leader is where
|
|
53
|
+
* the TUI reads keys (docs/tui.md, "The leader"). `C-\\` is `ctrl+\\`, `M-x` is `alt+x`, `F5` is
|
|
54
|
+
* `f5`; `C-j` is `enter`, the byte the parser reads as Enter. Every form of a back key reads as
|
|
55
|
+
* the same id. A key that is no back key (tui.json refuses it) has none: null. */
|
|
56
|
+
export function backKeyId(key) {
|
|
57
|
+
let sequences;
|
|
58
|
+
try { sequences = backKeySequences(key); } catch { return null; } // not a back key: none is read
|
|
59
|
+
const events = createKeyParser({ now: () => 0 }).feed(sequences[0]);
|
|
60
|
+
return events.length === 1 ? keyId(events[0]) : null;
|
|
61
|
+
}
|
|
62
|
+
|
|
52
63
|
const PASTE_START = escaped("[200~");
|
|
53
64
|
const PASTE_END = escaped("[201~");
|
|
54
65
|
/** The first bytes of a paste's start marker that are held when a read ends on them: from `ESC [ 2`
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
// The Capabilities view: (model, pane) -> rows of spans, the list of the open workspace's
|
|
2
|
+
// capabilities in their sections and groups, and the selected capability's detail. Pure: no IO, no
|
|
3
|
+
// clock, no escape byte. A capability's name, its description, a group's name and note, the facts
|
|
4
|
+
// of where it comes from and what it provides, the names of the souls that use it, the shared words
|
|
5
|
+
// of the detail (lib/model.mjs passes CAPABILITY_COPY's) and a failed read's sentence are text the
|
|
6
|
+
// TUI did not write and go through shown(); the section titles, the separators and the few lines
|
|
7
|
+
// of CAPABILITIES_TEXT are the TUI's own. Nothing is told by colour alone: the selected row and the
|
|
8
|
+
// marked soul carry `>` as well as reverse video, a soul's colour is drawn on a mark that is there
|
|
9
|
+
// without it, and the souls on an older version are said so in words before their warning style.
|
|
10
|
+
import { lit, shown, shownLines } from "../term/text.mjs";
|
|
11
|
+
import { COLORS, style } from "../term/style.mjs";
|
|
12
|
+
import { keyLabel } from "../actions.mjs";
|
|
13
|
+
import { cutNote, headingRow, marksOf, measured } from "./instances.mjs";
|
|
14
|
+
import { windowOf } from "./scroll.mjs";
|
|
15
|
+
import { COUNT_SIGN, SOUL_MARK, flowed, ownLines } from "./souls.mjs";
|
|
16
|
+
|
|
17
|
+
/** The TUI's own lines in the Capabilities view. The section titles are the Desktop's own
|
|
18
|
+
* (renderer/workspace-catalog.mjs), word for word: the shared home holds none (Spec 7, Settled 6).
|
|
19
|
+
* `retry` stands after the key that reads again (tui.json may rebind it). `reading` and
|
|
20
|
+
* `readingSouls` end in an ellipsis, drawn `...` in ASCII. */
|
|
21
|
+
export const CAPABILITIES_TEXT = Object.freeze({
|
|
22
|
+
reading: "Reading capabilities…",
|
|
23
|
+
none: "This workspace offers no capabilities. `oats capabilities` says why.",
|
|
24
|
+
nomatch: "No capability matches the filter.",
|
|
25
|
+
retry: "reads them again.",
|
|
26
|
+
noWorkspace: "Open a workspace of this machine to see its capabilities.",
|
|
27
|
+
readingSouls: "Reading souls…",
|
|
28
|
+
sections: Object.freeze({ workspace: "Workspace owned", repo: "Repo owned", packages: "Packages" }),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
/** The columns of the list: the selection mark, a section's title, a group's heading, a capability's name. */
|
|
32
|
+
const SECTION = 1, GROUP = 2, NAME = 4;
|
|
33
|
+
/** Where a line of the TUI's own and a failed read's sentence start in the list (views/souls.mjs). */
|
|
34
|
+
const SENTENCE_INDENT = 3;
|
|
35
|
+
/** The detail's title and headings start here: the first cell holds the mark of the pane with the
|
|
36
|
+
* focus (views/detail.mjs). Each section's lines are set in to INNER. */
|
|
37
|
+
const LEFT = 2, INNER = LEFT + 2;
|
|
38
|
+
/** The fewest cells a fact's value keeps beside its label: under them it goes on the row under it. */
|
|
39
|
+
const VALUE_MIN = 16;
|
|
40
|
+
/** The most rows a wrapped value or sentence takes, and the description. */
|
|
41
|
+
const WRAP_ROWS = 6, DESCRIPTION_ROWS = 8;
|
|
42
|
+
|
|
43
|
+
const PLAIN = style();
|
|
44
|
+
const BOLD = style({ bold: true });
|
|
45
|
+
const DIM = style({ dim: true });
|
|
46
|
+
const SELECTED = style({ reverse: true });
|
|
47
|
+
/** The warning style: what it marks says so in words too. */
|
|
48
|
+
const WARN = style({ bold: true, fg: "yellow" });
|
|
49
|
+
|
|
50
|
+
/** The mark between a group's name and its note, and before the instances on an older version. */
|
|
51
|
+
const dotOf = (ascii) => (ascii ? "-" : "·");
|
|
52
|
+
/** A line of the TUI's own as the screen draws it: the ellipsis is `...` in ASCII. */
|
|
53
|
+
const ownText = (text, ascii) => (ascii ? text.replace(/…/g, "...") : text);
|
|
54
|
+
|
|
55
|
+
/** The first key of the action `id` as the user has it, `{ text, width }`, or null when it has none. */
|
|
56
|
+
function keyOf(m, id) {
|
|
57
|
+
const action = (m.actions ?? []).find((a) => a.id === id && a.keys.length);
|
|
58
|
+
return action ? measured(keyLabel(action.keys[0])) : null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Whether the list stands, beside the detail on a wide terminal: once the catalog was read (its
|
|
62
|
+
* rows, or none of them matching the filter), and over the rows a failed re-read kept. A body of
|
|
63
|
+
* one sentence (reading, a failed first read, an empty catalog, no workspace here) has the whole
|
|
64
|
+
* width instead. */
|
|
65
|
+
export function capabilitiesListed(c) {
|
|
66
|
+
return Boolean(c) && c.local !== false && (c.heading != null || c.state === "rows" || c.state === "nomatch" || (c.list?.length ?? 0) > 0);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Text from outside, then `after` (parts `{ text, style }` of the TUI's own or shown already, each
|
|
70
|
+
* `width` cells) one cell after it, from column `col` in a row ending at `end`: the text is cut
|
|
71
|
+
* before what follows it is, which stands whole beside what is left of it, or not at all when no
|
|
72
|
+
* cell of the text would be left. */
|
|
73
|
+
function nameThen(name, after, col, end, look) {
|
|
74
|
+
const afterWidth = after.reduce((sum, part) => sum + 1 + part.width, 0);
|
|
75
|
+
const kept = end - col > afterWidth ? after : [];
|
|
76
|
+
const room = end - col - (kept.length ? afterWidth : 0);
|
|
77
|
+
if (room <= 0) return [];
|
|
78
|
+
const nameWidth = Math.min(name.width, room);
|
|
79
|
+
const spans = [{ col, text: name.text, style: look(PLAIN), width: kept.length ? nameWidth : room }];
|
|
80
|
+
let at = col + nameWidth;
|
|
81
|
+
for (const part of kept) { at += 1; spans.push({ col: at, text: part.text, style: look(part.style), width: part.width }); at += part.width; }
|
|
82
|
+
return spans;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** One item of the list in a pane `cols` wide: a section's title (bold), a group's heading (dim,
|
|
86
|
+
* `name · note`), or a capability: the selection mark, its name, and its layer's label dim when it
|
|
87
|
+
* has one. One cell is kept at the right edge. */
|
|
88
|
+
function itemRow(item, cols, ascii) {
|
|
89
|
+
const end = cols - 1;
|
|
90
|
+
if (item.section !== undefined) {
|
|
91
|
+
const title = CAPABILITIES_TEXT.sections[item.section];
|
|
92
|
+
return [{ col: SECTION, text: lit(title), style: BOLD, width: Math.max(0, Math.min(title.length, end - SECTION)) }];
|
|
93
|
+
}
|
|
94
|
+
if (item.group !== undefined) {
|
|
95
|
+
const name = measured(item.group), note = item.note ? measured(item.note) : null;
|
|
96
|
+
const spans = [{ col: GROUP, text: name.text, style: DIM, width: Math.max(0, Math.min(name.width, end - GROUP)) }];
|
|
97
|
+
const at = GROUP + name.width;
|
|
98
|
+
if (note && at + 3 < end) spans.push({ col: at + 1, text: lit(dotOf(ascii)), style: DIM, width: 1 }, { col: at + 3, text: note.text, style: DIM, width: Math.max(0, end - at - 3) });
|
|
99
|
+
return spans.filter((span) => span.width > 0);
|
|
100
|
+
}
|
|
101
|
+
const look = (own) => (item.selected ? SELECTED : own);
|
|
102
|
+
const spans = item.selected ? [{ col: 0, width: cols, style: SELECTED }, { col: 0, text: lit(marksOf(ascii).selected), style: SELECTED, width: 1 }] : [];
|
|
103
|
+
const layer = item.layer ? measured(item.layer) : null;
|
|
104
|
+
return [...spans, ...nameThen(measured(item.name), layer ? [{ text: layer.text, width: layer.width, style: DIM }] : [], NAME, end, look)];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** `size.rows` rows for the list pane, `size.cols` wide: the model's window of the sections, the
|
|
108
|
+
* groups and the capabilities (after the heading of a failed re-read, when there is one) and on
|
|
109
|
+
* the last row what is cut off; or the one body the catalog's state gives: reading, a failed first
|
|
110
|
+
* read (its sentence, then the key that reads again), an empty catalog, nothing matching the
|
|
111
|
+
* filter, no workspace of this machine. */
|
|
112
|
+
export function capabilitiesList(m, size) {
|
|
113
|
+
const c = m.capabilities, ascii = m.ascii;
|
|
114
|
+
const rows = Array.from({ length: size.rows }, () => []);
|
|
115
|
+
if (size.rows < 1 || !c) return rows;
|
|
116
|
+
const width = Math.max(0, size.cols - SENTENCE_INDENT - 1);
|
|
117
|
+
/** A line of the TUI's own, dim, from row `at` on: the rows it took. */
|
|
118
|
+
const own = (text, at) => {
|
|
119
|
+
const lines = ownLines(ownText(text, ascii), width).slice(0, Math.max(0, size.rows - at));
|
|
120
|
+
lines.forEach((line, i) => { rows[at + i] = [{ col: SENTENCE_INDENT, text: lit(line), style: DIM, width }]; });
|
|
121
|
+
return lines.length;
|
|
122
|
+
};
|
|
123
|
+
if (c.local === false) { own(CAPABILITIES_TEXT.noWorkspace, 0); return rows; }
|
|
124
|
+
if (!capabilitiesListed(c)) {
|
|
125
|
+
if (c.state === "failed") {
|
|
126
|
+
// The sentence from outside, whole where the rows allow, and under it the key that reads again.
|
|
127
|
+
const retry = keyOf(m, "refresh");
|
|
128
|
+
const lines = shownLines(c.failure, width, Math.max(1, size.rows - (retry ? 1 : 0)), { ascii });
|
|
129
|
+
lines.forEach((line, i) => { rows[i] = [{ col: SENTENCE_INDENT, text: line, width }]; });
|
|
130
|
+
if (retry && lines.length < size.rows) {
|
|
131
|
+
const at = lines.length, words = SENTENCE_INDENT + retry.width + 1;
|
|
132
|
+
rows[at] = [{ col: SENTENCE_INDENT, text: retry.text, style: BOLD, width: Math.min(retry.width, width) },
|
|
133
|
+
...(words < size.cols - 1 ? [{ col: words, text: lit(CAPABILITIES_TEXT.retry), style: DIM, width: size.cols - 1 - words }] : [])];
|
|
134
|
+
}
|
|
135
|
+
} else own(c.state === "none" ? CAPABILITIES_TEXT.none : CAPABILITIES_TEXT.reading, 0);
|
|
136
|
+
return rows;
|
|
137
|
+
}
|
|
138
|
+
let at = 0;
|
|
139
|
+
if (c.heading) rows[at++] = headingRow(c.heading, size.cols, ascii);
|
|
140
|
+
if (c.state === "none" || c.state === "nomatch") own(CAPABILITIES_TEXT[c.state], at);
|
|
141
|
+
else c.list.forEach((item, i) => { if (at + i < size.rows) rows[at + i] = itemRow(item, size.cols, ascii); });
|
|
142
|
+
const note = cutNote(c.above ?? 0, c.below ?? 0);
|
|
143
|
+
if (note) rows[size.rows - 1] = [{ col: SENTENCE_INDENT, text: lit(note), style: DIM, width: Math.max(0, size.cols - SENTENCE_INDENT) }];
|
|
144
|
+
return rows;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** `{ rows, mark }`: every row of the selected capability's detail for a pane `cols` wide, before it
|
|
148
|
+
* is scrolled, and the row of the marked soul of "Used by" (-1 when none is marked). Top to bottom:
|
|
149
|
+
* the name and its layer's label, a failed re-read's sentence (in the warning style; it says so in
|
|
150
|
+
* words), the description; where it comes from (each fact `label value`); what it provides (each
|
|
151
|
+
* kind its names, flowed, or the shared word for none or not listable); and the souls that use it,
|
|
152
|
+
* eight at most and then `+n`, each its colour mark, its name, a dim count of its instances that
|
|
153
|
+
* carry it and how many of those are on an older version. A section with nothing to say is left out. */
|
|
154
|
+
export function capabilityDetailRows(m, cols) {
|
|
155
|
+
const d = m.capabilities?.detail;
|
|
156
|
+
if (!d) return { rows: [], mark: -1 };
|
|
157
|
+
const ascii = m.ascii, wide = Math.max(0, cols - LEFT), inner = Math.max(0, cols - INNER);
|
|
158
|
+
const label = (text, col = LEFT) => { const t = measured(text); return { col, text: t.text, style: DIM, width: Math.max(0, Math.min(t.width, cols - col)) }; };
|
|
159
|
+
const layer = d.layer ? measured(d.layer) : null;
|
|
160
|
+
const rows = [nameThen(measured(d.name), layer ? [{ text: layer.text, width: layer.width, style: DIM }] : [], LEFT, cols, (own) => (own === PLAIN ? BOLD : own))];
|
|
161
|
+
/** Safe lines placed at `col`, each `width` cells, the first beside `first` when given. */
|
|
162
|
+
const lines = (list, col, width, look, first = null) => list.forEach((line, i) => rows.push([...(i === 0 && first ? [first] : []), { col, text: line, width, ...(look ? { style: look } : {}) }]));
|
|
163
|
+
/** Facts `{ label, value }` under a section's heading: the labels in a column of their own, and
|
|
164
|
+
* each value beside its label, wrapped, or under it when the column leaves too few cells (and
|
|
165
|
+
* none at all in a pane with no cell for it). */
|
|
166
|
+
const facts = (list, value) => {
|
|
167
|
+
const names = list.map((fact) => measured(fact.label));
|
|
168
|
+
const column = Math.max(0, ...names.map((name) => name.width));
|
|
169
|
+
const beside = inner - column - 2 >= VALUE_MIN;
|
|
170
|
+
list.forEach((fact, i) => {
|
|
171
|
+
const name = { col: INNER, text: names[i].text, style: DIM, width: Math.min(names[i].width, inner) };
|
|
172
|
+
if (beside) value(fact, INNER + column + 2, inner - column - 2, name);
|
|
173
|
+
else { rows.push([name]); if (inner - 2 >= 1) value(fact, INNER + 2, inner - 2, null); }
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
const blank = () => rows.push([]);
|
|
177
|
+
|
|
178
|
+
if (d.failure) lines(shownLines(d.failure, wide, WRAP_ROWS, { ascii }), LEFT, wide, WARN);
|
|
179
|
+
lines(shownLines(d.description, wide, DESCRIPTION_ROWS, { ascii }), LEFT, wide);
|
|
180
|
+
|
|
181
|
+
if (d.comesFrom.length) {
|
|
182
|
+
blank();
|
|
183
|
+
rows.push([label(d.words.comesFrom)]);
|
|
184
|
+
facts(d.comesFrom, (fact, col, width, name) => lines(shownLines(fact.value, width, WRAP_ROWS, { ascii }), col, width, null, name));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (d.provides.length) {
|
|
188
|
+
blank();
|
|
189
|
+
rows.push([label(d.words.provides)]);
|
|
190
|
+
const comma = { text: lit(","), width: 1, glue: true };
|
|
191
|
+
facts(d.provides, (kind, col, width, name) => {
|
|
192
|
+
if (kind.said) { lines(shownLines(kind.said, width, WRAP_ROWS, { ascii }), col, width, DIM, name); return; }
|
|
193
|
+
const set = width < 1 ? [] : flowed(kind.names.map((each, i, all) => [measured(each), ...(i < all.length - 1 ? [comma] : [])]), width);
|
|
194
|
+
if (!set.length) { if (name) rows.push([name]); return; }
|
|
195
|
+
set.forEach((spans, i) => rows.push([...(i === 0 && name ? [name] : []), ...spans.map((span) => ({ ...span, col: span.col + col }))]));
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const u = d.used;
|
|
200
|
+
blank();
|
|
201
|
+
const count = u.count ? measured(u.count) : null, heading = label(d.words.usedBy);
|
|
202
|
+
rows.push([heading, ...(count && LEFT + heading.width + 2 < cols ? [{ col: LEFT + heading.width + 2, text: count.text, style: DIM, width: Math.max(0, Math.min(count.width, cols - LEFT - heading.width - 2)) }] : [])]);
|
|
203
|
+
let mark = -1;
|
|
204
|
+
if (u.state === "reading") lines([lit(ownText(CAPABILITIES_TEXT.readingSouls, ascii))], INNER, inner, DIM);
|
|
205
|
+
else if (u.state === "failed") lines(shownLines(u.failure, inner, WRAP_ROWS, { ascii }), INNER, inner, WARN);
|
|
206
|
+
else if (u.empty) lines(shownLines(u.empty, inner, WRAP_ROWS, { ascii }), INNER, inner, DIM);
|
|
207
|
+
const sign = ascii ? COUNT_SIGN.ascii : COUNT_SIGN.utf8, soulMark = ascii ? SOUL_MARK.ascii : SOUL_MARK.utf8, end = cols - 1;
|
|
208
|
+
u.shown.forEach((user, i) => {
|
|
209
|
+
const marked = i === m.capabilities.mark;
|
|
210
|
+
if (marked) mark = rows.length;
|
|
211
|
+
const look = (own) => (marked ? SELECTED : own);
|
|
212
|
+
const colour = typeof user.color === "string" && COLORS.includes(user.color) ? user.color : null;
|
|
213
|
+
const spans = marked ? [{ col: LEFT, width: Math.max(0, cols - LEFT), style: SELECTED }, { col: LEFT, text: lit(">"), style: SELECTED, width: 1 }] : [];
|
|
214
|
+
spans.push({ col: INNER, text: lit(soulMark), style: look(colour ? style({ fg: colour }) : PLAIN), width: 1 });
|
|
215
|
+
const counted = `${sign}${user.count}`;
|
|
216
|
+
const after = [{ text: lit(counted), width: counted.length, style: DIM }];
|
|
217
|
+
if (user.behind) { const behind = measured(user.behind); after.push({ text: lit(dotOf(ascii)), width: 1, style: DIM }, { text: behind.text, width: behind.width, style: WARN }); }
|
|
218
|
+
rows.push([...spans, ...nameThen(measured(user.name), after, INNER + 2, end, look)]);
|
|
219
|
+
});
|
|
220
|
+
if (u.more > 0) rows.push([{ col: INNER, text: lit(`+${u.more}`), style: DIM, width: `+${u.more}`.length }]);
|
|
221
|
+
return { rows, mark };
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** `{ rows, extent, top }`: `size.rows` rows of the detail for a pane `size.cols` wide, scrolled to
|
|
225
|
+
* the model's `detailTop`, or the least from there that shows the marked soul while the detail was
|
|
226
|
+
* not scrolled away from it (`keep`); how many rows the whole detail has; and the row it was drawn
|
|
227
|
+
* from, which the loop gives the store. The pane with the focus says so with `>` beside the title,
|
|
228
|
+
* never by an attribute alone (views/detail.mjs). */
|
|
229
|
+
export function capabilityDetail(m, size) {
|
|
230
|
+
const { rows: all, mark } = capabilityDetailRows(m, size.cols);
|
|
231
|
+
const rows = Array.from({ length: size.rows }, () => []);
|
|
232
|
+
const c = m.capabilities;
|
|
233
|
+
const win = windowOf({ top: c?.detailTop ?? 0, count: all.length, height: size.rows, keep: c?.keep && mark >= 0 ? mark : -1 });
|
|
234
|
+
all.slice(win.top, win.top + win.size).forEach((spans, i) => { rows[i] = spans; });
|
|
235
|
+
const note = cutNote(win.above, win.below);
|
|
236
|
+
if (note && size.rows > 0) rows[size.rows - 1] = [{ col: LEFT, text: lit(note), style: DIM, width: Math.max(0, size.cols - LEFT) }];
|
|
237
|
+
if (c?.focus === "detail" && size.rows > 0 && all.length) rows[0] = [{ col: 0, text: lit(">"), style: BOLD, width: 1 }, ...rows[0]];
|
|
238
|
+
return { rows, extent: all.length, top: win.top };
|
|
239
|
+
}
|