@awebai/oats 0.65.0 → 0.67.1
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 +11 -5
- package/bin/oats.mjs +74 -20
- package/docs/capabilities.md +4 -4
- package/docs/capability-manifest.schema.json +1 -1
- package/docs/desktop-cli-api.md +222 -10
- package/docs/desktop.md +101 -22
- package/docs/implementation.md +16 -6
- package/docs/integrations.md +1 -1
- package/docs/official-catalog.md +2 -2
- package/docs/packages.md +7 -7
- package/docs/release-lane.md +16 -0
- package/docs/release-notes/v0.66.0.md +183 -0
- package/docs/release-notes/v0.67.0.md +366 -0
- package/docs/release-notes/v0.67.1.md +64 -0
- package/docs/servers.md +5 -4
- package/docs/souls-and-instances.md +20 -3
- package/docs/tui.md +658 -143
- package/docs/upgrading.md +107 -25
- package/docs/workspaces.md +9 -2
- package/lib/capability-contract.mjs +2 -2
- package/lib/core.mjs +126 -54
- package/lib/deployments.mjs +21 -5
- package/lib/instance-color.mjs +58 -0
- package/lib/instance-inspect.mjs +107 -23
- package/lib/instance-lifecycle.mjs +21 -1
- package/lib/instance-naming.mjs +187 -0
- package/lib/instance-resolution.mjs +5 -1
- package/lib/materialize.mjs +62 -11
- package/lib/servers.mjs +15 -6
- package/lib/soul-composition.mjs +7 -3
- package/package-catalog.json +2 -2
- package/package.json +1 -1
- package/packages/client/cli-adapter.mjs +37 -5
- package/packages/client/cli-locator.mjs +2 -2
- package/packages/client/composed-gate.mjs +10 -2
- package/packages/client/deployment-data.mjs +5 -0
- package/packages/client/deployment-identity.mjs +40 -0
- package/packages/client/deployment-panel.mjs +3 -1
- package/packages/client/inspect-boundary.mjs +11 -7
- package/packages/client/inspect-cache.mjs +2 -2
- package/packages/client/instance-name.mjs +28 -0
- package/packages/client/instance-presentation.mjs +11 -0
- package/packages/client/keymap.mjs +99 -11
- package/packages/client/keys-file.mjs +122 -0
- package/packages/client/machine-contract.mjs +1 -5
- package/packages/client/own-codes.mjs +4 -2
- package/packages/client/panel-views.mjs +62 -9
- package/packages/client/spawn-naming.mjs +31 -0
- package/packages/client/spawn-preview-cli.mjs +22 -7
- package/packages/client/spawn-preview-contract.mjs +24 -0
- package/packages/client/spawn-preview-facts.mjs +8 -4
- package/packages/client/spawn-preview.mjs +47 -2
- package/packages/record/bin/setup.mjs +10 -2
- package/packages/record/docs/capture-service.md +45 -6
- package/packages/record/lib/capture-service-install.mjs +6 -95
- package/packages/record/lib/capture-setup-write.mjs +233 -0
- package/packages/tui/README.md +9 -8
- package/packages/tui/lib/actions.mjs +108 -64
- package/packages/tui/lib/client.mjs +8 -3
- package/packages/tui/lib/config.mjs +208 -26
- package/packages/tui/lib/main.mjs +91 -20
- package/packages/tui/lib/model.mjs +167 -61
- package/packages/tui/lib/read.mjs +53 -1
- package/packages/tui/lib/store.mjs +156 -47
- package/packages/tui/lib/term/keys.mjs +150 -34
- package/packages/tui/lib/term/kitty.mjs +223 -0
- package/packages/tui/lib/term/through.mjs +174 -27
- package/packages/tui/lib/term/tty.mjs +43 -12
- package/packages/tui/lib/views/frame.mjs +158 -79
- package/packages/tui/lib/views/help.mjs +143 -21
- package/packages/tui/lib/views/instances.mjs +59 -20
- package/packages/tui/lib/views/palette.mjs +14 -4
- package/packages/tui/lib/views/souls.mjs +2 -2
- package/packages/tui/lib/views/switcher.mjs +6 -1
- package/skills/oats-getting-started/SKILL.md +107 -34
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
// whole width, and the detail and every overlay are a page over the whole screen. There is no
|
|
11
11
|
// header and no footer. The TUI's own words are lit(); everything else is shown(). Meaning never
|
|
12
12
|
// rests on colour alone: what is dim or bold also says what it is in words or by a mark.
|
|
13
|
-
import { LEADER, backKeyLabel, keyLabel } from "../actions.mjs";
|
|
13
|
+
import { LEADER, backKeyLabel, keyLabel, keysTogether } from "../actions.mjs";
|
|
14
14
|
import { lit, ownEllipsis, shown, shownLines, textOf } from "../term/text.mjs";
|
|
15
15
|
import { style } from "../term/style.mjs";
|
|
16
16
|
import { act } from "./act.mjs";
|
|
17
17
|
import { detail } from "./detail.mjs";
|
|
18
|
-
import { help, keyText } from "./help.mjs";
|
|
18
|
+
import { help, keyText, paletteGroupKeys } from "./help.mjs";
|
|
19
19
|
import { instances, measured } from "./instances.mjs";
|
|
20
20
|
import { textWidth } from "../term/width.mjs";
|
|
21
21
|
import { palette } from "./palette.mjs";
|
|
@@ -65,7 +65,7 @@ const FOCUSED = style({ bold: true, reverse: true });
|
|
|
65
65
|
|
|
66
66
|
const clamp = (n, low, high) => Math.min(Math.max(n, low), high);
|
|
67
67
|
const tooSmall = (size) => size.cols < MIN_SIZE.cols || size.rows < MIN_SIZE.rows;
|
|
68
|
-
/** The leader's label, spelt for people (`Alt+O
|
|
68
|
+
/** The leader's label, spelt for people (`Ctrl+X` by default, `Alt+O`): tui.json's open.detachKey is the
|
|
69
69
|
* user's, so it is text from outside. */
|
|
70
70
|
const leaderText = (m) => keyText(backKeyLabel(m.detachKey));
|
|
71
71
|
|
|
@@ -280,12 +280,16 @@ function types(m) {
|
|
|
280
280
|
}
|
|
281
281
|
|
|
282
282
|
/** THE CHEAT SHEET (docs/tui.md, "The cheat sheet"): the keys that apply now, one per row, the
|
|
283
|
-
* leader first in every focus (`
|
|
283
|
+
* leader first in every focus (`Ctrl+X commands`), then the palette, `help` and `quit` last. While
|
|
284
284
|
* the leader waits for its key it is the leader's hint (leaderHints). While what is typed goes to
|
|
285
|
-
* the agent the TUI reads the leader only: the leader then Esc gives the list the
|
|
286
|
-
* leader twice types the leader into the terminal
|
|
287
|
-
*
|
|
288
|
-
*
|
|
285
|
+
* the agent the TUI reads the leader and the chords only: the leader then Esc gives the list the
|
|
286
|
+
* focus, and the leader twice types the leader into the terminal; while the terminal confirms the
|
|
287
|
+
* kitty keyboard protocol the chords lead there (docs/tui.md, "Chords"; chordHints), the leader's
|
|
288
|
+
* hints after them, and the leader is the last given up; without it the leader's lead, and the
|
|
289
|
+
* Alt+Shift arrows, the chords that come then, follow them (the first given up). In the palette
|
|
290
|
+
* (its group keys last, where the TUI has them, so the first given up: paletteGroups), the spawn prompt
|
|
291
|
+
* (spawnHints), a confirmation, the filter field, the help and the switcher, how to work them: the
|
|
292
|
+
* keys they read are their own, so they are the TUI's words, but for the confirmation's close key and the
|
|
289
293
|
* field's clear, which are the user's. Else it is small: a view's list or its detail names what
|
|
290
294
|
* Enter does now, and the rest stays the leader's hint's, the palette's and the help's. In the list
|
|
291
295
|
* of instances Enter is `open` while it would open the selected agent's terminal and `focus
|
|
@@ -294,8 +298,9 @@ function types(m) {
|
|
|
294
298
|
* from the list and the soul's instances from the detail; in the Capabilities view the detail,
|
|
295
299
|
* and from it the marked soul. With the detail's focus the key that goes back to the list
|
|
296
300
|
* (`Tab back`) comes before it, and `spawn` after it where it spawns (the list of instances, the
|
|
297
|
-
* Souls view of a workspace of this machine)
|
|
298
|
-
*
|
|
301
|
+
* Souls view of a workspace of this machine), then in the Instances view `workspaces` (the
|
|
302
|
+
* switcher). An action with no key (tui.json may unbind one) has no hint. The views have no
|
|
303
|
+
* hint: the accordion names their keys. When rows are short the sheet
|
|
299
304
|
* gives up rows from its end (keptHints), down to the leader alone. */
|
|
300
305
|
function cheatSheet(m) {
|
|
301
306
|
const action = (id) => (m.actions ?? []).find((a) => a.id === id && a.keys.length);
|
|
@@ -309,9 +314,10 @@ function cheatSheet(m) {
|
|
|
309
314
|
const listing = !["help", "switcher", "souls", "capabilities"].includes(m.view);
|
|
310
315
|
if (listing && m.terminal?.focus === "terminal" && !m.palette && !m.spawn) {
|
|
311
316
|
const label = backKeyLabel(m.detachKey), list = keyLabel(LEADER.find((entry) => entry.does === "list").keys[0]);
|
|
312
|
-
|
|
317
|
+
const leader = [made("list", keyText(`${label} ${list}`), "the list"), made("again", keyText(`${label} ${label}`), types(m))];
|
|
318
|
+
return m.kitty ? [...chordHints(m), ...led(leader)] : [...led(leader), ...chordHints(m)];
|
|
313
319
|
}
|
|
314
|
-
if (m.palette) return led([own("run", "Enter", "run"), own("move", "Up/Down", "move"), own("close", "Esc", "close")]);
|
|
320
|
+
if (m.palette) return led([own("run", "Enter", "run"), own("move", "Up/Down", "move"), own("close", "Esc", "close"), paletteGroups(m)]);
|
|
315
321
|
if (m.spawn) return led(spawnHints(m.spawn, m.ascii));
|
|
316
322
|
if (m.view !== "help" && filter?.editing) return led([own("keep", "Enter", "keep"), hint("close", "clear")]);
|
|
317
323
|
if (m.view === "act" && m.act) {
|
|
@@ -331,7 +337,35 @@ function cheatSheet(m) {
|
|
|
331
337
|
: capability?.detail ? (capability.focus !== "detail" ? [hint("open", "detail")] : capability.mark >= 0 ? [hint("open", "soul")] : []) : [];
|
|
332
338
|
const detailed = soul ? soul.focus === "detail" && Boolean(soul.detail) : capability ? capability.focus === "detail" && Boolean(capability.detail) : listing && m.focus === "detail";
|
|
333
339
|
const spawns = listing || (soul && soul.local !== false);
|
|
334
|
-
return led([hint("palette"), ...(detailed ? [hint("detail", "back")] : []), ...enter, ...(spawns ? [hint("spawn")] : []), hint("help"), hint("quit")]);
|
|
340
|
+
return led([hint("palette"), ...(detailed ? [hint("detail", "back")] : []), ...enter, ...(spawns ? [hint("spawn")] : []), ...(listing ? [hint("workspaces")] : []), hint("help"), hint("quit")]);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** The palette's own keys as one hint (docs/tui.md, "The palette"): the first row of the group
|
|
344
|
+
* before and of the next, `Alt+Shift+Up/Down group` (keysTogether), from the model's
|
|
345
|
+
* `paletteKeys` (views/help.mjs paletteGroupKeys); null where the TUI has none (macOS). */
|
|
346
|
+
function paletteGroups(m) {
|
|
347
|
+
const pair = paletteGroupKeys(m.paletteKeys);
|
|
348
|
+
return pair === null ? null : own("group", keysTogether(pair), "group");
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** The chords a terminal's cheat sheet names under the kitty keyboard protocol, in this order, a
|
|
352
|
+
* pair as one hint, each with the TUI's word: what is reached most from a terminal. */
|
|
353
|
+
const SHEET_CHORDS = Object.freeze([
|
|
354
|
+
Object.freeze([["palette"], "palette"]),
|
|
355
|
+
Object.freeze([["previous", "next"], "agent"]),
|
|
356
|
+
Object.freeze([["tab-previous", "tab-next"], "tab"]),
|
|
357
|
+
Object.freeze([["close-terminal"], "close"]),
|
|
358
|
+
Object.freeze([["zoom"], "zoom"]),
|
|
359
|
+
]);
|
|
360
|
+
/** The chord hints of a terminal's focus (docs/tui.md, "Chords"): those of SHEET_CHORDS read now
|
|
361
|
+
* (the model's `chords`: tui.json may have taken a key; without the protocol the Alt+Shift
|
|
362
|
+
* arrows alone), the tabs' only
|
|
363
|
+
* with two tabs or more, as the leader's hint has them. A pair's keys share their modifiers:
|
|
364
|
+
* `Alt+Shift+Up/Down` (keysTogether). They stand in a block of their own (cheatRows). */
|
|
365
|
+
function chordHints(m) {
|
|
366
|
+
const keyOf = new Map((m.chords ?? []).map(([key, does]) => [does, key]));
|
|
367
|
+
return SHEET_CHORDS.filter(([list]) => list.every((does) => keyOf.has(does)) && (list[0] !== "tab-previous" || (m.tabs?.length ?? 0) > 1))
|
|
368
|
+
.map(([list, word]) => ({ ...made(`chord-${list[0]}`, keyText(keysTogether(list.map((does) => keyOf.get(does)))), word), block: "chords" }));
|
|
335
369
|
}
|
|
336
370
|
|
|
337
371
|
/** The spawn prompt's hints (docs/tui.md, "Spawning an agent"): the keys the prompt reads are its
|
|
@@ -373,26 +407,49 @@ function leaderHints(m) {
|
|
|
373
407
|
];
|
|
374
408
|
}
|
|
375
409
|
|
|
376
|
-
/** The hints that stand in `count` rows: given up from the end, down to the leader alone;
|
|
377
|
-
* leader's hint keeps its last, the list's, while it has two rows. */
|
|
410
|
+
/** The hints that stand in `count` rows: given up from the end, down to the leader alone (givenUp);
|
|
411
|
+
* the leader's hint keeps its last, the list's, while it has two rows. */
|
|
378
412
|
function keptHints(m, hints, count) {
|
|
379
413
|
if (count >= hints.length) return hints;
|
|
380
414
|
if (m.leader && count >= 2) return [...hints.slice(0, count - 1), hints.at(-1)];
|
|
381
|
-
|
|
415
|
+
let kept = hints;
|
|
416
|
+
while (kept.length > Math.max(1, count)) kept = givenUp(kept);
|
|
417
|
+
return kept;
|
|
418
|
+
}
|
|
419
|
+
/** `hints` with one given up: the last but the leader's (`commands`), which goes last of all. In a
|
|
420
|
+
* sheet that leads with the leader that is the last; in one that leads with the chords (a
|
|
421
|
+
* terminal's, under the kitty keyboard protocol) the leader stays after them. */
|
|
422
|
+
function givenUp(hints) {
|
|
423
|
+
const at = hints.findLastIndex((h) => h.id !== "leader");
|
|
424
|
+
return at < 0 ? hints.slice(0, -1) : [...hints.slice(0, at), ...hints.slice(at + 1)];
|
|
382
425
|
}
|
|
383
426
|
|
|
384
427
|
/** The cheat sheet's rows, `cols` wide: each hint's key in bold from the margin, and what it does
|
|
385
|
-
* in a column of its own after the widest key; a word is cut at the edge.
|
|
428
|
+
* in a column of its own after the widest key; a word is cut at the edge. The hints of a `block`
|
|
429
|
+
* (the chords') have a column of their own, after their own widest key, and as far left as
|
|
430
|
+
* leaves their words whole: those words are the TUI's own and short, where their keys are long
|
|
431
|
+
* (`Alt+Shift+Left/Right` in the 30 cells beside a terminal). */
|
|
386
432
|
function cheatRows(hints, cols) {
|
|
387
433
|
const edge = cols - MARGIN;
|
|
388
|
-
const
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
{
|
|
392
|
-
|
|
393
|
-
|
|
434
|
+
const columns = new Map();
|
|
435
|
+
for (const h of hints) {
|
|
436
|
+
const c = columns.get(h.block) ?? { widest: 0, word: 6 };
|
|
437
|
+
columns.set(h.block, { widest: Math.max(c.widest, h.key.width), word: h.block === undefined ? c.word : Math.max(c.word, h.word.width) });
|
|
438
|
+
}
|
|
439
|
+
return hints.map((h) => {
|
|
440
|
+
const c = columns.get(h.block), wordCol = Math.min(MARGIN + c.widest + GAP, Math.max(MARGIN + 1, edge - c.word));
|
|
441
|
+
return [
|
|
442
|
+
{ col: MARGIN, text: h.key.text, style: BOLD, width: Math.max(0, Math.min(h.key.width, wordCol - 1 - MARGIN)) },
|
|
443
|
+
...h.word.spans.map((span) => ({ ...span, col: wordCol + span.col, width: Math.max(0, Math.min(span.width, edge - wordCol - span.col)) })),
|
|
444
|
+
].filter((span) => span.width > 0);
|
|
445
|
+
});
|
|
394
446
|
}
|
|
395
447
|
|
|
448
|
+
/** The cheat sheet a title row carries (withKeys): without the kitty keyboard protocol the
|
|
449
|
+
* Alt+Shift arrows follow the leader's hints in the sheet's rows, but a title row keeps to the
|
|
450
|
+
* leader's; under it the chords lead there as in the rows. */
|
|
451
|
+
const titleSheet = (m) => cheatSheet(m).filter((h) => m.kitty || h.block !== "chords");
|
|
452
|
+
|
|
396
453
|
/** An overlay's or a detail page's first row on a narrow terminal, where it has the whole screen:
|
|
397
454
|
* its essential keys (the cheat sheet's, but for the leader, the palette, help and quit) at the
|
|
398
455
|
* right, dim, as many as fit after what the row holds, given up from the end. With `first`, the
|
|
@@ -406,8 +463,9 @@ function withKeys(given, hints, cols, { skip = ["leader", "palette", "help", "qu
|
|
|
406
463
|
// What the row holds ends where its text does: a span may be given more cells than its text takes.
|
|
407
464
|
const end = row.reduce((most, span) => (span.text !== undefined ? Math.max(most, span.col + Math.min(span.width ?? Infinity, textWidth(textOf(span.text)))) : most), 0);
|
|
408
465
|
let kept = keys;
|
|
409
|
-
// Given up from the end; with `last`, the last is kept as long as one
|
|
410
|
-
|
|
466
|
+
// Given up from the end, the leader last (givenUp); with `last`, the last is kept as long as one
|
|
467
|
+
// other is (the leader's `Esc`).
|
|
468
|
+
while (kept.length && end + GAP + widthOf(kept) > cols - MARGIN) kept = last && kept.length > 1 ? [...kept.slice(0, -2), kept.at(-1)] : givenUp(kept);
|
|
411
469
|
const spans = [];
|
|
412
470
|
let col = cols - MARGIN - widthOf(kept);
|
|
413
471
|
for (const h of kept) {
|
|
@@ -514,7 +572,7 @@ function framed(m, size) {
|
|
|
514
572
|
const overlay = (drawn) => {
|
|
515
573
|
if (g.wide) { sidebar(m, g, rows, listOf(m, g)); barred(m, rows, g.listCols); }
|
|
516
574
|
drawn.forEach((spans, i) => { if (i < size.rows) rows[i] = [...rows[i], ...placed(spans, main.col)]; });
|
|
517
|
-
if (!g.wide) rows[0] = withKeys(rows[0],
|
|
575
|
+
if (!g.wide) rows[0] = withKeys(rows[0], titleSheet(m), cols);
|
|
518
576
|
};
|
|
519
577
|
|
|
520
578
|
// The palette, whatever is under it.
|
|
@@ -539,7 +597,7 @@ function framed(m, size) {
|
|
|
539
597
|
}
|
|
540
598
|
// The help, under its top row (readRow).
|
|
541
599
|
if (m.view === "help") {
|
|
542
|
-
const drawn = help(m.actions, { cols: main.cols, rows: size.rows - 1 }, { top: m.helpTop, ascii: m.ascii, detachKey: m.detachKey });
|
|
600
|
+
const drawn = help(m.actions, { cols: main.cols, rows: size.rows - 1 }, { top: m.helpTop, ascii: m.ascii, detachKey: m.detachKey, chords: m.chords ?? null, chordsLead: m.kitty === true, paletteKeys: m.paletteKeys ?? null, keys: m.keys ?? null });
|
|
543
601
|
overlay([readRow(m), ...drawn.rows]);
|
|
544
602
|
return { rows, page: Math.max(1, g.page), extent: drawn.extent, room: Math.max(1, size.rows - 1) };
|
|
545
603
|
}
|
|
@@ -584,7 +642,7 @@ function framed(m, size) {
|
|
|
584
642
|
// Over the whole screen no cheat sheet is drawn: the terminal's title row, the TUI's own, carries
|
|
585
643
|
// its keys at the right instead (the leader, then Esc for the list), and while the leader waits,
|
|
586
644
|
// the leader's hint, as many as fit, its last (`Esc the list`) kept.
|
|
587
|
-
if (zoomed) rows[area.title] = m.leader ? withKeys(rows[area.title], leaderHints(m), cols, { skip: [], last: true }) : withKeys(rows[area.title],
|
|
645
|
+
if (zoomed) rows[area.title] = m.leader ? withKeys(rows[area.title], leaderHints(m), cols, { skip: [], last: true }) : withKeys(rows[area.title], titleSheet(m), cols, { skip: ["again"] });
|
|
588
646
|
// The focused group's terminal, when it shows one: the agent's cursor, where the agent has it,
|
|
589
647
|
// while what is typed goes to the agent.
|
|
590
648
|
const shownArea = area !== null && area.id !== null && m.terminal ? { title: area.title, top: area.top, col: area.col, cols: area.cols, rows: area.rows, whole: area.whole } : null;
|
|
@@ -679,25 +737,41 @@ function terminalAt(m, size, g) {
|
|
|
679
737
|
|
|
680
738
|
/** A hidden tab's mark for output since it was last shown (docs/tui.md, "Tabs"). */
|
|
681
739
|
const ACTIVITY = "\u2022";
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
740
|
+
/** What stands between a tab's agent and its machine, another machine's: ` · ` (` - ` in ASCII). */
|
|
741
|
+
const tabDot = (ascii) => (ascii ? "-" : "\u00b7");
|
|
742
|
+
/** The divider between two tabs: one dim cell. */
|
|
743
|
+
const tabDivider = (ascii) => (ascii ? "|" : "\u2502");
|
|
744
|
+
/** The shown tab's own mark, which no style is needed to read: brackets in place of its side cells. */
|
|
745
|
+
const SHOWN_SIDES = Object.freeze(["[", "]"]);
|
|
746
|
+
/** A hidden tab's look: dim. Its activity mark is not: it is what a glance looks for. */
|
|
747
|
+
const HIDDEN = DIM;
|
|
748
|
+
/** The machine of the shown tab while what is typed goes to it: dim, in the tab's reverse video. */
|
|
749
|
+
const FOCUSED_DIM = style({ dim: true, reverse: true });
|
|
750
|
+
|
|
751
|
+
/** THE TAB BAR (docs/tui.md, "Tabs"), the top row of a group's region whenever it shows a tab, one
|
|
752
|
+
* or many, as a terminal's own tabs read: each tab in order, a dim `│` (`|` in ASCII) between two.
|
|
753
|
+
* A tab is its agent's name with a cell on each side, `•` (`*` in ASCII) after the name of a hidden
|
|
754
|
+
* one whose agent wrote since it was shown, and ` · <machine>` dim (` - ` in ASCII) inside it for
|
|
755
|
+
* another machine's agent. The shown tab reads as the front one: `[` and `]` stand in its side
|
|
756
|
+
* cells (a mark no style is needed for: it holds under NO_COLOR and in ASCII), its name is bold,
|
|
757
|
+
* and the whole tab is in reverse video while what is typed goes to it; a hidden tab is dim.
|
|
758
|
+
* What does not fit is cut in this order: the hidden tabs' machines, then their names, each to an
|
|
759
|
+
* equal share of what the shown tab leaves with `…`, then the shown tab's machine, then the hidden
|
|
760
|
+
* tabs farthest from the shown one are left out (each takes its divider with it). The shown tab's
|
|
761
|
+
* name stays whole while the row can hold it, and is cut last. */
|
|
690
762
|
function stripRow(given, area, { focused, ascii }) {
|
|
691
|
-
const mark = ascii ? "*" : ACTIVITY;
|
|
692
|
-
const tabs = given.map((tab) => ({ ...tab, name: measured(tab.name), machine: tab.machine
|
|
693
|
-
const machineCells = (tab) => (tab.machine ?
|
|
763
|
+
const mark = ascii ? "*" : ACTIVITY, dot = tabDot(ascii);
|
|
764
|
+
const tabs = given.map((tab) => ({ ...tab, name: measured(tab.name), machine: tab.machine ? measured(tab.machine) : null, mark: !tab.shown && tab.activity === true }));
|
|
765
|
+
const machineCells = (tab) => (tab.machine ? 3 + tab.machine.width : 0);
|
|
694
766
|
const cellsOf = (tab, { machine, name = tab.name.width, dropped = false }) => (dropped ? 0 : 1 + name + (tab.mark ? 1 : 0) + (machine ? machineCells(tab) : 0) + 1);
|
|
695
|
-
const total = (plan) => tabs.reduce((sum, tab, i) => sum + cellsOf(tab, plan[i]), 0);
|
|
696
767
|
const plan = tabs.map((tab) => ({ machine: true, name: tab.name.width, dropped: false }));
|
|
697
|
-
|
|
698
|
-
const
|
|
699
|
-
|
|
700
|
-
const
|
|
768
|
+
// Each drawn tab after the first has its divider before it.
|
|
769
|
+
const total = () => tabs.reduce((sum, tab, i) => sum + cellsOf(tab, plan[i]), 0) + Math.max(0, plan.filter((p) => !p.dropped).length - 1);
|
|
770
|
+
const fits = () => total() <= area.cols;
|
|
771
|
+
const shown = Math.max(0, tabs.findIndex((tab) => tab.shown));
|
|
772
|
+
// The least a hidden tab is drawn in: a cell of its name (the cut mark), its mark, a cell each
|
|
773
|
+
// side, and its divider.
|
|
774
|
+
const least = (tab) => 4 + (tab.mark ? 1 : 0);
|
|
701
775
|
// The shown tab's cells are taken first; the hidden ones share the rest equally. Those that do
|
|
702
776
|
// not get even their least are left out, the farthest from the shown tab first.
|
|
703
777
|
const share = () => {
|
|
@@ -705,42 +779,56 @@ function stripRow(given, area, { focused, ascii }) {
|
|
|
705
779
|
const near = tabs.map((tab, i) => i).filter((i) => i !== shown).sort((a, b) => Math.abs(a - shown) - Math.abs(b - shown) || a - b);
|
|
706
780
|
const kept = [];
|
|
707
781
|
for (const i of near) { plan[i].dropped = left - least(tabs[i]) < 0; if (!plan[i].dropped) { kept.push(i); left -= least(tabs[i]); } }
|
|
708
|
-
const room = area.cols - cellsOf(tabs[shown], plan[shown]), each = Math.floor(room / Math.max(1, kept.length));
|
|
782
|
+
const room = area.cols - cellsOf(tabs[shown], plan[shown]) - kept.length, each = Math.floor(room / Math.max(1, kept.length));
|
|
709
783
|
for (const i of kept) plan[i].name = Math.max(1, Math.min(tabs[i].name.width, each - 2 - (tabs[i].mark ? 1 : 0)));
|
|
710
784
|
while (!fits() && kept.length) plan[kept.pop()].dropped = true;
|
|
711
785
|
};
|
|
712
786
|
if (!fits()) tabs.forEach((tab, i) => { if (i !== shown) plan[i].machine = false; });
|
|
713
787
|
if (!fits()) share();
|
|
714
|
-
if (plan.some((p) => p.dropped) && plan[shown].machine && tabs[shown].machine) { plan[shown].machine = false; plan.forEach((p) => { p.dropped = false; }); share(); }
|
|
788
|
+
if ((!fits() || plan.some((p) => p.dropped)) && plan[shown].machine && tabs[shown].machine) { plan[shown].machine = false; plan.forEach((p) => { p.dropped = false; }); share(); }
|
|
789
|
+
// A shown name wider than the row itself: cut, its brackets kept.
|
|
790
|
+
if (cellsOf(tabs[shown], plan[shown]) > area.cols) plan[shown].name = Math.max(1, area.cols - 2);
|
|
791
|
+
const cut = (tab, p) => (p.name < tab.name.width ? shownLines(textOf(tab.name.text), p.name, 1, { ascii })[0] ?? lit("") : tab.name.text);
|
|
715
792
|
const row = [];
|
|
716
|
-
let col = area.col;
|
|
717
793
|
const end = area.col + area.cols;
|
|
794
|
+
let col = area.col, first = true;
|
|
795
|
+
// `text` null is a blank cell (a hidden tab's side): its cells are passed over.
|
|
796
|
+
const put = (text, width, look) => {
|
|
797
|
+
const w = Math.max(0, Math.min(width, end - col));
|
|
798
|
+
if (w > 0 && text !== null) row.push({ col, text, width: w, ...(look ? { style: look } : {}) });
|
|
799
|
+
col += width;
|
|
800
|
+
};
|
|
718
801
|
tabs.forEach((tab, i) => {
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
802
|
+
const p = plan[i];
|
|
803
|
+
if (p.dropped || col >= end) return;
|
|
804
|
+
if (!first) put(lit(tabDivider(ascii)), 1, DIM);
|
|
805
|
+
first = false;
|
|
806
|
+
if (col >= end) return;
|
|
807
|
+
const front = tab.shown, reversed = front && focused;
|
|
808
|
+
const look = front ? (reversed ? FOCUSED : BOLD) : HIDDEN;
|
|
809
|
+
// In reverse while what is typed goes to it: the whole tab, its sides and machine included.
|
|
810
|
+
if (reversed) row.push({ col, width: Math.max(0, Math.min(cellsOf(tab, p), end - col)), style: FOCUSED });
|
|
811
|
+
const [left, right] = front ? SHOWN_SIDES.map((side) => lit(side)) : [null, null];
|
|
812
|
+
put(left, 1, look);
|
|
813
|
+
const name = cut(tab, p);
|
|
814
|
+
put(name, Math.min(p.name, textWidth(textOf(name))), look);
|
|
815
|
+
if (tab.mark) put(lit(mark), 1, null);
|
|
816
|
+
if (p.machine && tab.machine) {
|
|
817
|
+
const machineLook = reversed ? FOCUSED_DIM : DIM;
|
|
818
|
+
put(null, 1, null);
|
|
819
|
+
put(lit(dot), 1, machineLook);
|
|
820
|
+
put(null, 1, null);
|
|
821
|
+
put(tab.machine.text, tab.machine.width, machineLook);
|
|
732
822
|
}
|
|
733
|
-
|
|
823
|
+
put(right, 1, look);
|
|
734
824
|
});
|
|
735
825
|
return row;
|
|
736
826
|
}
|
|
737
827
|
|
|
738
|
-
/** The open terminal's rows from its
|
|
739
|
-
*
|
|
740
|
-
*
|
|
741
|
-
|
|
742
|
-
* first column and kept inside its cells. */
|
|
743
|
-
/** What an empty group shows (docs/tui.md, "Splits"), under an empty strip row: that Enter on an
|
|
828
|
+
/** The open terminal's rows from its top row: the tab bar (stripRow), then the shown agent's
|
|
829
|
+
* screen as the last capture made it (lib/panel.mjs, term/capture.mjs: spans of the agent's own
|
|
830
|
+
* text and styles), each row placed at the terminal's first column and kept inside its cells. */
|
|
831
|
+
/** What an empty group shows (docs/tui.md, "Splits"), under an empty tab bar row: that Enter on an
|
|
744
832
|
* agent in the list opens it here, in reverse while it is the focused group, then the leader's
|
|
745
833
|
* keys for the groups. */
|
|
746
834
|
const EMPTY_HINT = "Enter on an agent opens it here";
|
|
@@ -764,18 +852,9 @@ function regionRows(m, area) {
|
|
|
764
852
|
// The focused group's shown tab is in reverse while what is typed goes to it; the other group's
|
|
765
853
|
// is bold, never in reverse, so one terminal at a time reads as focused (T3).
|
|
766
854
|
const focused = area.focused && m.terminal?.focus === "terminal";
|
|
767
|
-
|
|
768
|
-
const
|
|
769
|
-
|
|
770
|
-
if (group.tabs.length > 1) title = stripRow(group.tabs, area, { focused, ascii: m.ascii });
|
|
771
|
-
else {
|
|
772
|
-
if (focused) title.push({ col: area.col, width: Math.min(area.cols, name.width + 2), style: FOCUSED });
|
|
773
|
-
title.push({ col: area.col + 1, text: name.text, style: focused ? FOCUSED : BOLD, width: Math.max(0, Math.min(name.width, area.cols - 2)) });
|
|
774
|
-
if (tab.machine) {
|
|
775
|
-
const where = measured(tab.machine), at = area.col + name.width + 3;
|
|
776
|
-
if (at + ON.length + 1 < area.col + area.cols) title.push({ col: at, text: lit(ON), style: DIM, width: ON.length }, { col: at + ON.length + 1, text: where.text, style: DIM, width: Math.max(0, area.col + area.cols - (at + ON.length + 1)) });
|
|
777
|
-
}
|
|
778
|
-
}
|
|
855
|
+
// A model made by hand may name its terminal and no tabs: its one tab is that terminal.
|
|
856
|
+
const tabs = group.tabs.length ? group.tabs : [{ name: m.terminal?.name, machine: m.terminal?.routed ? m.terminal.machine : null, shown: true, activity: false }];
|
|
857
|
+
const title = stripRow(tabs, area, { focused, ascii: m.ascii });
|
|
779
858
|
const screenOf = area.focused ? m.screen : m.screens?.get(group.shown) ?? null;
|
|
780
859
|
const lines = screenOf?.lines ?? [];
|
|
781
860
|
const body = Array.from({ length: area.rows }, (_, r) => (lines[r] ?? [])
|