@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
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
// The frame: (model, size) -> the rows of the whole screen. Pure: no IO, no clock, no escape
|
|
2
|
-
// byte.
|
|
3
|
-
//
|
|
4
|
-
// the
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
|
|
2
|
+
// byte. The screen is two things (docs/tui.md, "What it shows"): the sidebar on the left and the
|
|
3
|
+
// main area on the right, a rule between them over the whole height. The sidebar holds, from the
|
|
4
|
+
// top, the workspace's name, what stood above the panes (a deployment's state and reason, the
|
|
5
|
+
// note of a one-deployment view, the line after an open), the three views as an accordion (the
|
|
6
|
+
// open one's heading and its list: the instances, the souls or the capabilities) and the cheat
|
|
7
|
+
// sheet of the keys that apply now, the leader first. The main area holds the detail, or the open
|
|
8
|
+
// terminal (zoomed, over the whole screen), or an overlay: the switcher of workspaces, the
|
|
9
|
+
// palette, the spawn prompt, the help or a confirmation. Under WIDE columns the sidebar has the
|
|
10
|
+
// whole width, and the detail and every overlay are a page over the whole screen. There is no
|
|
11
|
+
// header and no footer. The TUI's own words are lit(); everything else is shown(). Meaning never
|
|
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";
|
|
11
14
|
import { lit, ownEllipsis, shown, shownLines, textOf } from "../term/text.mjs";
|
|
12
15
|
import { style } from "../term/style.mjs";
|
|
13
16
|
import { act } from "./act.mjs";
|
|
@@ -24,47 +27,47 @@ import { switcher } from "./switcher.mjs";
|
|
|
24
27
|
|
|
25
28
|
/** The frame is drawn from this size up (docs/tui.md); the design size is 80x24. */
|
|
26
29
|
export const MIN_SIZE = Object.freeze({ cols: 60, rows: 15 });
|
|
27
|
-
/** From this width up the
|
|
30
|
+
/** From this width up the main area stands beside the sidebar; under it, the sidebar has the whole
|
|
31
|
+
* width and the detail and the overlays are a page of their own. */
|
|
28
32
|
export const WIDE = 80;
|
|
29
|
-
/** The views, the
|
|
30
|
-
*
|
|
33
|
+
/** The views, the sidebar's accordion, in this order: each a row with its key dim at the right,
|
|
34
|
+
* the open one's in bold with its list under it. */
|
|
31
35
|
const VIEWS = Object.freeze([Object.freeze({ id: "instances", name: "Instances" }), Object.freeze({ id: "souls", name: "Souls" }), Object.freeze({ id: "capabilities", name: "Capabilities" })]);
|
|
32
|
-
/** The cells between two views' names: each name has one cell on each side of it (the reverse bar
|
|
33
|
-
* of the open one), and one between. */
|
|
34
|
-
const VIEW_GAP = 1;
|
|
35
36
|
const GAP = 3;
|
|
36
|
-
/** The least width of a terminal beside the
|
|
37
|
+
/** The least width of a terminal beside the sidebar: under it the terminal has the whole screen. */
|
|
37
38
|
export const PANEL_MIN = 40;
|
|
38
|
-
/** The most cells the
|
|
39
|
+
/** The most cells the sidebar keeps beside an open terminal: the agent's screen has the rest. */
|
|
39
40
|
export const LIST_BESIDE = 30;
|
|
40
|
-
/** One cell of margin on each side of the
|
|
41
|
+
/** One cell of margin on each side of the sidebar's rows. */
|
|
41
42
|
const MARGIN = 1;
|
|
42
43
|
/** The longest run one lit() holds with room to spare: the display filter bounds a line, and a
|
|
43
44
|
* terminal can be wider than that bound. */
|
|
44
45
|
const RUN = 500;
|
|
45
|
-
/** The rows a reason may take
|
|
46
|
+
/** The rows a reason may take in the sidebar: a quarter of the screen, at least one, at most this. */
|
|
46
47
|
const REASON_ROWS = 4;
|
|
47
|
-
/** The rows a deployment's note may take
|
|
48
|
+
/** The rows a deployment's note may take in the sidebar. */
|
|
48
49
|
const NOTE_ROWS = 2;
|
|
50
|
+
/** The fewest rows the open view's list keeps: what stands above it gives way first. */
|
|
51
|
+
const LIST_LEAST = 3;
|
|
49
52
|
/** The TUI's word before the soul a kept filter of the instances is by. */
|
|
50
53
|
const SOUL_WORD = "soul";
|
|
51
|
-
/**
|
|
52
|
-
const FILTER_COLS = 24;
|
|
53
|
-
/** What the header holds in the workspace's place while the switcher is shown. */
|
|
54
|
+
/** What the title says in the workspace's place while the switcher is shown. */
|
|
54
55
|
const WORKSPACES = "workspaces";
|
|
55
56
|
/** The TUI's word before the one machine of a view that holds no deployment of this machine. */
|
|
56
57
|
const ON = "on";
|
|
57
|
-
/** The cells the workspace's name keeps (all of them, when it is shorter) before the
|
|
58
|
+
/** The cells the workspace's name keeps (all of them, when it is shorter) before the title says
|
|
58
59
|
* how many other machines it is on: under that the name comes first. */
|
|
59
60
|
const NAME_MIN = 8;
|
|
60
61
|
|
|
61
62
|
const BOLD = style({ bold: true });
|
|
62
63
|
const DIM = style({ dim: true });
|
|
63
|
-
const REVERSE = style({ reverse: true });
|
|
64
64
|
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`, `Ctrl+\`): tui.json's open.detachKey is the
|
|
69
|
+
* user's, so it is text from outside. */
|
|
70
|
+
const leaderText = (m) => keyText(backKeyLabel(m.detachKey));
|
|
68
71
|
|
|
69
72
|
/** One row saying so, with the size found and the size needed. Short, and the sizes early: on a
|
|
70
73
|
* terminal this small the screen clips the end of the row. */
|
|
@@ -74,11 +77,10 @@ function tooSmallRows(size) {
|
|
|
74
77
|
return rows;
|
|
75
78
|
}
|
|
76
79
|
|
|
77
|
-
/** A horizontal rule
|
|
78
|
-
function rule(cols, ascii
|
|
80
|
+
/** A horizontal rule `cols` cells wide from column 0: the sidebar's, between its parts. */
|
|
81
|
+
function rule(cols, ascii) {
|
|
79
82
|
const spans = [], dash = ascii ? "-" : "─";
|
|
80
83
|
for (let col = 0; col < cols; col += RUN) spans.push({ col, text: lit(dash.repeat(Math.min(RUN, cols - col))), style: DIM });
|
|
81
|
-
if (joint) spans.push({ col: joint.col, text: lit(ascii ? "+" : joint.up ? "┴" : "┬"), style: DIM, width: 1 });
|
|
82
84
|
return spans;
|
|
83
85
|
}
|
|
84
86
|
|
|
@@ -125,37 +127,57 @@ export function partRows(parts, width, max, { ascii = false } = {}) {
|
|
|
125
127
|
return rows;
|
|
126
128
|
}
|
|
127
129
|
|
|
128
|
-
/**
|
|
129
|
-
*
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
*
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
130
|
+
/** The open view of the accordion for a model: the view under the help or a confirmation, none
|
|
131
|
+
* while the switcher is shown. A model made by hand that names none is the Instances view's. */
|
|
132
|
+
function openOf(m) {
|
|
133
|
+
const under = m.under ?? m.view;
|
|
134
|
+
if (under === "switcher") return null;
|
|
135
|
+
return VIEWS.some((view) => view.id === under) ? under : "instances";
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Where everything stands for a size (docs/tui.md, "What it shows"): the sidebar's width
|
|
139
|
+
* (`listCols`), and in it what stands under the title: the reason of a deployment that is not
|
|
140
|
+
* live, the note of the one deployment of a view without headings and the line after an agent was
|
|
141
|
+
* opened, each wrapped to the sidebar's width here, since their rows are taken from the list's.
|
|
142
|
+
* `notice`, `note` and `outcome` are the model's (lib/model.mjs): the main loop asks for the
|
|
143
|
+
* layout first, because the model's window is as tall (`page`), and the sentences in its list as
|
|
144
|
+
* wide, as this gives. The answer's `note` is the note's rows and `outcome` the line's: its
|
|
145
|
+
* sentence and each text under it (what the viewer printed, what the kernel said) set as a reason
|
|
146
|
+
* is, on as many rows as a reason may take; `above` is how many of those rows stand. `open` is the
|
|
147
|
+
* accordion's open view (null while the switcher is shown): the title, the three views' rows and
|
|
148
|
+
* the rules between the sidebar's parts take what they need, what stands above gives way to keep
|
|
149
|
+
* the list LIST_LEAST rows and the leader's, and `room` is what is left for the empty row under
|
|
150
|
+
* the title, the open view's list and the cheat sheet. `page` is the list's rows when it has to
|
|
151
|
+
* scroll (room less the leader's row): the model windows the list in it, and the frame gives the
|
|
152
|
+
* rows the list does not need to the cheat sheet. `body` is an overlay's rows: the whole height.
|
|
153
|
+
* While a terminal is open (`terminal`) the sidebar keeps LIST_BESIDE cells at most, whether the
|
|
154
|
+
* terminal or the detail stands beside it, so the agent's screen keeps one size; a name longer
|
|
155
|
+
* than its row is cut there. */
|
|
156
|
+
export function layout(notice, size, { note = null, ascii = false, outcome = null, terminal = false, open = "instances" } = {}) {
|
|
141
157
|
const wide = size.cols >= WIDE;
|
|
142
158
|
const listCols = !wide ? size.cols : terminal ? LIST_BESIDE : clamp(Math.floor(size.cols * 0.48), 36, 60);
|
|
143
|
-
const across = Math.max(1,
|
|
144
|
-
const reasonRows = clamp(Math.floor(
|
|
159
|
+
const across = Math.max(1, listCols - 2 * MARGIN);
|
|
160
|
+
const reasonRows = clamp(Math.floor(size.rows / 4), 1, REASON_ROWS);
|
|
145
161
|
const reason = notice ? shownLines(notice.reason, across, reasonRows, { ascii }) : [];
|
|
146
162
|
const noted = note ? shownLines(note, across, NOTE_ROWS, { ascii }) : [];
|
|
147
163
|
const after = outcome ? [
|
|
148
164
|
...partRows(outcome.said, across, reasonRows, { ascii }),
|
|
149
165
|
...outcome.under.flatMap((text) => shownLines(text, across, reasonRows, { ascii }).map((line) => [{ col: 0, text: line, width: across }])),
|
|
150
166
|
] : [];
|
|
151
|
-
// The
|
|
152
|
-
//
|
|
167
|
+
// The title, a row per view, and the rules: one before the cheat sheet, one between the open
|
|
168
|
+
// view's list and the views after it, and one between the views before it and its heading.
|
|
169
|
+
const at = VIEWS.findIndex((view) => view.id === open);
|
|
170
|
+
const rules = 1 + (at < 0 ? 0 : (at > 0 ? 1 : 0) + (at < VIEWS.length - 1 ? 1 : 0));
|
|
171
|
+
const fixed = 1 + VIEWS.length + rules;
|
|
153
172
|
const said = (notice ? 1 + reason.length : 0) + noted.length + after.length;
|
|
154
|
-
const above = said
|
|
155
|
-
|
|
173
|
+
const above = Math.min(said, Math.max(0, size.rows - fixed - 1 - LIST_LEAST));
|
|
174
|
+
const room = Math.max(0, size.rows - fixed - above);
|
|
175
|
+
return { wide, listCols, reason, note: noted, outcome: after, above, open: at < 0 ? null : open, room, page: Math.max(1, room - 1), body: size.rows };
|
|
156
176
|
}
|
|
177
|
+
/** The layout the frame draws a model by. */
|
|
178
|
+
const layoutOf = (m, size, given = {}) => layout(m.notice, size, { note: m.note, ascii: m.ascii, outcome: m.outcome, terminal: panelOpen(m), open: openOf(m), ...given });
|
|
157
179
|
|
|
158
|
-
/** The
|
|
180
|
+
/** The title, from `col` on in `room` cells: the workspace's name and, when the view
|
|
159
181
|
* holds other machines, what says so, in the TUI's words and dim:
|
|
160
182
|
* `+N machine(s)` beside a deployment of this machine;
|
|
161
183
|
* `on <machine>` the one machine of a view that holds no deployment of this machine (no
|
|
@@ -164,14 +186,14 @@ export function layout(notice, size, { observed = true, note = null, ascii = fal
|
|
|
164
186
|
* Whether a deployment is this machine's is the shared entries' word (the model's `here`), and
|
|
165
187
|
* the machine's name is theirs. What stands after the name gives way before the name is cut
|
|
166
188
|
* short of NAME_MIN cells, and a machine's name is cut before the workspace's. While the
|
|
167
|
-
* switcher is shown no workspace is named: the
|
|
189
|
+
* switcher is shown no workspace is named: the title says what is listed instead. */
|
|
168
190
|
function nameSpans(m, col, room) {
|
|
169
191
|
if (room <= 0) return [];
|
|
170
192
|
if (m.under === "switcher") return [{ col, text: lit(WORKSPACES), width: room }];
|
|
171
193
|
const name = measured(m.workspace), alone = [{ col, text: name.text, width: room }];
|
|
172
194
|
if (!(m.machines > 0)) return alone;
|
|
173
195
|
const least = Math.min(name.width, NAME_MIN);
|
|
174
|
-
// Two cells between the name and what follows it
|
|
196
|
+
// Two cells between the name and what follows it.
|
|
175
197
|
const after = (width) => col + width + (width ? 2 : 0);
|
|
176
198
|
if (!m.here && m.machine !== null) {
|
|
177
199
|
const where = measured(m.machine), left = room - 2 - ON.length - 1;
|
|
@@ -189,272 +211,292 @@ function nameSpans(m, col, room) {
|
|
|
189
211
|
return [...(width ? [{ col, text: name.text, width }] : []), { col: after(width), text: lit(more), style: DIM, width: more.length }];
|
|
190
212
|
}
|
|
191
213
|
|
|
192
|
-
/** The
|
|
193
|
-
*
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
214
|
+
/** The title, the sidebar's first row: the workspace's name in bold and what the view holds of
|
|
215
|
+
* other machines (nameSpans), or `workspaces` while the switcher is shown. */
|
|
216
|
+
function titleRow(m, cols) {
|
|
217
|
+
return nameSpans(m, MARGIN, cols - 2 * MARGIN).map((span) => (span.style ? span : { ...span, style: BOLD }));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** What stands under the title, wrapped by layout(): the state of a deployment that is not live
|
|
221
|
+
* and, on rows of its own, the reason, which is the shared home's sentence or the kernel's
|
|
222
|
+
* (nothing of the TUI's stands on a reason's row); then the note of the one deployment of a view
|
|
223
|
+
* without headings, the shared home's sentence too; then the line after an open. */
|
|
224
|
+
function sayings(m, g) {
|
|
225
|
+
const cols = g.listCols, said = [];
|
|
226
|
+
if (m.notice) {
|
|
227
|
+
const since = m.notice.since ? `since ${m.notice.since}` : null;
|
|
228
|
+
said.push([{ col: MARGIN, text: shown(m.notice.text), style: BOLD, width: Math.max(0, cols - 2 * MARGIN - (since ? since.length + 2 : 0)) }, ...(since ? [{ col: cols - MARGIN - since.length, text: lit(since), style: DIM, width: since.length }] : [])]);
|
|
229
|
+
for (const line of g.reason) said.push([{ col: MARGIN, text: line, width: cols - 2 * MARGIN }]);
|
|
230
|
+
}
|
|
231
|
+
for (const line of g.note) said.push([{ col: MARGIN, text: line, width: cols - 2 * MARGIN }]);
|
|
232
|
+
for (const spans of g.outcome) said.push(placed(spans, MARGIN));
|
|
233
|
+
return said.slice(0, g.above);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** The filter of view `id` as its heading draws it, while that view is shown: the field while it
|
|
237
|
+
* is typed, else a filter kept by its text, or in the list of instances by a soul (the Souls
|
|
238
|
+
* view's `i`). Null for a view not shown, or with nothing to say. */
|
|
239
|
+
function filterOf(m, id) {
|
|
240
|
+
if (m.view !== id) return null;
|
|
241
|
+
const filter = id === "souls" ? m.souls?.filter : id === "capabilities" ? m.capabilities?.filter : m.filter;
|
|
242
|
+
if (!filter) return null;
|
|
243
|
+
const soul = id === "instances" && filter.soul && !filter.query ? filter.soul : null;
|
|
244
|
+
if (filter.editing) return { editing: true, query: filter.query ?? "", soul: null };
|
|
245
|
+
return filter.query || soul !== null ? { editing: false, query: filter.query ?? "", soul } : null;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** A view's row of the accordion, `cols` wide: its name (bold while it is the open one) and its
|
|
249
|
+
* key dim at the right, the first the user's table gives its action (none while it has none).
|
|
250
|
+
* On the open view's row the filter: while it is typed the row is the field, `/` and what is
|
|
251
|
+
* typed; a kept one is named after the view's name, `/text` or `soul <name>`, cut first. */
|
|
252
|
+
function viewRow(m, view, cols, open) {
|
|
253
|
+
const action = (m.actions ?? []).find((a) => a.id === view.id && a.keys.length);
|
|
254
|
+
const key = action ? keyText(keyLabel(action.keys[0])) : null;
|
|
255
|
+
const edge = cols - MARGIN, keyCol = key ? Math.max(MARGIN, edge - key.width) : edge;
|
|
256
|
+
const end = key ? keyCol - 1 : edge;
|
|
257
|
+
const field = open ? filterOf(m, view.id) : null;
|
|
204
258
|
const spans = [];
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
259
|
+
if (field?.editing) spans.push({ col: MARGIN, text: lit("/"), style: BOLD, width: Math.min(1, end - MARGIN) }, { col: MARGIN + 1, text: shown(field.query), width: Math.max(0, end - MARGIN - 1) });
|
|
260
|
+
else {
|
|
261
|
+
spans.push({ col: MARGIN, text: lit(view.name), ...(open ? { style: BOLD } : {}), width: Math.max(0, Math.min(view.name.length, end - MARGIN)) });
|
|
262
|
+
const at = MARGIN + view.name.length + 2, room = end - at;
|
|
263
|
+
if (field?.soul && room >= SOUL_WORD.length + 2) spans.push({ col: at, text: lit(SOUL_WORD), style: BOLD, width: SOUL_WORD.length }, { col: at + SOUL_WORD.length + 1, text: shown(field.soul.name), style: BOLD, width: room - SOUL_WORD.length - 1 });
|
|
264
|
+
else if (field && !field.soul && room >= 2) spans.push({ col: at, text: lit("/"), style: BOLD, width: 1 }, { col: at + 1, text: shown(field.query), style: BOLD, width: room - 1 });
|
|
265
|
+
}
|
|
266
|
+
if (key) spans.push({ col: keyCol, text: key.text, style: DIM, width: Math.max(0, Math.min(key.width, edge - keyCol)) });
|
|
267
|
+
return spans.filter((span) => span.width > 0);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** A hint of the cheat sheet: `id` (an action's, or the hint's own), the key (`{ text, width }`:
|
|
271
|
+
* a key's label is the user's once tui.json names it, views/help.mjs keyText) and what it does
|
|
272
|
+
* (the TUI's word, or `{ spans, width }` made of parts). */
|
|
273
|
+
const made = (id, key, word) => ({ id, key, word: typeof word === "string" ? { spans: [{ col: 0, text: lit(word), width: word.length }], width: word.length } : word });
|
|
274
|
+
/** A hint of keys that are no action's (a key name the TUI writes, like `Enter`). */
|
|
275
|
+
const own = (id, keys, word) => made(id, { text: lit(keys), width: keys.length }, word);
|
|
276
|
+
/** `types <the leader>`: what the leader pressed twice does while a terminal has the focus. */
|
|
277
|
+
function types(m) {
|
|
278
|
+
const key = leaderText(m);
|
|
279
|
+
return { spans: [{ col: 0, text: lit("types"), width: 5 }, { col: 6, text: key.text, width: key.width }], width: 6 + key.width };
|
|
280
|
+
}
|
|
281
|
+
|
|
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 (`Alt+O commands`), then the palette, `help` and `quit` last. While
|
|
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 focus, and the
|
|
286
|
+
* leader twice types the leader into the terminal. In the palette, the spawn prompt (spawnHints),
|
|
287
|
+
* a confirmation, the filter field, the help and the switcher, how to work them: the keys they
|
|
288
|
+
* read are their own, so they are the TUI's words, but for the confirmation's close key and the
|
|
289
|
+
* field's clear, which are the user's. Else it is small: a view's list or its detail names what
|
|
290
|
+
* Enter does now, and the rest stays the leader's hint's, the palette's and the help's. In the list
|
|
291
|
+
* of instances Enter is `open` while it would open the selected agent's terminal and `focus
|
|
292
|
+
* terminal` on the row whose terminal is open; while another machine is asked first, the key that
|
|
293
|
+
* gives the open up (`stop opening`) stands in its place. In the Souls view Enter is the detail
|
|
294
|
+
* from the list and the soul's instances from the detail; in the Capabilities view the detail,
|
|
295
|
+
* and from it the marked soul. With the detail's focus the key that goes back to the list
|
|
296
|
+
* (`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). An action with no key (tui.json may unbind one) has
|
|
298
|
+
* no hint. The views have no hint: the accordion names their keys. When rows are short the sheet
|
|
299
|
+
* gives up rows from its end (keptHints), down to the leader alone. */
|
|
300
|
+
function cheatSheet(m) {
|
|
301
|
+
const action = (id) => (m.actions ?? []).find((a) => a.id === id && a.keys.length);
|
|
302
|
+
const hint = (id, label) => { const a = action(id); return a ? made(id, keyText(keyLabel(a.keys[0])), label ?? a.label) : null; };
|
|
303
|
+
if (m.leader) return leaderHints(m);
|
|
304
|
+
const led = (list) => [made("leader", leaderText(m), "commands"), ...list.filter(Boolean)];
|
|
245
305
|
const soul = m.view === "souls" && m.souls ? m.souls : null;
|
|
246
|
-
// The Capabilities view's the same way: from the list Enter shows the detail, and from the detail
|
|
247
|
-
// the marked soul of "Used by" in the Souls view (no hint while none is marked).
|
|
248
306
|
const capability = m.view === "capabilities" && m.capabilities ? m.capabilities : null;
|
|
249
307
|
const filter = soul ? soul.filter : capability ? capability.filter : m.filter;
|
|
250
|
-
//
|
|
251
|
-
// drawn `soul <name>` where the text's `/` stands.
|
|
252
|
-
const bySoul = !soul && m.view === "instances" && filter.soul && !filter.query ? filter.soul : null;
|
|
253
|
-
const filtered = Boolean(filter.query) || bySoul !== null;
|
|
254
|
-
/** A hint: a key and what it does, the TUI's word or safe text with its width. */
|
|
255
|
-
const made = (key, word) => {
|
|
256
|
-
const said = typeof word === "string" ? { text: lit(word), width: word.length } : word;
|
|
257
|
-
return { key, word: said, width: key.width + 1 + said.width };
|
|
258
|
-
};
|
|
259
|
-
const hint = (id, label) => { const a = action(id); return a ? made(keyText(keyLabel(a.keys[0])), label ?? a.label) : null; };
|
|
260
|
-
/** `[/] tab`: the keys of `tab-previous` and `tab-next`, while both have one. */
|
|
261
|
-
const tabsHint = () => { const [before, after] = [action("tab-previous"), action("tab-next")]; return before && after ? made(keyText(`${keyLabel(before.keys[0])}/${keyLabel(after.keys[0])}`), "tab") : null; };
|
|
262
|
-
/** The hints that are no one action's: made below. */
|
|
263
|
-
const hintOf = {};
|
|
264
|
-
const edge = cols - MARGIN; // nothing stands at or past it
|
|
265
|
-
/** A hint's spans at `col`, never past the edge. */
|
|
266
|
-
const put = (h, col, look) => [
|
|
267
|
-
{ col, text: h.key.text, width: Math.max(0, Math.min(h.key.width, edge - col)), ...look },
|
|
268
|
-
...h.word.spans.map((span) => ({ ...span, col: col + h.key.width + 1 + span.col })).map((span) => ({ ...span, width: Math.max(0, Math.min(span.width, edge - span.col)), ...look })),
|
|
269
|
-
].filter((span) => span.width > 0);
|
|
270
|
-
const span = (hints) => hints.reduce((sum, h) => sum + h.width, 0) + Math.max(0, hints.length - 1) * GAP;
|
|
271
|
-
// A word is drawn as one span, unless it was made of spans already.
|
|
272
|
-
const spansOf = (h) => ({ ...h, word: { ...h.word, spans: h.word.spans ?? [{ col: 0, text: h.word.text, width: h.word.width }] } });
|
|
273
|
-
/** A hint of keys that are no action's (a key name the TUI writes, like `Enter`). */
|
|
274
|
-
const own = (keys, word) => spansOf(made({ text: lit(keys), width: keys.length }, word));
|
|
275
|
-
|
|
276
|
-
// While the leader waits for its key, the row is its hint (docs/tui.md, "The leader").
|
|
277
|
-
if (m.leader) return leaderHint(m, edge, put, own);
|
|
278
|
-
// The leader stands first in every focus (tui.json's open.detachKey, text from outside): from
|
|
279
|
-
// it, every action is reached.
|
|
280
|
-
const lead = spansOf(made(keyText(m.detachKey), "commands"));
|
|
281
|
-
const start = lead.width + GAP;
|
|
282
|
-
const led = (spans) => [...put(lead, FOOT), ...spans];
|
|
283
|
-
// While what is typed goes to the agent the TUI takes one key, the leader, and the footer names
|
|
284
|
-
// it and the leader twice, which takes the focus back to the list.
|
|
285
|
-
// The list of instances: what Enter opens, the open terminal's keys and the acts are its own
|
|
286
|
-
// (Souls and Capabilities have none of them, the help and the switcher neither: the Souls view's
|
|
287
|
-
// Enter is its own, below).
|
|
308
|
+
// The list of instances, or a confirmation over it.
|
|
288
309
|
const listing = !["help", "switcher", "souls", "capabilities"].includes(m.view);
|
|
289
310
|
if (listing && m.terminal?.focus === "terminal" && !m.palette && !m.spawn) {
|
|
290
|
-
const
|
|
291
|
-
return led(
|
|
292
|
-
}
|
|
293
|
-
if (m.palette) {
|
|
294
|
-
const hints = [own("Enter", "run"), own("Up/Down", "move"), own("Esc", "close")], spans = [];
|
|
295
|
-
let col = start;
|
|
296
|
-
for (const h of hints) { if (col + h.width > edge) break; spans.push(...put(h, col)); col += h.width + GAP; }
|
|
297
|
-
return led(spans);
|
|
298
|
-
}
|
|
299
|
-
if (m.spawn) return led(spawnHints(m.spawn, start, edge, put, own, m.ascii));
|
|
300
|
-
if (m.view !== "help" && filter.editing) {
|
|
301
|
-
const hints = [made({ text: lit("Enter"), width: "Enter".length }, "keep"), hint("close", "clear")].filter(Boolean).map(spansOf);
|
|
302
|
-
const spans = [...put(lead, FOOT), { col: start, text: lit("/"), style: BOLD, width: 1 }, { col: start + 1, text: shown(filter.query), width: Math.max(0, edge - span(hints) - GAP - start - 1) }];
|
|
303
|
-
let col = Math.max(start + 2, edge - span(hints));
|
|
304
|
-
for (const h of hints) { spans.push(...put(h, col, { style: DIM })); col += h.width + GAP; }
|
|
305
|
-
return spans;
|
|
311
|
+
const label = backKeyLabel(m.detachKey), list = keyLabel(LEADER.find((entry) => entry.does === "list").keys[0]);
|
|
312
|
+
return led([made("list", keyText(`${label} ${list}`), "the list"), made("again", keyText(`${label} ${label}`), types(m))]);
|
|
306
313
|
}
|
|
314
|
+
if (m.palette) return led([own("run", "Enter", "run"), own("move", "Up/Down", "move"), own("close", "Esc", "close")]);
|
|
315
|
+
if (m.spawn) return led(spawnHints(m.spawn, m.ascii));
|
|
316
|
+
if (m.view !== "help" && filter?.editing) return led([own("keep", "Enter", "keep"), hint("close", "clear")]);
|
|
307
317
|
if (m.view === "act" && m.act) {
|
|
308
|
-
// The confirmation: its buttons are the offers,
|
|
318
|
+
// The confirmation: its buttons are the offers, in the main area; the sheet says how to work them.
|
|
309
319
|
const close = action("close"), shut = m.act.buttons.find((button) => button.id === "close");
|
|
310
|
-
|
|
311
|
-
...(close && shut ? [made(keyText(keyLabel(close.keys[0])), shut.label)] : []),
|
|
312
|
-
...(m.act.buttons.length > 1 ? [made({ text: lit("Left/Right"), width: "Left/Right".length }, "move")] : []),
|
|
313
|
-
made({ text: lit("Enter"), width: "Enter".length }, "press"),
|
|
314
|
-
].map(spansOf);
|
|
315
|
-
const quit = hint("quit");
|
|
316
|
-
const all = [...hints, ...(quit ? [spansOf(quit)] : [])];
|
|
317
|
-
const spans = [];
|
|
318
|
-
let col = start;
|
|
319
|
-
for (const h of all) { if (col + h.width > edge) break; spans.push(...put(h, col)); col += h.width + GAP; }
|
|
320
|
-
return led(spans);
|
|
320
|
+
return led([close && shut ? made("close", keyText(keyLabel(close.keys[0])), shut.label) : null, m.act.buttons.length > 1 ? own("move", "Left/Right", "move") : null, own("press", "Enter", "press"), hint("quit")]);
|
|
321
321
|
}
|
|
322
|
-
//
|
|
323
|
-
|
|
322
|
+
// The help and the switcher cover the main area: their keys are how to work them.
|
|
323
|
+
if (m.view === "help") return led([hint("palette"), hint("close"), hint("help"), hint("quit")]);
|
|
324
|
+
// Esc closes the switcher only onto a view, and there is none before a workspace is opened.
|
|
325
|
+
// Remove stands on a row of this computer's deployments list only, after the keys that move about.
|
|
326
|
+
if (m.view === "switcher") return led([hint("palette"), ...["open", "filter", ...(m.filter?.query ? ["close", "refresh"] : ["refresh", ...(m.open ? ["close"] : [])]), ...(m.switcher?.removable ? ["remove"] : [])].map((id) => hint(id)), hint("help"), hint("quit")]);
|
|
327
|
+
// A view's list or its detail: a small sheet; the rest is the leader's, the palette's and the help's.
|
|
324
328
|
const asking = listing && m.opening?.phase === "preflight";
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
// with two tabs or more in the focused group, then the keys that show the tab before and after.
|
|
332
|
-
const terminal = listing && m.terminal ? [["zoom", hint("zoom")], ["close-terminal", hint("close-terminal")], ...((m.tabs?.length ?? 0) > 1 ? [["tabs", tabsHint()]] : [])].filter(([, h]) => h) : [];
|
|
333
|
-
// The acts the selected row offers now stand after those, and are the first given up.
|
|
334
|
-
const acts = listing && !asking ? (m.actable ?? []).map((verb) => [verb, hint(verb)]).filter(([, h]) => h) : [];
|
|
335
|
-
const ACTS = ["stop", "retire", "start", "restart"];
|
|
336
|
-
// The views have no hint: the header names them, and the leader's hint and the help their keys.
|
|
337
|
-
const VIEW_KEYS = [];
|
|
338
|
-
const [ids, keep] = m.view === "help" ? [["close"], ["close"]]
|
|
339
|
-
// The Souls view: after Enter, `i` shows the selected soul's instances, then the filter, a
|
|
340
|
-
// read again, Esc and the workspaces. They are given up from the end of `keep`: the workspaces
|
|
341
|
-
// first, then `refresh`, `filter` and `close`; `i` and Enter last. With no workspace of this
|
|
342
|
-
// machine there is nothing to filter or read: Esc and the workspaces only. No spawn hint: the
|
|
343
|
-
// help names n and N.
|
|
344
|
-
: soul ? (soul.local === false ? [["close", "workspaces"], ["close", "workspaces"]]
|
|
345
|
-
: [[...(soul.detail ? ["soul-instances"] : []), "filter", "refresh", "close", "workspaces"], ["open", "soul-instances", "close", "filter", "refresh", "workspaces"]])
|
|
346
|
-
// The Capabilities view: the filter, a read again, Esc and the workspaces, given up from the
|
|
347
|
-
// workspaces on; Enter last. With no workspace of this machine, Esc and the workspaces only.
|
|
348
|
-
: capability ? (capability.local === false ? [["close", "workspaces"], ["close", "workspaces"]]
|
|
349
|
-
: [["filter", "refresh", "close", "workspaces"], ["open", "close", "filter", "refresh", "workspaces"]])
|
|
350
|
-
// Esc closes the switcher only onto a view, and there is none before a workspace is opened.
|
|
351
|
-
// A kept filter puts `close` before `refresh`, as in the list: the key that clears it is the hint to keep.
|
|
352
|
-
: m.view === "switcher" ? [["open", "filter", ...(m.filter.query ? ["close", "refresh"] : ["refresh", ...(m.open ? ["close"] : [])])], null]
|
|
353
|
-
: m.focus === "detail" ? [["detail", "close", "refresh"], ["open", "zoom", "close-terminal", "detail", "tabs", "close", "refresh", ...ACTS]]
|
|
354
|
-
// A kept filter shows its own `/` beside the hints: then `open` outlives the `/ filter` hint.
|
|
355
|
-
: [["filter", "detail", ...(filtered ? ["close"] : []), "refresh", "workspaces", ...VIEW_KEYS], [...(filtered ? ["open", "zoom", "close-terminal", "filter"] : ["filter", "open", "zoom", "close-terminal"]), "detail", "tabs", "close", "refresh", "workspaces", ...VIEW_KEYS, ...ACTS]];
|
|
356
|
-
const hints = [...first, ...terminal, ...acts, ...ids.filter((id) => !(asking && id === "close")).map((id) => [id, id in hintOf ? hintOf[id] : hint(id)])].filter(([, h]) => h).map(([id, h]) => [id, spansOf(h)]);
|
|
357
|
-
// `help` and `quit` stand last, and always but in one case: when the two do not fit whole
|
|
358
|
-
// after the leader (keys tui.json made long), `help` is given up, then `quit`. The leader
|
|
359
|
-
// reaches the help too, and a hint is never cut.
|
|
360
|
-
let last = ["help", "quit"].map((id) => hint(id)).filter(Boolean).map(spansOf);
|
|
361
|
-
while (last.length && start + span(last) > edge) last = last.slice(1);
|
|
362
|
-
const spans = put(lead, FOOT);
|
|
363
|
-
let col = start;
|
|
364
|
-
if (m.view !== "help" && filtered) {
|
|
365
|
-
// The kept filter has a place of its own width, so the hints stand where they always do;
|
|
366
|
-
// it gives way, down to nothing, before `help` and `quit` do, and before the hint that
|
|
367
|
-
// stands first while Enter would open an agent (or Esc gives an open up).
|
|
368
|
-
// The room of that first hint is kept only when it fits beside `help` and `quit`: a hint that
|
|
369
|
-
// cannot stand takes no room from the filter.
|
|
370
|
-
const firstFits = first.length > 0 && col + first[0][1].width + GAP + span(last) <= edge;
|
|
371
|
-
const held = firstFits ? first[0][1].width + GAP : 0;
|
|
372
|
-
const slot = Math.min(FILTER_COLS - GAP, edge - col - span(last) - (last.length ? GAP : 0) - held);
|
|
373
|
-
if (bySoul && slot >= SOUL_WORD.length + 2) {
|
|
374
|
-
spans.push({ col, text: lit(SOUL_WORD), style: BOLD, width: SOUL_WORD.length }, { col: col + SOUL_WORD.length + 1, text: shown(bySoul.name), style: BOLD, width: slot - SOUL_WORD.length - 1 });
|
|
375
|
-
col += slot + GAP;
|
|
376
|
-
} else if (!bySoul && slot >= 2) {
|
|
377
|
-
spans.push({ col, text: lit("/"), style: BOLD, width: 1 }, { col: col + 1, text: shown(filter.query), style: BOLD, width: slot - 1 });
|
|
378
|
-
col += slot + GAP;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
// Give up hints until the rest fit: the one kept least first, else (no order of its own) the last.
|
|
382
|
-
let kept = hints;
|
|
383
|
-
const room = () => col + span(kept.map(([, h]) => h)) + (kept.length ? GAP : 0) + span(last) <= edge;
|
|
384
|
-
while (kept.length && !room()) {
|
|
385
|
-
const order = keep ?? kept.map(([id]) => id);
|
|
386
|
-
const least = [...order].reverse().find((id) => kept.some(([k]) => k === id)) ?? kept.at(-1)[0];
|
|
387
|
-
kept = kept.filter(([id]) => id !== least);
|
|
388
|
-
}
|
|
389
|
-
for (const [, h] of kept) { spans.push(...put(h, col)); col += h.width + GAP; }
|
|
390
|
-
for (const h of last) { spans.push(...put(h, col)); col += h.width + GAP; }
|
|
391
|
-
return spans;
|
|
329
|
+
const enter = asking ? [hint("close", "stop opening")] : listing && m.onTerminal ? [hint("open", "focus terminal")] : listing && m.openable ? [hint("open")]
|
|
330
|
+
: soul?.detail ? [hint("open", soul.focus === "detail" ? "instances" : "detail")]
|
|
331
|
+
: capability?.detail ? (capability.focus !== "detail" ? [hint("open", "detail")] : capability.mark >= 0 ? [hint("open", "soul")] : []) : [];
|
|
332
|
+
const detailed = soul ? soul.focus === "detail" && Boolean(soul.detail) : capability ? capability.focus === "detail" && Boolean(capability.detail) : listing && m.focus === "detail";
|
|
333
|
+
const spawns = listing || (soul && soul.local !== false);
|
|
334
|
+
return led([hint("palette"), ...(detailed ? [hint("detail", "back")] : []), ...enter, ...(spawns ? [hint("spawn")] : []), hint("help"), hint("quit")]);
|
|
392
335
|
}
|
|
393
336
|
|
|
394
|
-
/** The
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
*
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
* then Tab, then Esc, Enter last; in the picker from the end, as the palette's. */
|
|
402
|
-
function spawnHints(s, start, edge, put, own, ascii) {
|
|
403
|
-
const hints = s.step === "picker" ? [own("Enter", "pick"), own("Up/Down", "move"), own("Esc", "close")]
|
|
404
|
-
: [...(s.enter ? [own("Enter", ownEllipsis(s.enter, ascii))] : []), own("Tab", "next"), own("Shift+Tab", "back"), own("Esc", "back")];
|
|
405
|
-
// The least kept first: Shift+Tab, Tab, Esc, then Enter.
|
|
406
|
-
const order = s.step === "picker" ? [...hints].reverse() : [hints.at(-2), hints.at(-3), hints.at(-1), ...(s.enter ? [hints[0]] : [])];
|
|
407
|
-
let kept = hints;
|
|
408
|
-
const width = (list) => list.reduce((sum, h) => sum + h.width, 0) + Math.max(0, list.length - 1) * GAP;
|
|
409
|
-
for (const least of order) { if (start + width(kept) <= edge) break; kept = kept.filter((h) => h !== least); }
|
|
410
|
-
const spans = [];
|
|
411
|
-
let col = start;
|
|
412
|
-
for (const h of kept) { spans.push(...put(h, col)); col += h.width + GAP; }
|
|
413
|
-
return spans;
|
|
337
|
+
/** The spawn prompt's hints (docs/tui.md, "Spawning an agent"): the keys the prompt reads are its
|
|
338
|
+
* own, as the palette's are, so they are the TUI's words. The picker: Enter picks, Up/Down move,
|
|
339
|
+
* Esc closes. The preview: Enter and what it does at the focus (the model's `enter`; none while
|
|
340
|
+
* Enter does nothing), Tab and Shift+Tab move the focus, Esc goes back. */
|
|
341
|
+
function spawnHints(s, ascii) {
|
|
342
|
+
return s.step === "picker" ? [own("pick", "Enter", "pick"), own("move", "Up/Down", "move"), own("close", "Esc", "close")]
|
|
343
|
+
: [...(s.enter ? [own("enter", "Enter", ownEllipsis(s.enter, ascii))] : []), own("next", "Tab", "next"), own("back", "Shift+Tab", "back"), own("esc", "Esc", "back")];
|
|
414
344
|
}
|
|
345
|
+
|
|
415
346
|
/** The leader's hint (docs/tui.md, "The leader"): the leader's key, then what each key after it
|
|
416
347
|
* does, from actions.mjs LEADER, the views, the instances and the acts each one hint. The keys
|
|
417
348
|
* that need a terminal are named only while one is open, the tabs' only with two or more, and the
|
|
418
|
-
* split's only where they apply
|
|
419
|
-
*
|
|
420
|
-
function
|
|
349
|
+
* split's only where they apply; while what is typed goes to the agent, the leader again, which
|
|
350
|
+
* types it there. The last, the list's, is never given up. */
|
|
351
|
+
function leaderHints(m) {
|
|
421
352
|
const by = (does) => LEADER.find((entry) => entry.does === does);
|
|
422
|
-
const one = (does) => { const entry = by(does); return own(keyLabel(entry.keys[0]), entry.label); };
|
|
353
|
+
const one = (does) => { const entry = by(does); return own(does, keyLabel(entry.keys[0]), entry.label); };
|
|
423
354
|
const keysOf = (list) => list.map((does) => keyLabel(by(does).keys[0])).join("/");
|
|
424
|
-
const
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
355
|
+
const views = keysOf(["instances", "souls", "capabilities"]);
|
|
356
|
+
const typing = m.terminal?.focus === "terminal" && m.view === "instances" && !m.palette && !m.spawn;
|
|
357
|
+
return [
|
|
358
|
+
made("leader", leaderText(m), "then"),
|
|
359
|
+
own("palette", keyLabel(by("palette").keys[0]), "palette"),
|
|
360
|
+
own("views", views === "1/2/3" ? "1-3" : views, "views"),
|
|
361
|
+
own("instance", keysOf(["previous", "next"]), "instance"),
|
|
428
362
|
...(m.terminal ? [one("zoom"), one("close-terminal")] : []),
|
|
429
363
|
// With two tabs or more, the keys that move between them.
|
|
430
|
-
...((m.tabs?.length ?? 0) > 1 ? [own(keysOf(["tab-previous", "tab-next"]), "tab")] : []),
|
|
364
|
+
...((m.tabs?.length ?? 0) > 1 ? [own("tabs", keysOf(["tab-previous", "tab-next"]), "tab")] : []),
|
|
431
365
|
// The split's (docs/tui.md, "Splits"): to split while there is one group; with two, the next
|
|
432
366
|
// group, and the move of the shown tab, or the close of the focused group while it is empty.
|
|
433
|
-
...(m.panelOpen && !m.split ? [own(keysOf(["split-right", "split-down"]), "split")] : []),
|
|
367
|
+
...(m.panelOpen && !m.split ? [own("split", keysOf(["split-right", "split-down"]), "split")] : []),
|
|
434
368
|
...(m.split ? [one("group-next"), ...(m.terminal ? [one("tab-move")] : [one("group-close")])] : []),
|
|
435
|
-
own(keysOf(["stop", "restart", "start", "retire"]), "acts"),
|
|
369
|
+
own("acts", keysOf(["stop", "restart", "start", "retire"]), "acts"),
|
|
436
370
|
one("filter"), one("workspaces"), one("help"),
|
|
371
|
+
...(typing ? [made("again", leaderText(m), types(m))] : []),
|
|
372
|
+
one("list"),
|
|
437
373
|
];
|
|
438
|
-
const last = one("list"), key = keyText(m.detachKey);
|
|
439
|
-
const width = (list) => list.reduce((sum, h) => sum + h.width + GAP, 0);
|
|
440
|
-
let kept = hints;
|
|
441
|
-
while (kept.length && key.width + GAP + width(kept) + last.width > edge) kept = kept.slice(0, -1);
|
|
442
|
-
const spans = [{ col: FOOT, text: key.text, style: BOLD, width: Math.min(key.width, edge) }];
|
|
443
|
-
let col = key.width + GAP;
|
|
444
|
-
for (const h of [...kept, last]) { if (col + h.width > edge) break; spans.push(...put(h, col)); col += h.width + GAP; }
|
|
445
|
-
return spans;
|
|
446
374
|
}
|
|
447
375
|
|
|
376
|
+
/** The hints that stand in `count` rows: given up from the end, down to the leader alone; the
|
|
377
|
+
* leader's hint keeps its last, the list's, while it has two rows. */
|
|
378
|
+
function keptHints(m, hints, count) {
|
|
379
|
+
if (count >= hints.length) return hints;
|
|
380
|
+
if (m.leader && count >= 2) return [...hints.slice(0, count - 1), hints.at(-1)];
|
|
381
|
+
return hints.slice(0, Math.max(1, count));
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/** 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. */
|
|
386
|
+
function cheatRows(hints, cols) {
|
|
387
|
+
const edge = cols - MARGIN;
|
|
388
|
+
const widest = hints.reduce((most, h) => Math.max(most, h.key.width), 0);
|
|
389
|
+
const wordCol = Math.min(MARGIN + widest + GAP, Math.max(MARGIN + 1, edge - 6));
|
|
390
|
+
return hints.map((h) => [
|
|
391
|
+
{ col: MARGIN, text: h.key.text, style: BOLD, width: Math.max(0, Math.min(h.key.width, wordCol - 1 - MARGIN)) },
|
|
392
|
+
...h.word.spans.map((span) => ({ ...span, col: wordCol + span.col, width: Math.max(0, Math.min(span.width, edge - wordCol - span.col)) })),
|
|
393
|
+
].filter((span) => span.width > 0));
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/** An overlay's or a detail page's first row on a narrow terminal, where it has the whole screen:
|
|
397
|
+
* its essential keys (the cheat sheet's, but for the leader, the palette, help and quit) at the
|
|
398
|
+
* right, dim, as many as fit after what the row holds, given up from the end. With `first`, the
|
|
399
|
+
* first key always stands (a detail page's way back): what the row holds is cut to leave it room. */
|
|
400
|
+
function withKeys(given, hints, cols, { skip = ["leader", "palette", "help", "quit"], last = false, first = false } = {}) {
|
|
401
|
+
const keys = hints.filter((h) => !skip.includes(h.id));
|
|
402
|
+
const widthOf = (list) => list.reduce((sum, h) => sum + h.key.width + 1 + h.word.width, 0) + Math.max(0, list.length - 1) * GAP;
|
|
403
|
+
const limit = first && keys.length ? cols - MARGIN - widthOf(keys.slice(0, 1)) - GAP : Infinity;
|
|
404
|
+
const row = limit === Infinity ? given : given.filter((span) => span.text === undefined || span.col < limit)
|
|
405
|
+
.map((span) => (span.text === undefined ? span : { ...span, width: Math.min(span.width ?? textWidth(textOf(span.text)), limit - span.col) }));
|
|
406
|
+
// What the row holds ends where its text does: a span may be given more cells than its text takes.
|
|
407
|
+
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
|
+
let kept = keys;
|
|
409
|
+
// Given up from the end; with `last`, the last is kept as long as one other is (the leader's `Esc`).
|
|
410
|
+
while (kept.length && end + GAP + widthOf(kept) > cols - MARGIN) kept = last && kept.length > 1 ? [...kept.slice(0, -2), kept.at(-1)] : kept.slice(0, -1);
|
|
411
|
+
const spans = [];
|
|
412
|
+
let col = cols - MARGIN - widthOf(kept);
|
|
413
|
+
for (const h of kept) {
|
|
414
|
+
spans.push({ col, text: h.key.text, style: DIM, width: h.key.width }, ...h.word.spans.map((span) => ({ ...span, col: col + h.key.width + 1 + span.col, style: DIM })));
|
|
415
|
+
col += h.key.width + 1 + h.word.width + GAP;
|
|
416
|
+
}
|
|
417
|
+
return [...row, ...spans];
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/** The rows of the open view's list in the sidebar, `page` rows of the sidebar's width (none while
|
|
421
|
+
* the switcher is shown). */
|
|
422
|
+
function listOf(m, g) {
|
|
423
|
+
const size = { cols: g.listCols, rows: g.page };
|
|
424
|
+
if (g.open === "instances") return instances(m, size);
|
|
425
|
+
if (g.open === "souls") return m.souls ? soulsList(m, size) : [];
|
|
426
|
+
if (g.open === "capabilities") return m.capabilities ? capabilitiesList(m, size) : [];
|
|
427
|
+
return [];
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/** The sidebar (docs/tui.md, "What it shows") in `rows`, from column 0 in the sidebar's width:
|
|
431
|
+
* the title; what stands under it (sayings); an empty row; the views, the open one's heading
|
|
432
|
+
* with its list (`list`, trailing empty rows left out) under it and a rule between the views
|
|
433
|
+
* before it and its heading, and between its list and the views after it; a rule, then the
|
|
434
|
+
* cheat sheet. It flows from the top. The list keeps its rows ahead of the cheat sheet: when both
|
|
435
|
+
* do not fit, the sheet gives up rows from its end down to the leader alone, then the empty row
|
|
436
|
+
* goes, and the list scrolls in what is left (layout's `page`). */
|
|
437
|
+
function sidebar(m, g, rows, list) {
|
|
438
|
+
const cols = g.listCols;
|
|
439
|
+
let r = 0;
|
|
440
|
+
const put = (spans) => { if (r < rows.length) rows[r] = spans; r += 1; };
|
|
441
|
+
put(titleRow(m, cols));
|
|
442
|
+
sayings(m, g).forEach(put);
|
|
443
|
+
let n = list.length;
|
|
444
|
+
while (n > 0 && list[n - 1].length === 0) n -= 1;
|
|
445
|
+
const hints = cheatSheet(m), room = g.room;
|
|
446
|
+
const [empty, count, shownRows] = n + 1 + hints.length <= room ? [1, hints.length, n] : n + 2 <= room ? [1, room - 1 - n, n] : [0, 1, Math.min(n, room - 1)];
|
|
447
|
+
r += empty;
|
|
448
|
+
const at = VIEWS.findIndex((view) => view.id === g.open);
|
|
449
|
+
VIEWS.forEach((view, i) => {
|
|
450
|
+
if (i === at && i > 0) put(rule(cols, m.ascii));
|
|
451
|
+
put(viewRow(m, view, cols, i === at));
|
|
452
|
+
if (i !== at) return;
|
|
453
|
+
list.slice(0, shownRows).forEach(put);
|
|
454
|
+
if (i < VIEWS.length - 1) put(rule(cols, m.ascii));
|
|
455
|
+
});
|
|
456
|
+
put(rule(cols, m.ascii));
|
|
457
|
+
cheatRows(keptHints(m, hints, count), cols).forEach(put);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/** The rule between the sidebar and the main area, over the whole height. */
|
|
461
|
+
function barred(m, rows, col) {
|
|
462
|
+
for (let i = 0; i < rows.length; i++) rows[i] = [...rows[i], { col, text: lit(m.ascii ? "|" : "│"), style: DIM, width: 1 }];
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/** The help's top row: the time of the read of this machine that the screen shows, which moves with
|
|
466
|
+
* every read, and how many rows the kernel reported that were withheld (a home outside its soul's
|
|
467
|
+
* directory, or one reported twice), when any were. */
|
|
468
|
+
function readRow(m) {
|
|
469
|
+
const withheld = (m.counts ?? []).find((count) => count.word === "withheld")?.n ?? 0;
|
|
470
|
+
// Each its own span, two cells apart: one text of the TUI's never holds two spaces in a row.
|
|
471
|
+
const parts = [m.readAt ? `read ${m.readAt}` : null, withheld > 0 ? `${withheld} withheld` : null].filter(Boolean);
|
|
472
|
+
let col = 2;
|
|
473
|
+
return parts.map((part) => { const span = { col, text: lit(part), style: DIM, width: part.length }; col += part.length + 2; return span; });
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/** The switcher's filter field, on a row of its own above its list while it is typed or kept: `/`
|
|
477
|
+
* and the text, bold once kept. */
|
|
478
|
+
function switcherField(m, cols) {
|
|
479
|
+
const f = m.filter;
|
|
480
|
+
return [{ col: 2, text: lit("/"), style: BOLD, width: 1 }, { col: 3, text: shown(f.query ?? ""), ...(f.editing ? {} : { style: BOLD }), width: Math.max(0, cols - 3 - MARGIN) }];
|
|
481
|
+
}
|
|
482
|
+
/** Whether the switcher shows its filter field. */
|
|
483
|
+
export const switcherFieldShown = (filter) => Boolean(filter?.editing) || Boolean(filter?.query);
|
|
484
|
+
|
|
485
|
+
/** The main area for a layout `g` of a screen `cols` wide: beside the sidebar from WIDE columns,
|
|
486
|
+
* a cell of margin on each side; under them the whole width. `{ col, cols }`. The switcher is drawn
|
|
487
|
+
* in it, so lib/main.mjs gives the model its width: the lines above the choices wrap to it. */
|
|
488
|
+
export const mainArea = (g, cols) => (g.wide ? { col: g.listCols + 2, cols: Math.max(0, cols - g.listCols - 2 - MARGIN) } : { col: 0, cols });
|
|
489
|
+
|
|
448
490
|
/** Shift a pane's rows to its place on the screen. */
|
|
449
491
|
const placed = (spans, col) => spans.map((span) => ({ ...span, col: span.col + col }));
|
|
450
492
|
|
|
451
|
-
/** The
|
|
452
|
-
*
|
|
453
|
-
*
|
|
454
|
-
*
|
|
455
|
-
|
|
456
|
-
*
|
|
457
|
-
*
|
|
493
|
+
/** The frame for model `m` at `size`: `{ rows, page, extent, room, cursor, regions }`. `page` is
|
|
494
|
+
* the rows the list pane scrolls by (an overlay's, for the palette, the spawn prompt and the
|
|
495
|
+
* switcher); `extent` and `room` are how many rows the other scrolling pane (the help, else the
|
|
496
|
+
* detail) holds and shows. The main loop hands the three back with the next key, so the store
|
|
497
|
+
* scrolls by what is on the screen without holding a size. `regions`, for the loop
|
|
498
|
+
* (lib/main.mjs fitPanel), is each group of the panel this frame draws, empty when it draws none
|
|
499
|
+
* (another view, an overlay, a screen too small). */
|
|
458
500
|
export function frame(m, size) {
|
|
459
501
|
const made = framed(m, size);
|
|
460
502
|
return made.regions ? made : { ...made, regions: [] };
|
|
@@ -462,107 +504,87 @@ export function frame(m, size) {
|
|
|
462
504
|
function framed(m, size) {
|
|
463
505
|
if (tooSmall(size)) return { rows: tooSmallRows(size), page: 1, extent: 0, room: 1 };
|
|
464
506
|
const rows = Array.from({ length: size.rows }, () => []);
|
|
465
|
-
const g =
|
|
507
|
+
const g = layoutOf(m, size);
|
|
466
508
|
const { cols } = size;
|
|
467
|
-
// The
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
if (open) rows[1].push({ col, width: view.name.length + 2, style: REVERSE });
|
|
478
|
-
rows[1].push({ col: col + 1, text: lit(view.name), ...(open ? { style: REVERSE } : {}), width: view.name.length });
|
|
479
|
-
col += view.name.length + 2 + VIEW_GAP;
|
|
480
|
-
}
|
|
481
|
-
if (m.readAt) { const read = `read ${m.readAt}`; rows[1].push({ col: cols - MARGIN - read.length, text: lit(read), style: DIM, width: read.length }); }
|
|
482
|
-
rows[size.rows - 1] = footer(m, cols);
|
|
509
|
+
// The main area: beside the sidebar from WIDE columns, a cell of margin on each side; under it
|
|
510
|
+
// an overlay has the whole screen.
|
|
511
|
+
const main = mainArea(g, cols);
|
|
512
|
+
/** An overlay in the main area, the sidebar beside it; on a narrow terminal over the whole
|
|
513
|
+
* screen, its first row carrying its keys (withKeys). */
|
|
514
|
+
const overlay = (drawn) => {
|
|
515
|
+
if (g.wide) { sidebar(m, g, rows, listOf(m, g)); barred(m, rows, g.listCols); }
|
|
516
|
+
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], cheatSheet(m), cols);
|
|
518
|
+
};
|
|
483
519
|
|
|
484
|
-
// The palette
|
|
520
|
+
// The palette, whatever is under it.
|
|
485
521
|
if (m.palette) {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
return { rows, page: Math.max(1, g.body.rows), extent: 0, room: 1, cursor: { row: g.body.top, col: drawn.cursor } };
|
|
522
|
+
const drawn = palette(m, { cols: main.cols, rows: size.rows });
|
|
523
|
+
overlay(drawn.rows);
|
|
524
|
+
return { rows, page: Math.max(1, size.rows), extent: 0, room: 1, cursor: { row: 0, col: main.col + drawn.cursor } };
|
|
490
525
|
}
|
|
491
526
|
// The spawn prompt in the same place (the palette wins if both are ever set). `extent` and `room`
|
|
492
527
|
// are its preview's, which the store scrolls as it scrolls a confirmation; `drawnTop` the
|
|
493
528
|
// row its window was drawn from, which the loop gives the store once the frame is written; `armed` says the ready
|
|
494
529
|
// Spawn button is drawn, which the loop tells the store once the frame is written.
|
|
495
530
|
if (m.spawn) {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
return { rows, page: Math.max(1, g.body.rows), extent: drawn.extent, room: drawn.room, ...(drawn.top !== undefined ? { drawnTop: drawn.top } : {}), cursor: drawn.cursor ? { row: g.body.top + drawn.cursor.row, col: drawn.cursor.col } : null, ...(drawn.armed ? { armed: true } : {}) };
|
|
531
|
+
const drawn = spawn(m, { cols: main.cols, rows: size.rows });
|
|
532
|
+
overlay(drawn.rows);
|
|
533
|
+
return { rows, page: Math.max(1, size.rows), extent: drawn.extent, room: drawn.room, ...(drawn.top !== undefined ? { drawnTop: drawn.top } : {}), cursor: drawn.cursor ? { row: drawn.cursor.row, col: main.col + drawn.cursor.col } : null, ...(drawn.armed ? { armed: true } : {}) };
|
|
500
534
|
}
|
|
501
535
|
if (m.view === "act" && m.act) {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
drawn.rows.forEach((spans, i) => { rows[g.body.top + i] = spans; });
|
|
536
|
+
const drawn = act(m, { cols: main.cols, rows: size.rows });
|
|
537
|
+
overlay(drawn.rows);
|
|
505
538
|
return { rows, page: Math.max(1, g.page), extent: drawn.extent, room: drawn.room };
|
|
506
539
|
}
|
|
540
|
+
// The help, under its top row (readRow).
|
|
507
541
|
if (m.view === "help") {
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
return { rows, page: Math.max(1, g.page), extent: drawn.extent, room: g.body.rows };
|
|
542
|
+
const drawn = help(m.actions, { cols: main.cols, rows: size.rows - 1 }, { top: m.helpTop, ascii: m.ascii, detachKey: m.detachKey });
|
|
543
|
+
overlay([readRow(m), ...drawn.rows]);
|
|
544
|
+
return { rows, page: Math.max(1, g.page), extent: drawn.extent, room: Math.max(1, size.rows - 1) };
|
|
512
545
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
return { rows, page: Math.max(1, g.body.rows), extent: 0, room: 1 };
|
|
546
|
+
// The switcher, its filter field above it while it has one. Nothing beside it scrolls on its own.
|
|
547
|
+
if (m.under === "switcher") {
|
|
548
|
+
const field = switcherFieldShown(m.filter);
|
|
549
|
+
const drawn = switcher(m, { cols: main.cols, rows: size.rows - (field ? 1 : 0) });
|
|
550
|
+
overlay([...(field ? [switcherField(m, main.cols)] : []), ...drawn]);
|
|
551
|
+
return { rows, page: Math.max(1, size.rows), extent: 0, room: 1 };
|
|
520
552
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
const said = [];
|
|
526
|
-
if (m.notice) {
|
|
527
|
-
const since = m.notice.since ? `since ${m.notice.since}` : null;
|
|
528
|
-
said.push([{ col: MARGIN, text: shown(m.notice.text), style: BOLD, width: Math.max(0, cols - 2 * MARGIN - (since ? since.length + 2 : 0)) }, ...(since ? [{ col: cols - MARGIN - since.length, text: lit(since), style: DIM, width: since.length }] : [])]);
|
|
529
|
-
for (const line of g.reason) said.push([{ col: MARGIN, text: line, width: cols - 2 * MARGIN }]);
|
|
553
|
+
if (m.view === "souls" && m.souls) {
|
|
554
|
+
const s = m.souls;
|
|
555
|
+
const { extent } = viewFrame(m, size, g, rows, { listed: soulsListed(s), paged: s.focus === "detail" && Boolean(s.detail), draw: soulDetail });
|
|
556
|
+
return { rows, page: Math.max(1, g.page), extent, room: size.rows };
|
|
530
557
|
}
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
558
|
+
if (m.view === "capabilities" && m.capabilities) {
|
|
559
|
+
const c = m.capabilities;
|
|
560
|
+
const { extent, top } = viewFrame(m, size, g, rows, { listed: capabilitiesListed(c), paged: c.focus === "detail" && Boolean(c.detail), draw: capabilityDetail });
|
|
561
|
+
return { rows, page: Math.max(1, g.page), extent, room: size.rows, ...(top !== undefined ? { capabilitiesTop: top } : {}) };
|
|
562
|
+
}
|
|
563
|
+
|
|
536
564
|
const area = terminalAt(m, size, g);
|
|
537
565
|
const zoomed = area !== null && area.whole;
|
|
538
566
|
const paged = !zoomed && !g.wide && m.focus === "detail" && m.detail;
|
|
539
|
-
|
|
540
|
-
// no terminal there is nothing to put beside the list.
|
|
541
|
-
const split = !zoomed && g.wide && g.panes.rows > 0 && (m.observed || area !== null);
|
|
542
|
-
const joint = split ? { col: g.listCols } : null;
|
|
543
|
-
// The rule that opens the panes: the one under the header, or the one under the reason and the note.
|
|
544
|
-
const opening = m.observed && g.above > 0 ? g.panes.top - 1 : 2;
|
|
545
|
-
rows[2] = rule(cols, m.ascii, opening === 2 ? joint : null);
|
|
546
|
-
if (opening !== 2 && opening < size.rows - 1) rows[opening] = rule(cols, m.ascii, joint);
|
|
547
|
-
|
|
548
|
-
const pane = { cols: g.wide ? g.listCols : cols, rows: g.panes.rows };
|
|
567
|
+
if (!zoomed && !paged) { sidebar(m, g, rows, listOf(m, g)); if (g.wide) barred(m, rows, g.listCols); }
|
|
549
568
|
let extent = 0;
|
|
550
|
-
if (!paged && !zoomed) instances(m, pane).forEach((spans, i) => { rows[g.panes.top + i] = spans; });
|
|
551
|
-
const bar = split ? [{ col: g.listCols, text: lit(m.ascii ? "|" : "│"), style: DIM, width: 1 }] : [];
|
|
552
569
|
if (area !== null) {
|
|
553
|
-
for (let i = 0; i < g.panes.rows; i++) rows[g.panes.top + i] = [...rows[g.panes.top + i], ...bar];
|
|
554
570
|
for (const region of area.regions) regionRows(m, region).forEach((spans, i) => { rows[region.title + i] = [...rows[region.title + i], ...spans]; });
|
|
555
571
|
// The rule between two groups: a column side by side, a row one above the other.
|
|
556
572
|
const p = area.panel, r = area.rule;
|
|
557
|
-
if (r?.col !== undefined) for (let i = 0; i <= p.rows; i++) rows[p.title + i] = [...rows[p.title + i], { col: r.col, text: lit(m.ascii ? "|" : "
|
|
558
|
-
// Beside the
|
|
559
|
-
if (r?.row !== undefined) rows[r.row] = [...rows[r.row], ...(
|
|
560
|
-
} else if (
|
|
573
|
+
if (r?.col !== undefined) for (let i = 0; i <= p.rows; i++) rows[p.title + i] = [...rows[p.title + i], { col: r.col, text: lit(m.ascii ? "|" : "│"), style: DIM, width: 1 }];
|
|
574
|
+
// Beside the sidebar, the row meets its rule there: a joint (`├`, `+` in ASCII).
|
|
575
|
+
if (r?.row !== undefined) rows[r.row] = [...rows[r.row], ...(!zoomed && p.col === g.listCols + 1 ? [{ col: g.listCols, text: lit(m.ascii ? "+" : "├"), style: DIM, width: 1 }] : []), { col: p.col, text: lit((m.ascii ? "-" : "─").repeat(p.cols)), style: DIM, width: p.cols }];
|
|
576
|
+
} else if (g.wide || paged) {
|
|
561
577
|
const at = paged ? MARGIN : g.listCols + 2;
|
|
562
|
-
const drawn = detail(m, { cols: Math.max(0, cols - at - MARGIN), rows:
|
|
578
|
+
const drawn = detail(m, { cols: Math.max(0, cols - at - MARGIN), rows: size.rows });
|
|
563
579
|
extent = drawn.extent;
|
|
564
|
-
drawn.rows.forEach((spans, i) => { rows[
|
|
580
|
+
drawn.rows.forEach((spans, i) => { rows[i] = [...rows[i], ...placed(spans, at)]; });
|
|
581
|
+
// Over the whole screen, the detail's first row carries its keys, as an overlay's does.
|
|
582
|
+
if (paged) rows[0] = withKeys(rows[0], cheatSheet(m), cols, { first: true });
|
|
565
583
|
}
|
|
584
|
+
// Over the whole screen no cheat sheet is drawn: the terminal's title row, the TUI's own, carries
|
|
585
|
+
// its keys at the right instead (the leader, then Esc for the list), and while the leader waits,
|
|
586
|
+
// 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], cheatSheet(m), cols, { skip: ["again"] });
|
|
566
588
|
// The focused group's terminal, when it shows one: the agent's cursor, where the agent has it,
|
|
567
589
|
// while what is typed goes to the agent.
|
|
568
590
|
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;
|
|
@@ -571,72 +593,47 @@ function framed(m, size) {
|
|
|
571
593
|
// The regions the loop gives the panel (lib/main.mjs): each group drawn, its shown tab's id and
|
|
572
594
|
// its size; and the panel's room as the terminal's focus would give it, for a split's size.
|
|
573
595
|
const regions = area === null ? [] : area.regions.map(({ group, id, focused, cols: c, rows: r }) => ({ group, id, focused, cols: c, rows: r }));
|
|
574
|
-
return { rows, page: Math.max(1, g.page), extent, room:
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
/** The Souls view in the
|
|
578
|
-
*
|
|
579
|
-
*
|
|
580
|
-
*
|
|
581
|
-
*
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
const
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
let extent = 0;
|
|
592
|
-
if (split || paged) {
|
|
593
|
-
const at = paged ? MARGIN : g.listCols + 2;
|
|
594
|
-
const bar = split ? [{ col: g.listCols, text: lit(m.ascii ? "|" : "│"), style: DIM, width: 1 }] : [];
|
|
595
|
-
const drawn = soulDetail(m, { cols: Math.max(0, cols - at - MARGIN), rows: g.panes.rows });
|
|
596
|
-
extent = drawn.extent;
|
|
597
|
-
drawn.rows.forEach((spans, i) => { rows[g.panes.top + i] = [...rows[g.panes.top + i], ...bar, ...placed(spans, at)]; });
|
|
598
|
-
}
|
|
599
|
-
return { rows, page: Math.max(1, g.page), extent, room: Math.max(1, g.panes.rows) };
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
/** The Capabilities view in the panes of the list (views/capabilities.mjs), as the Souls view: the
|
|
603
|
-
* capabilities in the list's place and width, and beside them the selected capability's detail;
|
|
604
|
-
* under WIDE columns the list alone, and the detail in its place while it has the focus. A body of
|
|
605
|
-
* one sentence has the whole width. `capabilitiesTop` is the row the detail was drawn from, which
|
|
606
|
-
* the loop gives the store once the frame is written (it keeps the marked soul in sight). */
|
|
607
|
-
function capabilitiesFrame(m, size, g, rows) {
|
|
608
|
-
const { cols } = size, c = m.capabilities;
|
|
609
|
-
const paged = !g.wide && c.focus === "detail" && Boolean(c.detail);
|
|
610
|
-
const split = g.wide && g.panes.rows > 0 && capabilitiesListed(c);
|
|
611
|
-
const joint = split ? { col: g.listCols } : null;
|
|
612
|
-
const opening = m.observed && g.above > 0 ? g.panes.top - 1 : 2;
|
|
613
|
-
rows[2] = rule(cols, m.ascii, opening === 2 ? joint : null);
|
|
614
|
-
if (opening !== 2 && opening < size.rows - 1) rows[opening] = rule(cols, m.ascii, joint);
|
|
615
|
-
if (!paged) capabilitiesList(m, { cols: split ? g.listCols : cols, rows: g.panes.rows }).forEach((spans, i) => { rows[g.panes.top + i] = spans; });
|
|
616
|
-
let extent = 0, top;
|
|
617
|
-
if (split || paged) {
|
|
618
|
-
const at = paged ? MARGIN : g.listCols + 2;
|
|
619
|
-
const bar = split ? [{ col: g.listCols, text: lit(m.ascii ? "|" : "│"), style: DIM, width: 1 }] : [];
|
|
620
|
-
const drawn = capabilityDetail(m, { cols: Math.max(0, cols - at - MARGIN), rows: g.panes.rows });
|
|
621
|
-
extent = drawn.extent;
|
|
622
|
-
top = drawn.top;
|
|
623
|
-
drawn.rows.forEach((spans, i) => { rows[g.panes.top + i] = [...rows[g.panes.top + i], ...bar, ...placed(spans, at)]; });
|
|
596
|
+
return { rows, page: Math.max(1, g.page), extent, room: size.rows, terminal: shownArea, cursor, regions };
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/** The Souls or the Capabilities view: its list in the sidebar, and beside it in the main area the
|
|
600
|
+
* selected entry's detail (`draw`: views/souls.mjs soulDetail, views/capabilities.mjs
|
|
601
|
+
* capabilityDetail) once the list stands (`listed`); under WIDE columns the sidebar alone, and
|
|
602
|
+
* the detail as a page over the whole screen while it has the focus (`paged`), its first row
|
|
603
|
+
* carrying its keys (withKeys). Answers the detail's `extent` and, for the Capabilities view,
|
|
604
|
+
* `top`: the row the detail was drawn from, which the loop gives the store once the frame is
|
|
605
|
+
* written (it keeps the marked soul in sight). */
|
|
606
|
+
function viewFrame(m, size, g, rows, { listed, paged, draw }) {
|
|
607
|
+
const { cols } = size;
|
|
608
|
+
if (!g.wide && paged) {
|
|
609
|
+
const drawn = draw(m, { cols: Math.max(0, cols - 2 * MARGIN), rows: size.rows });
|
|
610
|
+
drawn.rows.forEach((spans, i) => { rows[i] = placed(spans, MARGIN); });
|
|
611
|
+
rows[0] = withKeys(rows[0], cheatSheet(m), cols, { first: true });
|
|
612
|
+
return { extent: drawn.extent, top: drawn.top };
|
|
624
613
|
}
|
|
625
|
-
|
|
614
|
+
sidebar(m, g, rows, listOf(m, g));
|
|
615
|
+
if (!g.wide) return { extent: 0 };
|
|
616
|
+
barred(m, rows, g.listCols);
|
|
617
|
+
if (!listed) return { extent: 0 };
|
|
618
|
+
const at = g.listCols + 2;
|
|
619
|
+
const drawn = draw(m, { cols: Math.max(0, cols - at - MARGIN), rows: size.rows });
|
|
620
|
+
drawn.rows.forEach((spans, i) => { rows[i] = [...rows[i], ...placed(spans, at)]; });
|
|
621
|
+
return { extent: drawn.extent, top: drawn.top };
|
|
626
622
|
}
|
|
627
623
|
|
|
628
624
|
/** Where the open terminal stands for a model and a size, or null while it is not shown (no
|
|
629
|
-
* terminal; another view
|
|
630
|
-
* too narrow for it beside the
|
|
625
|
+
* terminal; another view or an overlay; the detail in its place; the list's focus on a terminal
|
|
626
|
+
* too narrow for it beside the sidebar). `{ title, top, col, cols, rows, whole }`, the focused
|
|
631
627
|
* group's: `title` is the row that names the agent, and the agent's screen is `rows` rows of
|
|
632
628
|
* `cols` cells from (`top`, `col`) (the size the panel gives the viewer); with `panel` the whole
|
|
633
629
|
* panel's place, `regions` each group drawn (`group`, `id` its shown tab's or null, `focused`),
|
|
634
|
-
* and `rule` between two (views/split.mjs). With the terminal's focus it has
|
|
635
|
-
* zoomed, under WIDE columns, and when the side beside the
|
|
636
|
-
* (`whole`); else it stands beside the
|
|
630
|
+
* and `rule` between two (views/split.mjs). It spans every row. With the terminal's focus it has
|
|
631
|
+
* the whole screen when it is zoomed, under WIDE columns, and when the side beside the sidebar
|
|
632
|
+
* would be under PANEL_MIN cells (`whole`); else it stands beside the sidebar, edge to edge, in
|
|
633
|
+
* the detail's place. */
|
|
637
634
|
export function terminalArea(m, size) {
|
|
638
635
|
if (tooSmall(size)) return null;
|
|
639
|
-
return terminalAt(m, size,
|
|
636
|
+
return terminalAt(m, size, layoutOf(m, size));
|
|
640
637
|
}
|
|
641
638
|
/** Where the panel stands as the Instances view gives it with the terminal's focus, whatever this
|
|
642
639
|
* frame draws (an overlay, another view, the list's focus): `{ panel, focused }`, the panel's
|
|
@@ -645,7 +642,7 @@ export function terminalArea(m, size) {
|
|
|
645
642
|
* at), or null on a screen too small. */
|
|
646
643
|
export function panelPlace(m, size) {
|
|
647
644
|
if (tooSmall(size)) return null;
|
|
648
|
-
const g =
|
|
645
|
+
const g = layoutOf(m, size, { terminal: true, open: "instances" });
|
|
649
646
|
const area = terminalAt({ ...m, view: "instances", under: "instances", palette: null, spawn: null, panelOpen: true, terminal: { ...(m.terminal ?? {}), focus: "terminal" } }, size, g);
|
|
650
647
|
return { panel: panelRoom(size, g), focused: area === null ? null : { cols: area.cols, rows: area.rows } };
|
|
651
648
|
}
|
|
@@ -657,19 +654,19 @@ const groupsIn = (m) => m.groups ?? [{ tabs: m.tabs ?? [], shown: m.terminal?.id
|
|
|
657
654
|
* is measured against (lib/store.mjs splitRefused). */
|
|
658
655
|
function panelRoom(size, g) {
|
|
659
656
|
const side = size.cols - g.listCols - 1;
|
|
660
|
-
return { cols: !g.wide || side < PANEL_MIN ? size.cols : side, rows:
|
|
657
|
+
return { cols: !g.wide || side < PANEL_MIN ? size.cols : side, rows: size.rows };
|
|
661
658
|
}
|
|
662
659
|
function terminalAt(m, size, g) {
|
|
663
660
|
const t = m.terminal;
|
|
664
|
-
if (!panelOpen(m) || m.view !== "instances" || m.under === "switcher" || m.palette || m.spawn ||
|
|
661
|
+
if (!panelOpen(m) || m.view !== "instances" || m.under === "switcher" || m.palette || m.spawn || size.rows < 2) return null;
|
|
665
662
|
const focus = t?.focus ?? "list", zoom = Boolean(t?.zoom);
|
|
666
663
|
const side = size.cols - g.listCols - 1;
|
|
667
664
|
const narrow = !g.wide || side < PANEL_MIN;
|
|
668
665
|
const whole = focus === "terminal" && (zoom || narrow);
|
|
669
|
-
// From the list's focus it stands beside the
|
|
666
|
+
// From the list's focus it stands beside the sidebar, unless the detail stands there or there is no room.
|
|
670
667
|
if (focus !== "terminal" && (m.focus === "detail" || narrow)) return null;
|
|
671
668
|
const col = whole ? 0 : g.listCols + 1;
|
|
672
|
-
const panel = { title:
|
|
669
|
+
const panel = { title: 0, top: 1, col, cols: whole ? size.cols : side, rows: size.rows - 1 };
|
|
673
670
|
// Both groups while the panel holds them and nothing is zoomed; else the focused one alone, the
|
|
674
671
|
// other kept (Settled 3 of T3).
|
|
675
672
|
const groups = groupsIn(m), focused = m.group ?? 0;
|
|
@@ -750,7 +747,7 @@ const EMPTY_HINT = "Enter on an agent opens it here";
|
|
|
750
747
|
function emptyRows(m, area) {
|
|
751
748
|
const end = area.col + area.cols, at = area.col + 1;
|
|
752
749
|
const hint = [{ col: at, text: lit(EMPTY_HINT), width: Math.max(0, Math.min(EMPTY_HINT.length, end - at - 1)), ...(area.focused ? { style: FOCUSED } : {}) }];
|
|
753
|
-
const leader =
|
|
750
|
+
const leader = leaderText(m), keys = [];
|
|
754
751
|
let col = at;
|
|
755
752
|
for (const does of ["group-next", "group-close"]) {
|
|
756
753
|
const entry = LEADER.find((each) => each.does === does), key = keyLabel(entry.keys[0]), word = entry.label;
|