@awebai/oats 0.63.0 → 0.65.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 +14 -1
- package/bin/oats.mjs +158 -26
- package/docs/desktop-cli-api.md +127 -3
- package/docs/desktop.md +14 -5
- package/docs/execution-targets.md +9 -5
- package/docs/first-team.md +6 -0
- package/docs/implementation.md +17 -3
- package/docs/official-catalog.md +1 -1
- package/docs/packages.md +5 -5
- package/docs/release-notes/v0.64.0.md +105 -0
- package/docs/release-notes/v0.65.0.md +187 -0
- package/docs/souls-and-instances.md +26 -6
- package/docs/tui.md +416 -238
- package/docs/upgrading.md +2 -1
- package/docs/workspaces.md +125 -1
- package/lib/core.mjs +43 -11
- package/lib/deployments.mjs +325 -0
- package/lib/resolved-deployment.mjs +37 -0
- package/lib/session-input.mjs +12 -2
- package/lib/workspace.mjs +2 -0
- package/package-catalog.json +1 -1
- package/package.json +1 -1
- package/packages/client/cli-locator.mjs +2 -2
- package/packages/client/deployment-label.mjs +2 -2
- package/packages/client/deployment-list-cli.mjs +98 -0
- package/packages/client/deployment-list.mjs +91 -0
- package/packages/client/instance-tree.mjs +53 -3
- package/packages/client/keymap.mjs +106 -0
- package/packages/client/own-codes.mjs +2 -0
- package/packages/client/panel-views.mjs +1 -1
- package/packages/client/roster-sections.mjs +22 -6
- package/packages/client/workspace-admission.mjs +2 -1
- package/packages/tui/README.md +4 -4
- package/packages/tui/lib/actions.mjs +29 -5
- package/packages/tui/lib/client.mjs +3 -1
- package/packages/tui/lib/config.mjs +21 -14
- package/packages/tui/lib/main.mjs +108 -31
- package/packages/tui/lib/model.mjs +71 -41
- package/packages/tui/lib/read.mjs +15 -45
- package/packages/tui/lib/store.mjs +158 -39
- package/packages/tui/lib/term/through.mjs +40 -18
- package/packages/tui/lib/views/act.mjs +17 -13
- package/packages/tui/lib/views/frame.mjs +418 -421
- package/packages/tui/lib/views/help.mjs +41 -19
- package/packages/tui/lib/views/instances.mjs +38 -9
- package/packages/tui/lib/views/switcher.mjs +65 -21
- package/skills/oats-getting-started/SKILL.md +440 -170
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// text. Pure: no IO, no clock, no escape byte. The keys are generated from the table the reducer
|
|
3
3
|
// acts on, so the help names every key that does something and no key that does not; the marks
|
|
4
4
|
// are the ones the list and the switcher draw (views/instances.mjs, views/switcher.mjs).
|
|
5
|
-
import { LEADER, keyLabel } from "../actions.mjs";
|
|
5
|
+
import { LEADER, backKeyLabel, keyLabel } from "../actions.mjs";
|
|
6
6
|
import { lit, ownEllipsis } from "../term/text.mjs";
|
|
7
7
|
import { style } from "../term/style.mjs";
|
|
8
8
|
import { cutNote, marksOf, measured } from "./instances.mjs";
|
|
@@ -41,14 +41,14 @@ export const NOT_YET = Object.freeze([
|
|
|
41
41
|
Object.freeze({ what: "add a machine to this workspace", command: "oats server connect <id> --ssh <alias>" }),
|
|
42
42
|
Object.freeze({ what: "check a machine", command: "oats server check <id>" }),
|
|
43
43
|
Object.freeze({ what: "remove a machine", command: "oats server remove <id>" }),
|
|
44
|
-
// The switcher lists the deployments opened in this run and those
|
|
45
|
-
Object.freeze({ what: "open a deployment
|
|
44
|
+
// The switcher lists the deployments opened in this run and those on this computer's list, and no other.
|
|
45
|
+
Object.freeze({ what: "open a deployment that is not listed", command: "oats tui --dir <path>" }),
|
|
46
46
|
]);
|
|
47
47
|
/** What a user should know of the machines the list shows, each a sentence of the TUI's own: a
|
|
48
48
|
* limit that no command lifts is stated too. */
|
|
49
49
|
export const MACHINES = Object.freeze([
|
|
50
|
-
"A machine's rows are what it reported at the time on its heading (in a view of one machine,
|
|
51
|
-
"Nothing is kept on disk: a machine not reached in this run is listed by its own name.",
|
|
50
|
+
"A machine's rows are what it reported at the time on its heading (in a view of one machine, at the top of this help).",
|
|
51
|
+
"Nothing of its own is kept on disk: a machine not reached in this run is listed by its own name.",
|
|
52
52
|
"Souls and Capabilities are this machine's.",
|
|
53
53
|
]);
|
|
54
54
|
/** The views the frame names, what each holds, and what to run for what a view does not do yet.
|
|
@@ -71,7 +71,7 @@ const flow = (pieces, room) => pieces.reduce((lines, piece) => {
|
|
|
71
71
|
* pieces that are never broken (a word, or a whole command: a command cut in two cannot be
|
|
72
72
|
* typed). What does not fit `cols` goes on in the same column on the next row. A table with a
|
|
73
73
|
* piece wider than that column puts every meaning under its entry instead, so no row is cut at
|
|
74
|
-
* the smallest width the frame draws at. */
|
|
74
|
+
* the smallest width the frame draws at; a piece wider than even that starts further left. */
|
|
75
75
|
function table(pairs, cols, look) {
|
|
76
76
|
// An entry is the TUI's own word, or text made elsewhere with its width (a key's label). A
|
|
77
77
|
// third member makes rows of its own under the entry's meaning: given the meaning's column and
|
|
@@ -83,7 +83,9 @@ function table(pairs, cols, look) {
|
|
|
83
83
|
const stacked = pairs.some(([, pieces]) => pieces.some((piece) => column + piece.length > cols));
|
|
84
84
|
const at = stacked ? INDENT + 2 : column;
|
|
85
85
|
return pairs.flatMap(([left, pieces]) => {
|
|
86
|
-
|
|
86
|
+
// A row wider than its column (a whole command, in a narrow area) starts as far left as it
|
|
87
|
+
// must to stand whole, down to the area's first column: a command cut short cannot be typed.
|
|
88
|
+
const lines = flow(pieces, cols - at).map((text) => ({ col: Math.max(0, Math.min(at, cols - text.length)), text: lit(text) }));
|
|
87
89
|
const more = (under.get(pieces)?.(cols - at) ?? []).map((spans) => spans.map((span) => ({ ...span, col: span.col + at })));
|
|
88
90
|
return [...(stacked ? [[entry(left)], ...lines.map((line) => [line])] : lines.map((line, i) => (i === 0 ? [entry(left), line] : [line]))), ...more];
|
|
89
91
|
});
|
|
@@ -97,15 +99,18 @@ export const OPEN_RULES = Object.freeze([
|
|
|
97
99
|
"Up to 4 terminals are open at a time, each a tab. They have no scrollback but the viewer's own, and no mouse.",
|
|
98
100
|
"docs/tui.md has the keys that can be the leader.",
|
|
99
101
|
]);
|
|
100
|
-
/** The rows under the line of `open`, in `room` cells: the leader
|
|
101
|
-
*
|
|
102
|
-
* each sentence on as many rows as it needs. */
|
|
102
|
+
/** The rows under the line of `open`, in `room` cells: the leader then Esc, which takes the focus
|
|
103
|
+
* from the open terminal, and the leader twice, which types it into the terminal (tui.json's
|
|
104
|
+
* open.detachKey, text from outside), then OPEN_RULES, each sentence on as many rows as it needs. */
|
|
103
105
|
function openRows(detachKey, room) {
|
|
104
|
-
const
|
|
105
|
-
const
|
|
106
|
+
const label = backKeyLabel(detachKey), esc = keyLabel(LEADER.find((entry) => entry.does === "list").keys[0]);
|
|
107
|
+
const pair = (keys, said) => {
|
|
108
|
+
const key = keyText(keys), lines = flow(words(said), Math.max(1, room - key.width - 1));
|
|
109
|
+
return [[{ col: 0, text: key.text, width: key.width }, { col: key.width + 1, text: lit(lines[0]) }], ...lines.slice(1).map((text) => [{ col: key.width + 1, text: lit(text) }])];
|
|
110
|
+
};
|
|
106
111
|
return [
|
|
107
|
-
|
|
108
|
-
...
|
|
112
|
+
...pair(`${label} ${esc}`, "takes the focus from the terminal back to the list; the agent keeps running."),
|
|
113
|
+
...pair(`${label} ${label}`, "types the leader into the terminal."),
|
|
109
114
|
...OPEN_RULES.flatMap((sentence) => flow(words(sentence), room).map((text) => [{ col: 0, text: lit(text) }])),
|
|
110
115
|
];
|
|
111
116
|
}
|
|
@@ -124,10 +129,22 @@ const sentences = (list, cols) => list.flatMap((sentence) => {
|
|
|
124
129
|
return [first, ...flow(rest.flatMap(words), cols - 2 * INDENT - 2)].map((text, i) => [{ col: INDENT + (i ? 2 : 0), text: lit(text) }]);
|
|
125
130
|
});
|
|
126
131
|
|
|
132
|
+
/** What the leader pressed again does, the last line of the leader's table. */
|
|
133
|
+
export const LEADER_AGAIN = "the leader again: types it into the terminal that has the focus; with the list focused, closes the hint";
|
|
134
|
+
|
|
135
|
+
/** The palette's keys (docs/tui.md, "The palette"): it reads its keys itself, so they are fixed
|
|
136
|
+
* and the TUI's words. */
|
|
137
|
+
export const PALETTE_KEYS = Object.freeze([
|
|
138
|
+
Object.freeze(["Up, Down", "move; typing narrows the list"]),
|
|
139
|
+
Object.freeze(["Enter", "run the selected row"]),
|
|
140
|
+
Object.freeze(["Esc", "close the palette"]),
|
|
141
|
+
]);
|
|
142
|
+
const paletteRows = (cols) => [heading("The palette"), [], ...table(PALETTE_KEYS.map(([keys, said]) => [keys, words(said)]), cols, KEYS)];
|
|
143
|
+
|
|
127
144
|
/** The leader's rows (docs/tui.md, "The leader"): its key, then the table of what each key after
|
|
128
145
|
* it does (actions.mjs LEADER), from every focus. */
|
|
129
146
|
function leaderRows(detachKey, cols) {
|
|
130
|
-
const key = keyText(detachKey);
|
|
147
|
+
const key = keyText(backKeyLabel(detachKey));
|
|
131
148
|
// The sentence after the key on as many rows as it needs, its later rows under its first.
|
|
132
149
|
const at = INDENT + key.width + 1;
|
|
133
150
|
const lead = flow(words("then one of these keys, from every focus; a terminal too:"), Math.max(1, cols - INDENT - at));
|
|
@@ -136,8 +153,11 @@ function leaderRows(detachKey, cols) {
|
|
|
136
153
|
[],
|
|
137
154
|
[{ col: INDENT, text: key.text, width: key.width, style: KEYS }, { col: at, text: lit(lead[0]) }],
|
|
138
155
|
...lead.slice(1).map((text) => [{ col: at, text: lit(text) }]),
|
|
139
|
-
...table(LEADER.map((entry) => [entry.keys.map(keyLabel).join(", "),
|
|
140
|
-
words(entry.
|
|
156
|
+
...table([...LEADER.map((entry) => [entry.keys.map(keyLabel).join(", "),
|
|
157
|
+
words(entry.terminal ? `${entry.label}, while a terminal is open` : entry.label)]),
|
|
158
|
+
// The leader again is the user's key, so it is not in the table: it types the leader into the
|
|
159
|
+
// terminal that has the focus, and with the list focused only closes the hint.
|
|
160
|
+
[key, words(LEADER_AGAIN)]], cols, KEYS),
|
|
141
161
|
];
|
|
142
162
|
}
|
|
143
163
|
|
|
@@ -148,7 +168,7 @@ export const SPAWN_KEYS = Object.freeze([
|
|
|
148
168
|
Object.freeze(["Enter", "pick the selected soul; a soul marked ! would be refused here and cannot be picked"]),
|
|
149
169
|
Object.freeze(["Esc", "close the soul picker"]),
|
|
150
170
|
Object.freeze(["Tab, Shift+Tab", "move the focus in the preview: Spawn, name, child of, then each fold"]),
|
|
151
|
-
Object.freeze(["Enter", "do what the
|
|
171
|
+
Object.freeze(["Enter", "do what the cheat sheet names: on Spawn spawn, on name keep the name and read the preview again, on child of switch it, on a fold open or close it"]),
|
|
152
172
|
Object.freeze(["Esc", "from a field back to Spawn; from Spawn back to the picker, or to the list"]),
|
|
153
173
|
]);
|
|
154
174
|
export const SPAWN_RULES = Object.freeze([
|
|
@@ -161,7 +181,7 @@ const spawnRows = (cols) => [heading("The spawn prompt"), [], ...table(SPAWN_KEY
|
|
|
161
181
|
* now. An action that does one thing in each view has a line per view, its key on each; under
|
|
162
182
|
* the line of opening an agent stand the back key (`detachKey`, tui.json's `open.detachKey`) and
|
|
163
183
|
* the rules of OPEN_RULES; under the line of the last act, ACT_RULES. After the leader's table,
|
|
164
|
-
* the spawn prompt's
|
|
184
|
+
* the palette's keys (PALETTE_KEYS) and the spawn prompt's (SPAWN_KEYS, SPAWN_RULES). */
|
|
165
185
|
export function helpRows(actions, ascii, cols = 100, detachKey = null) {
|
|
166
186
|
const marks = marksOf(ascii);
|
|
167
187
|
const closing = keyText(["close", "help"].map((id) => actions.find((action) => action.id === id)).filter((action) => action?.keys.length).map((action) => keyLabel(action.keys[0])).join(" or "));
|
|
@@ -176,6 +196,8 @@ export function helpRows(actions, ascii, cols = 100, detachKey = null) {
|
|
|
176
196
|
}), cols, KEYS),
|
|
177
197
|
...(detachKey !== null ? [[], ...leaderRows(detachKey, cols)] : []),
|
|
178
198
|
[],
|
|
199
|
+
...paletteRows(cols),
|
|
200
|
+
[],
|
|
179
201
|
...spawnRows(cols),
|
|
180
202
|
[],
|
|
181
203
|
heading("Marks"),
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// many it folds away, `+n`. In a view of two or more deployments the list also holds a heading
|
|
8
8
|
// per deployment and the sentences the model sets under one: a heading says in words what it is
|
|
9
9
|
// of.
|
|
10
|
+
import { keyLabel } from "../actions.mjs";
|
|
10
11
|
import { lit, shown, shownEnd, textOf } from "../term/text.mjs";
|
|
11
12
|
import { style } from "../term/style.mjs";
|
|
12
13
|
import { textWidth } from "../term/width.mjs";
|
|
@@ -28,8 +29,11 @@ const WAITING = 4;
|
|
|
28
29
|
const LEAD = 4;
|
|
29
30
|
/** The column of the state mark, before a row's indent. */
|
|
30
31
|
const MARK = 2;
|
|
32
|
+
/** The cells a row's name keeps before its word, and the fewest a cut word is drawn in: under
|
|
33
|
+
* them the word is left out, since a few cells of it say nothing. */
|
|
34
|
+
const NAME_LEAST = 16, WORD_LEAST = 6;
|
|
31
35
|
|
|
32
|
-
/** A heading starts here: at the margin the
|
|
36
|
+
/** A heading starts here: at the margin the sidebar keeps, not at a row's indent. */
|
|
33
37
|
const HEAD = 1;
|
|
34
38
|
/** The cells between two parts of a heading. */
|
|
35
39
|
const GAP = 2;
|
|
@@ -52,10 +56,13 @@ const WAITS_SELECTED = style({ reverse: true, bold: true });
|
|
|
52
56
|
|
|
53
57
|
export const EMPTY_TEXT = Object.freeze({
|
|
54
58
|
reading: "Reading the deployment.",
|
|
55
|
-
none: "No
|
|
59
|
+
none: "No agents yet",
|
|
56
60
|
nomatch: "No instance matches the filter.",
|
|
57
61
|
});
|
|
58
62
|
|
|
63
|
+
/** The words after EMPTY_TEXT.none and the key that spawns (docs/tui.md, "What it shows"). */
|
|
64
|
+
export const SPAWNS_ONE = "spawns one";
|
|
65
|
+
|
|
59
66
|
/** Text the TUI did not write, with the cells its display takes: `{ text, width }`. What stands
|
|
60
67
|
* after it on a row is placed by that width. */
|
|
61
68
|
export function measured(value) {
|
|
@@ -68,27 +75,33 @@ const waitingText = (row) => (row.below > 99 ? "!99+" : row.below > 0 ? `!${row.
|
|
|
68
75
|
/** One instance's row in a pane `cols` wide: the state mark, the name cut to what is left, on a
|
|
69
76
|
* folded row `+n` after the name, the row's word (when it has one) in the word column, and the
|
|
70
77
|
* waiting mark at the edge. A row with no word gives its name the word column's cells too. The
|
|
71
|
-
* name
|
|
72
|
-
*
|
|
78
|
+
* name wins over the word: it keeps NAME_LEAST cells (all of it when it is shorter), and when the
|
|
79
|
+
* word column would leave it fewer, the word is cut to what the name leaves, after it, or given
|
|
80
|
+
* up under WORD_LEAST cells; the mark and the detail still say it. The name is cut before `+n`
|
|
81
|
+
* is: the count stays whole beside what is left of the name. Every span has its width, so no
|
|
82
|
+
* text can pass its column whatever the terminal thinks a character takes. */
|
|
73
83
|
function instanceRow(row, cols, wordWidth, marks) {
|
|
74
84
|
const look = (own) => (row.selected ? SELECTED : own);
|
|
75
85
|
const at = Math.min(row.depth, LEVELS - 1) * INDENT;
|
|
76
|
-
const worded = wordWidth > 0 && row.word !== null && row.word !== undefined;
|
|
77
|
-
const wordCol = Math.max(0, cols - WAITING - 1 - wordWidth);
|
|
78
|
-
const nameCol = LEAD + at, nameEnd = worded ? wordCol - 2 : cols - WAITING - 1;
|
|
79
86
|
const fold = row.folded > 0 ? `+${row.folded}` : null;
|
|
87
|
+
const nameCol = LEAD + at, room = cols - WAITING - 1 - nameCol;
|
|
88
|
+
const name = measured(row.name), claim = Math.min(name.width + (fold ? fold.length + 1 : 0), NAME_LEAST);
|
|
89
|
+
// The word's cells: its column's, or what the name's claim leaves of the row, or none.
|
|
90
|
+
const left = room - claim - 2;
|
|
91
|
+
const wordCells = wordWidth > 0 && row.word !== null && row.word !== undefined ? (left >= wordWidth ? wordWidth : left >= WORD_LEAST ? left : 0) : 0;
|
|
92
|
+
const wordCol = left >= wordWidth ? cols - WAITING - 1 - wordWidth : nameCol + claim + 2;
|
|
93
|
+
const nameEnd = wordCells ? wordCol - 2 : cols - WAITING - 1;
|
|
80
94
|
const spans = [];
|
|
81
95
|
if (row.selected) spans.push({ col: 0, width: cols, style: SELECTED }, { col: 0, text: lit(marks.selected), style: SELECTED, width: 1 });
|
|
82
96
|
spans.push({ col: MARK + at, text: lit(marks[row.mark] ?? marks.unknown), style: look(LOOK[row.mark] ?? LOOK.unknown), width: 1 });
|
|
83
97
|
if (nameEnd > nameCol) {
|
|
84
|
-
const name = measured(row.name);
|
|
85
98
|
// The count and the gap before it, when there is room for them and for a cell of the name.
|
|
86
99
|
const after = fold && nameEnd - nameCol > fold.length + 1 ? fold.length + 1 : 0;
|
|
87
100
|
const nameWidth = Math.min(name.width, nameEnd - nameCol - after);
|
|
88
101
|
spans.push({ col: nameCol, text: name.text, style: look(PLAIN), width: after ? nameWidth : nameEnd - nameCol });
|
|
89
102
|
if (after) spans.push({ col: nameCol + nameWidth + 1, text: lit(fold), style: look(DIM), width: fold.length });
|
|
90
103
|
}
|
|
91
|
-
if (
|
|
104
|
+
if (wordCells) spans.push({ col: wordCol, text: shown(row.word), style: look(DIM), width: wordCells });
|
|
92
105
|
const waits = waitingText(row);
|
|
93
106
|
if (waits) spans.push({ col: cols - waits.length, text: lit(waits), style: row.selected ? WAITS_SELECTED : WAITS, width: waits.length });
|
|
94
107
|
return spans;
|
|
@@ -132,6 +145,21 @@ export function cutNote(above, below) {
|
|
|
132
145
|
return [above > 0 ? `${above} more above` : null, below > 0 ? `${below} more below` : null].filter(Boolean).join(", ");
|
|
133
146
|
}
|
|
134
147
|
|
|
148
|
+
/** The one row of a view with no instances, in `aside` cells: `No agents yet: n spawns one`, with
|
|
149
|
+
* the key the user's table gives `spawn` (text from outside: tui.json may rebind it), or `No
|
|
150
|
+
* agents yet.` while it has none. Cut at the edge, the key before the words after it. */
|
|
151
|
+
function noneRow(m, aside) {
|
|
152
|
+
const action = (m.actions ?? []).find((a) => a.id === "spawn" && a.keys.length);
|
|
153
|
+
if (!action) return [{ col: SENTENCE_INDENT, text: lit(`${EMPTY_TEXT.none}.`), style: DIM, width: aside }];
|
|
154
|
+
const end = SENTENCE_INDENT + aside, lead = `${EMPTY_TEXT.none}:`, key = measured(keyLabel(action.keys[0]));
|
|
155
|
+
const at = SENTENCE_INDENT + lead.length + 1, after = at + key.width + 1;
|
|
156
|
+
return [
|
|
157
|
+
{ col: SENTENCE_INDENT, text: lit(lead), style: DIM, width: Math.min(lead.length, aside) },
|
|
158
|
+
{ col: at, text: key.text, style: DIM, width: Math.max(0, Math.min(key.width, end - at)) },
|
|
159
|
+
{ col: after, text: lit(SPAWNS_ONE), style: DIM, width: Math.max(0, Math.min(SPAWNS_ONE.length, end - after)) },
|
|
160
|
+
].filter((span) => span.width > 0);
|
|
161
|
+
}
|
|
162
|
+
|
|
135
163
|
/** `size.rows` rows for a pane `size.cols` wide: the model's window of the list, one item per row,
|
|
136
164
|
* and on the last row what is cut off above and below. An item is an instance, a deployment's
|
|
137
165
|
* heading, one row of a sentence the model wrapped (safe text already, placed as it is), a line
|
|
@@ -146,6 +174,7 @@ export function instances(m, size) {
|
|
|
146
174
|
if (item.heading) rows[i] = headingRow(item.heading, size.cols, m.ascii);
|
|
147
175
|
else if (item.line) rows[i] = [{ col: SENTENCE_INDENT, text: item.line, width: sentence }];
|
|
148
176
|
else if (item.own) rows[i] = [{ col: SENTENCE_INDENT, text: lit(item.own), style: DIM, width: sentence }];
|
|
177
|
+
else if (item.empty === "none") rows[i] = noneRow(m, aside);
|
|
149
178
|
else if (item.empty) rows[i] = [{ col: SENTENCE_INDENT, text: lit(EMPTY_TEXT[item.empty]), style: DIM, width: aside }];
|
|
150
179
|
else rows[i] = instanceRow(item, size.cols, m.wordWidth, marks);
|
|
151
180
|
});
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// The switcher of workspaces: (model, area) -> rows of spans. Pure: no IO, no clock, no escape
|
|
2
|
-
// byte. It
|
|
3
|
-
// its deployments are not live are the shared home's words and go through shown(), as
|
|
4
|
-
//
|
|
2
|
+
// byte. It is drawn in the area views/frame.mjs gives it: the main area. A workspace's name, its machines and how many of
|
|
3
|
+
// its deployments are not live are the shared home's words and go through shown(), as do a listed
|
|
4
|
+
// deployment's name and path and what the kernel said; the marks, the headings of its own and its
|
|
5
|
+
// few sentences are the TUI's.
|
|
5
6
|
// Nothing is told by colour alone: the selected row carries `>` as well as reverse video, and
|
|
6
7
|
// the workspace that is open carries `*`.
|
|
7
|
-
import { lit, shown } from "../term/text.mjs";
|
|
8
|
+
import { lit, shown, shownLines } from "../term/text.mjs";
|
|
8
9
|
import { style } from "../term/style.mjs";
|
|
9
10
|
import { cutNote, measured } from "./instances.mjs";
|
|
10
11
|
|
|
@@ -17,12 +18,22 @@ export const SWITCHER_TEXT = Object.freeze({
|
|
|
17
18
|
nomatch: "No workspace matches the filter.",
|
|
18
19
|
gone: "That workspace is no longer listed.",
|
|
19
20
|
refused: "Not an OATS deployment any more.",
|
|
21
|
+
/** A stale row of this computer's deployments list, in place of its path, by the kernel's state
|
|
22
|
+
* (packages/client/deployment-list.mjs DEPLOYMENT_STATES). Such a row does not open. */
|
|
23
|
+
states: Object.freeze({ missing: "Not found.", "not-a-deployment": "Not an OATS deployment any more.", unreadable: "Can't be read." }),
|
|
24
|
+
/** The two lines of a Remove asked, over the rows: the selected row stays marked under them. */
|
|
25
|
+
removing: Object.freeze(["Remove the selected row from this computer's list?", "Enter removes it; other keys keep it. Its folder stays."]),
|
|
26
|
+
/** What a Remove answered, and that the list could not be read: each with a name or the kernel's
|
|
27
|
+
* message, shown as it came. */
|
|
28
|
+
removed: (name) => `${name} was removed from this computer's list.`,
|
|
29
|
+
notRemoved: (name, message) => `${name} was not removed from this computer's list: ${message}`,
|
|
30
|
+
unread: (message) => `This computer's list of deployments could not be read: ${message}`,
|
|
20
31
|
});
|
|
21
32
|
|
|
22
33
|
/** The columns of a choice: the selection mark in the first cell, the open mark, then the label.
|
|
23
34
|
* A heading and every line that is not a choice start two cells before the labels. */
|
|
24
35
|
const OPEN = 2, LABEL = 4, ASIDE = LABEL - 2;
|
|
25
|
-
/** One cell of margin at the right edge, as the
|
|
36
|
+
/** One cell of margin at the right edge, as the sidebar keeps. */
|
|
26
37
|
const MARGIN = 1;
|
|
27
38
|
/** The cells between two columns. */
|
|
28
39
|
const GAP = 2;
|
|
@@ -35,7 +46,7 @@ const PLAIN = style();
|
|
|
35
46
|
const DIM = style({ dim: true });
|
|
36
47
|
const SELECTED = style({ reverse: true });
|
|
37
48
|
|
|
38
|
-
/** One choice in an area `cols` wide: a workspace, or a
|
|
49
|
+
/** One choice in an area `cols` wide: a workspace, or a listed deployment that is not opened yet. What a
|
|
39
50
|
* workspace says of its deployments that are not live stands whole at the right edge; when the
|
|
40
51
|
* row is too narrow the place is cut first, then the label. */
|
|
41
52
|
function choiceRow(item, cols) {
|
|
@@ -49,29 +60,63 @@ function choiceRow(item, cols) {
|
|
|
49
60
|
const liveCol = Math.max(LABEL, edge - live.width);
|
|
50
61
|
// Where the label and the place end: at the edge, or two cells before what stands there.
|
|
51
62
|
const limit = live.width ? liveCol - GAP : edge;
|
|
52
|
-
// A
|
|
53
|
-
const
|
|
63
|
+
// A row that turned out not to be a deployment, and a stale one, say so where its path stood.
|
|
64
|
+
const own = item.refused ? SWITCHER_TEXT.refused : SWITCHER_TEXT.states[item.state] ?? null;
|
|
65
|
+
const place = own !== null ? { text: lit(own), width: own.length } : measured(item.place);
|
|
54
66
|
// With no place to show, the label has the row.
|
|
55
67
|
const labelWidth = Math.max(0, Math.min(place.width ? labelCols : limit - LABEL, limit - LABEL));
|
|
56
68
|
if (labelWidth) spans.push({ col: LABEL, text: shown(item.label), style: look(PLAIN), width: labelWidth });
|
|
57
|
-
if (place.width && limit > placeCol) spans.push({ col: placeCol, text: place.text, style: look(
|
|
69
|
+
if (place.width && limit > placeCol) spans.push({ col: placeCol, text: place.text, style: look(own !== null ? PLAIN : DIM), width: limit - placeCol });
|
|
58
70
|
if (live.width) spans.push({ col: liveCol, text: live.text, style: look(PLAIN), width: Math.max(0, Math.min(live.width, edge - liveCol)) });
|
|
59
71
|
return spans.filter((span) => span.width > 0);
|
|
60
72
|
}
|
|
61
73
|
|
|
62
|
-
/** The
|
|
63
|
-
*
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
74
|
+
/** The most rows one sentence with a name or the kernel's words in it takes above the choices: the
|
|
75
|
+
* kernel's message says what to do, so it is wrapped, not cut, up to this. */
|
|
76
|
+
const LEAD_ROWS = 4;
|
|
77
|
+
|
|
78
|
+
/** The rows that stand above the choices, top to bottom, for an area `cols` wide, each
|
|
79
|
+
* `{ text, style }` with `text` made (term/text.mjs): what happened (that the workspace which was
|
|
80
|
+
* open is no longer listed, what a Remove answered), that this computer's deployments list could
|
|
81
|
+
* not be read, and a Remove asked: each something to read, so not dim, and each wrapped to the
|
|
82
|
+
* width: a sentence with a name or the kernel's words in it is shown as it came. lib/model.mjs counts these rows to make
|
|
83
|
+
* the window of the choices that much shorter (switcherLead), so it never hides a choice. */
|
|
84
|
+
export function leadRows(s, cols, { ascii = false } = {}) {
|
|
85
|
+
const width = Math.max(1, cols - ASIDE - MARGIN), rows = [];
|
|
86
|
+
// A sentence of the TUI's own is broken at its spaces (the main area beside the sidebar can be narrow).
|
|
87
|
+
const own = (text) => { for (const line of wrapped(text, width)) rows.push({ text: lit(line), style: PLAIN }); };
|
|
88
|
+
const shared = (text) => { for (const line of shownLines(text, width, LEAD_ROWS, { ascii })) rows.push({ text: line, style: PLAIN }); };
|
|
89
|
+
if (s.said === "gone") own(SWITCHER_TEXT.gone);
|
|
90
|
+
else if (s.said?.removed !== undefined) shared(SWITCHER_TEXT.removed(s.said.removed));
|
|
91
|
+
else if (s.said?.notRemoved !== undefined) shared(SWITCHER_TEXT.notRemoved(s.said.notRemoved, s.said.message));
|
|
92
|
+
if (s.failure) shared(SWITCHER_TEXT.unread(s.failure));
|
|
93
|
+
if (s.removing) for (const text of SWITCHER_TEXT.removing) own(text);
|
|
94
|
+
return rows;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The rows above the choices: leadRows, then why no workspace is listed (dim, as the list's own
|
|
98
|
+
* empty line is), which stands only when there is no choice to hide. */
|
|
99
|
+
function leadLines(s, cols, ascii) {
|
|
100
|
+
const lines = leadRows(s, cols, { ascii });
|
|
101
|
+
const dim = (text) => lines.push({ text: lit(text), style: DIM });
|
|
102
|
+
if (s.empty === "nomatch") dim(SWITCHER_TEXT.nomatch);
|
|
69
103
|
if (s.empty === "none") {
|
|
70
|
-
const [first, second, command] = SWITCHER_TEXT.none, whole = `${second} ${command}
|
|
71
|
-
|
|
104
|
+
const [first, second, command] = SWITCHER_TEXT.none, whole = `${second} ${command}`, room = cols - MARGIN - ASIDE;
|
|
105
|
+
// A sentence wider than the area (the main area beside the sidebar can be narrow) goes on on the
|
|
106
|
+
// next row, broken at its spaces; the command is a piece of its own, never broken.
|
|
107
|
+
for (const text of [...wrapped(first, room), ...(whole.length <= room ? [whole] : [...wrapped(second, room), command])]) dim(text);
|
|
72
108
|
}
|
|
73
109
|
return lines;
|
|
74
110
|
}
|
|
111
|
+
/** A sentence of the TUI's own on rows of at most `room` cells, broken at its spaces. */
|
|
112
|
+
function wrapped(text, room) {
|
|
113
|
+
return text.split(" ").reduce((rows, word) => {
|
|
114
|
+
const last = rows.at(-1);
|
|
115
|
+
if (last !== undefined && last.length + 1 + word.length <= room) rows[rows.length - 1] = `${last} ${word}`;
|
|
116
|
+
else rows.push(word);
|
|
117
|
+
return rows;
|
|
118
|
+
}, []);
|
|
119
|
+
}
|
|
75
120
|
|
|
76
121
|
/** `size.rows` rows for an area `size.cols` wide: the lines above, the model's window of the
|
|
77
122
|
* switcher's rows, one item per row, and on the last row what is cut off above and below.
|
|
@@ -83,13 +128,12 @@ export function switcher(m, size) {
|
|
|
83
128
|
if (!s || size.rows < 1) return rows;
|
|
84
129
|
const { cols } = size, aside = Math.max(0, cols - ASIDE - MARGIN);
|
|
85
130
|
const note = cutNote(s.above, s.below);
|
|
86
|
-
const lead = leadLines(s, cols).slice(0, Math.max(0, size.rows - s.rows.length - (note ? 1 : 0)));
|
|
87
|
-
lead.forEach((line, i) => { rows[i] = [{ col: ASIDE, text:
|
|
131
|
+
const lead = leadLines(s, cols, m.ascii === true).slice(0, Math.max(0, size.rows - s.rows.length - (note ? 1 : 0)));
|
|
132
|
+
lead.forEach((line, i) => { rows[i] = [{ col: ASIDE, text: line.text, style: line.style, width: aside }]; });
|
|
88
133
|
s.rows.forEach((item, i) => {
|
|
89
134
|
const at = lead.length + i;
|
|
90
135
|
if (at >= size.rows) return;
|
|
91
136
|
if (item.heading !== undefined) rows[at] = [{ col: ASIDE, text: item.shared ? shown(item.heading) : lit(item.heading), style: DIM, width: aside }];
|
|
92
|
-
else if (item.own !== undefined) rows[at] = [{ col: LABEL, text: lit(item.own), style: DIM, width: Math.max(0, cols - LABEL - MARGIN) }];
|
|
93
137
|
else rows[at] = choiceRow(item, cols);
|
|
94
138
|
});
|
|
95
139
|
if (note) rows[size.rows - 1] = [{ col: ASIDE, text: lit(note), style: DIM, width: aside }];
|