@operad-io/tui 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +68 -2
- package/package.json +27 -4
- package/src/actions.ts +997 -0
- package/src/app.ts +1665 -0
- package/src/args.ts +198 -0
- package/src/autostart.ts +302 -0
- package/src/client.ts +478 -0
- package/src/discover.ts +90 -0
- package/src/events.ts +345 -0
- package/src/index.ts +11 -0
- package/src/layout.ts +260 -0
- package/src/live.ts +113 -0
- package/src/markdown.ts +85 -0
- package/src/recent.ts +40 -0
- package/src/sanitize.ts +18 -0
- package/src/state.ts +3200 -0
- package/src/theme.ts +525 -0
- package/src/themes.ts +60 -0
- package/src/view/index.ts +1204 -0
- package/src/wrap.ts +156 -0
- package/theme.schema.json +197 -0
- package/themes/LICENSE-catppuccin +21 -0
- package/themes/LICENSE-dracula +21 -0
- package/themes/LICENSE-github +21 -0
- package/themes/LICENSE-kanagawa +21 -0
- package/themes/LICENSE-nord +21 -0
- package/themes/LICENSE-one +20 -0
- package/themes/LICENSE-rose-pine +21 -0
- package/themes/LICENSE-solarized +20 -0
- package/themes/LICENSE-tokyo-night +22 -0
- package/themes/README.md +81 -0
- package/themes/catppuccin-frappe.json +19 -0
- package/themes/catppuccin-latte.json +19 -0
- package/themes/catppuccin-macchiato.json +19 -0
- package/themes/catppuccin-mocha.json +19 -0
- package/themes/dracula.json +19 -0
- package/themes/github-dark.json +19 -0
- package/themes/github-light.json +19 -0
- package/themes/kanagawa-dragon.json +19 -0
- package/themes/kanagawa-lotus.json +19 -0
- package/themes/kanagawa-wave.json +19 -0
- package/themes/nord.json +19 -0
- package/themes/one-dark.json +19 -0
- package/themes/one-light.json +19 -0
- package/themes/rose-pine-dawn.json +19 -0
- package/themes/rose-pine-main.json +19 -0
- package/themes/solarized-dark.json +19 -0
- package/themes/solarized-light.json +19 -0
- package/themes/tokyo-night-day.json +19 -0
- package/themes/tokyo-night-night.json +19 -0
- package/tui.schema.json +24 -0
|
@@ -0,0 +1,1204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The OpenTUI view: it turns one `TuiState` into boxes and styled text. It owns
|
|
3
|
+
* no state, reads no clock and calls no client; every change arrives through
|
|
4
|
+
* `render(state)`.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
BoxRenderable,
|
|
9
|
+
StyledText,
|
|
10
|
+
TextAttributes,
|
|
11
|
+
TextRenderable,
|
|
12
|
+
type CliRenderer,
|
|
13
|
+
type TextChunk,
|
|
14
|
+
} from "@opentui/core";
|
|
15
|
+
import type { RowMark } from "@operad-io/engine";
|
|
16
|
+
import { allowedText } from "../args.ts";
|
|
17
|
+
import { confirmText, entryDetail, matchPositions, paletteEntries, settingText, type TuiPaletteEntry } from "../actions.ts";
|
|
18
|
+
import { chunksOfLine } from "../markdown.ts";
|
|
19
|
+
import {
|
|
20
|
+
TUI_PALETTE,
|
|
21
|
+
resolvePalette,
|
|
22
|
+
toRgba,
|
|
23
|
+
type ThemeSelection,
|
|
24
|
+
type TuiPalette,
|
|
25
|
+
} from "../theme.ts";
|
|
26
|
+
import { sanitize } from "../sanitize.ts";
|
|
27
|
+
import { displayWidth, graphemes, wrapText } from "../wrap.ts";
|
|
28
|
+
import {
|
|
29
|
+
CHILD_ROWS,
|
|
30
|
+
HELP_LINES,
|
|
31
|
+
KEY_GROUPS,
|
|
32
|
+
KEY_LIST,
|
|
33
|
+
ROW_INDENT,
|
|
34
|
+
activeSection,
|
|
35
|
+
bareId,
|
|
36
|
+
cancelledRow,
|
|
37
|
+
childProgress,
|
|
38
|
+
displayChildren,
|
|
39
|
+
rowDetail,
|
|
40
|
+
rowName,
|
|
41
|
+
activeTab,
|
|
42
|
+
LIST_HEAD,
|
|
43
|
+
dividerX,
|
|
44
|
+
listWidth,
|
|
45
|
+
rightX,
|
|
46
|
+
LIST_X,
|
|
47
|
+
bodyHeight,
|
|
48
|
+
filterHeader,
|
|
49
|
+
footerSegments,
|
|
50
|
+
helpViewport,
|
|
51
|
+
noticeText,
|
|
52
|
+
pageEntries,
|
|
53
|
+
pagePosition,
|
|
54
|
+
sectionLayout,
|
|
55
|
+
sectionTailLayout,
|
|
56
|
+
sectionWidth,
|
|
57
|
+
listWindow,
|
|
58
|
+
sectionViewport,
|
|
59
|
+
statusText,
|
|
60
|
+
twoPane,
|
|
61
|
+
type TuiChildEntry,
|
|
62
|
+
type TuiObject,
|
|
63
|
+
rowMark,
|
|
64
|
+
type TuiRow,
|
|
65
|
+
type TuiSection,
|
|
66
|
+
type TuiState,
|
|
67
|
+
type TuiTab,
|
|
68
|
+
type TuiTheme,
|
|
69
|
+
} from "../state.ts";
|
|
70
|
+
|
|
71
|
+
export { TUI_PALETTE, type TuiPalette };
|
|
72
|
+
|
|
73
|
+
/** The palette a state's theme names. */
|
|
74
|
+
export function paletteFor(theme: TuiTheme, name: string | ThemeSelection = "auto"): TuiPalette {
|
|
75
|
+
if (typeof name !== "string") return name.palette ?? resolvePalette(name.name, theme);
|
|
76
|
+
return resolvePalette(name, theme);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function chunk(
|
|
80
|
+
text: string,
|
|
81
|
+
color?: string,
|
|
82
|
+
attributes?: number,
|
|
83
|
+
background?: string,
|
|
84
|
+
): TextChunk {
|
|
85
|
+
return {
|
|
86
|
+
__isChunk: true,
|
|
87
|
+
// Whatever reaches the screen is cleaned here too, so a string that came
|
|
88
|
+
// by another way than the reducer cannot carry a control character.
|
|
89
|
+
text: sanitize(text),
|
|
90
|
+
...(color === undefined ? {} : { fg: toRgba(color) }),
|
|
91
|
+
...(background === undefined ? {} : { bg: toRgba(background) }),
|
|
92
|
+
...(attributes === undefined ? {} : { attributes }),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function styled(chunks: readonly TextChunk[]): StyledText {
|
|
97
|
+
return new StyledText([...chunks]);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The last lists stay visible but weak while the server does not answer. */
|
|
101
|
+
function dimmed(text: StyledText, on: boolean, palette: TuiPalette): StyledText {
|
|
102
|
+
if (!on) return text;
|
|
103
|
+
const fg = toRgba(palette.weak);
|
|
104
|
+
return new StyledText(text.chunks.map((part) => ({ ...part, fg })));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Cuts `text` to `width` display cells, ending in `…` when it was cut. */
|
|
108
|
+
export function fit(text: string, width: number): string {
|
|
109
|
+
const clean = sanitize(text).replace(/\n/g, " ");
|
|
110
|
+
if (width <= 0) return "";
|
|
111
|
+
let total = 0;
|
|
112
|
+
const all = graphemes(clean);
|
|
113
|
+
for (const char of all) total += displayWidth(char);
|
|
114
|
+
if (total <= width) return clean;
|
|
115
|
+
let out = "";
|
|
116
|
+
let used = 0;
|
|
117
|
+
for (const char of all) {
|
|
118
|
+
const next = displayWidth(char);
|
|
119
|
+
if (used + next > width - 1) break;
|
|
120
|
+
out += char;
|
|
121
|
+
used += next;
|
|
122
|
+
}
|
|
123
|
+
return `${out}…`;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** The count a tab shows after its name, when it has one. */
|
|
127
|
+
function tabCount(tab: TuiTab): number | undefined {
|
|
128
|
+
if (tab.kind === "plugin" && !tab.list.loaded) return undefined;
|
|
129
|
+
return tab.list.rows.length;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Cuts a line of chunks to `width` cells; the cut chunk ends in `…`. */
|
|
133
|
+
function truncateChunks(chunks: readonly TextChunk[], width: number): TextChunk[] {
|
|
134
|
+
const out: TextChunk[] = [];
|
|
135
|
+
let left = width;
|
|
136
|
+
for (const part of chunks) {
|
|
137
|
+
if (left <= 0) break;
|
|
138
|
+
const cells = displayWidth(part.text);
|
|
139
|
+
if (cells <= left) {
|
|
140
|
+
out.push(part);
|
|
141
|
+
left -= cells;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
out.push({ ...part, text: fit(part.text, left) });
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
return out;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function headerContent(state: TuiState, palette: TuiPalette): StyledText {
|
|
151
|
+
const chunks: TextChunk[] = [
|
|
152
|
+
chunk(" "),
|
|
153
|
+
chunk("operad", palette.text, TextAttributes.BOLD),
|
|
154
|
+
chunk(" "),
|
|
155
|
+
];
|
|
156
|
+
state.tabs.forEach((tab, index) => {
|
|
157
|
+
if (index > 0) chunks.push(chunk(" │ ", palette.weak));
|
|
158
|
+
const active = index === state.active;
|
|
159
|
+
const count = tabCount(tab);
|
|
160
|
+
chunks.push(
|
|
161
|
+
chunk(
|
|
162
|
+
count === undefined ? tab.title : `${tab.title} ${count}`,
|
|
163
|
+
active ? palette.accent : palette.weak,
|
|
164
|
+
active ? TextAttributes.BOLD : TextAttributes.NONE,
|
|
165
|
+
),
|
|
166
|
+
);
|
|
167
|
+
const extra = active ? filterHeader(tab) : undefined;
|
|
168
|
+
if (extra !== undefined) {
|
|
169
|
+
chunks.push(chunk(extra.filter, palette.accent));
|
|
170
|
+
if (extra.hidden !== "") chunks.push(chunk(extra.hidden, palette.weak));
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
return styled(truncateChunks(chunks, state.width));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** A thin horizontal rule from column 1 to the last column but one. */
|
|
177
|
+
function ruleContent(state: TuiState, palette: TuiPalette): StyledText {
|
|
178
|
+
return styled([
|
|
179
|
+
chunk(` ${"─".repeat(Math.max(0, state.width - 2))}`, palette.rule),
|
|
180
|
+
]);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** The divider's colour: the weak text colour, far clearer against the background than the rule. */
|
|
184
|
+
export function dividerColour(palette: TuiPalette): string {
|
|
185
|
+
return palette.weak;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** The dim title over the list: the page name, and a type list's filter. */
|
|
189
|
+
function listTitle(tab: TuiTab | undefined, palette: TuiPalette, width: number): TextChunk[] {
|
|
190
|
+
if (tab === undefined) return [];
|
|
191
|
+
const extra = filterHeader(tab);
|
|
192
|
+
// Cut to the list width: a wrapped title would push the last row out of the pane.
|
|
193
|
+
const title = fit(`${tab.title.toUpperCase()}${extra?.filter ?? ""}`, Math.max(1, width));
|
|
194
|
+
return [chunk(title, palette.weak), chunk("\n")];
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function dividerContent(state: TuiState, palette: TuiPalette): StyledText {
|
|
198
|
+
return styled([
|
|
199
|
+
chunk(Array.from({ length: bodyHeight(state) }, () => "│").join("\n"), dividerColour(palette)),
|
|
200
|
+
]);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** The columns a row under a group is indented. */
|
|
204
|
+
const GROUP_INDENT = 2;
|
|
205
|
+
|
|
206
|
+
type MarkColour = "weak" | "accent" | "run" | "ok" | "error";
|
|
207
|
+
|
|
208
|
+
/** One single-cell character and colour role per mark. */
|
|
209
|
+
export const MARK_GLYPHS: Readonly<
|
|
210
|
+
Record<RowMark, { readonly char: string; readonly colour: MarkColour }>
|
|
211
|
+
> = {
|
|
212
|
+
todo: { char: "○", colour: "weak" },
|
|
213
|
+
blocked: { char: "◌", colour: "weak" },
|
|
214
|
+
retry_wait: { char: "◷", colour: "weak" },
|
|
215
|
+
paused: { char: "‖", colour: "weak" },
|
|
216
|
+
proposed: { char: "+", colour: "accent" },
|
|
217
|
+
starting: { char: "◔", colour: "run" },
|
|
218
|
+
running: { char: "◐", colour: "run" },
|
|
219
|
+
reconciling: { char: "↻", colour: "run" },
|
|
220
|
+
checking: { char: "⌕", colour: "run" },
|
|
221
|
+
rework_pending: { char: "↩", colour: "accent" },
|
|
222
|
+
waiting: { char: "●", colour: "accent" },
|
|
223
|
+
integrating: { char: "⑂", colour: "run" },
|
|
224
|
+
ready_to_merge: { char: "◉", colour: "ok" },
|
|
225
|
+
done: { char: "✓", colour: "ok" },
|
|
226
|
+
failed: { char: "✗", colour: "error" },
|
|
227
|
+
cancelled: { char: "⊘", colour: "weak" },
|
|
228
|
+
broken: { char: "!", colour: "error" },
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
/** The glyph and colour of a list row. */
|
|
232
|
+
function glyph(row: TuiRow, palette: TuiPalette, tint?: string): TextChunk {
|
|
233
|
+
if (row.error !== undefined) return chunk("✗", palette.error, undefined, tint);
|
|
234
|
+
const mark = rowMark(row);
|
|
235
|
+
// A mark this client does not know (a newer server) draws as plain.
|
|
236
|
+
const shown = mark === "none" ? undefined : MARK_GLYPHS[mark];
|
|
237
|
+
if (shown !== undefined) return chunk(shown.char, palette[shown.colour], undefined, tint);
|
|
238
|
+
return chunk("○", palette.weak, undefined, tint);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** One object: its line, its dim line, both tinted to the pane's edge when selected. */
|
|
242
|
+
function drawRow(
|
|
243
|
+
row: TuiRow,
|
|
244
|
+
selected: boolean,
|
|
245
|
+
palette: TuiPalette,
|
|
246
|
+
width: number,
|
|
247
|
+
titles = true,
|
|
248
|
+
place: { readonly indent?: number; readonly folder?: boolean } = {},
|
|
249
|
+
): TextChunk[] {
|
|
250
|
+
const indent = place.indent ?? 0;
|
|
251
|
+
const tint = selected ? palette.tint : undefined;
|
|
252
|
+
const room = Math.max(0, width - ROW_INDENT - indent);
|
|
253
|
+
const name = row.unnamed === true && row.title !== "" ? row.title : rowName(row);
|
|
254
|
+
const head = fit(name, room);
|
|
255
|
+
const left = room - displayWidth(head);
|
|
256
|
+
const title =
|
|
257
|
+
!titles || row.unnamed === true || row.title === "" || left < 4
|
|
258
|
+
? ""
|
|
259
|
+
: fit(row.title, left - 2);
|
|
260
|
+
const first = title === "" ? head : `${head} `;
|
|
261
|
+
const pad1 = " ".repeat(Math.max(0, room - displayWidth(first) - displayWidth(title)));
|
|
262
|
+
const detail = fit(rowDetail(row), room);
|
|
263
|
+
const pad2 = " ".repeat(Math.max(0, room - displayWidth(detail)));
|
|
264
|
+
const fill = (text: string): TextChunk[] =>
|
|
265
|
+
text === "" || !selected ? [] : [chunk(text, undefined, undefined, tint)];
|
|
266
|
+
return [
|
|
267
|
+
chunk(selected ? "❯" : " ", palette.accent, undefined, tint),
|
|
268
|
+
chunk(" ", undefined, undefined, tint),
|
|
269
|
+
...(indent === 0 ? [] : [chunk(" ".repeat(indent), undefined, undefined, tint)]),
|
|
270
|
+
place.folder === true ? folder(row, palette, tint) : glyph(row, palette, tint),
|
|
271
|
+
chunk(" ", undefined, undefined, tint),
|
|
272
|
+
chunk(first, selected ? palette.accent : palette.text, undefined, tint),
|
|
273
|
+
...(title === "" ? [] : [chunk(title, palette.text, undefined, tint)]),
|
|
274
|
+
...fill(pad1),
|
|
275
|
+
chunk("\n"),
|
|
276
|
+
chunk(" ".repeat(ROW_INDENT + indent), undefined, undefined, tint),
|
|
277
|
+
...(detail === "" ? [] : [chunk(detail, palette.weak, undefined, tint)]),
|
|
278
|
+
...fill(pad2),
|
|
279
|
+
chunk("\n"),
|
|
280
|
+
];
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** The folder icon of a repository group: one cell, in the colour its row's mark has when that is the running colour. */
|
|
284
|
+
const FOLDER = "▤";
|
|
285
|
+
|
|
286
|
+
function folder(row: TuiRow, palette: TuiPalette, tint?: string): TextChunk {
|
|
287
|
+
const mark = rowMark(row);
|
|
288
|
+
const running = mark !== "none" && MARK_GLYPHS[mark]?.colour === "run";
|
|
289
|
+
return chunk(FOLDER, running ? palette.run : palette.weak, undefined, tint);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** The columns a list row has, marker and glyph included. */
|
|
293
|
+
function listCells(state: TuiState): number {
|
|
294
|
+
return twoPane(state) ? listWidth(state) : Math.max(1, state.width - LIST_X - 1);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function listContent(
|
|
298
|
+
state: TuiState,
|
|
299
|
+
tab: TuiTab | undefined,
|
|
300
|
+
palette: TuiPalette,
|
|
301
|
+
): StyledText {
|
|
302
|
+
if (tab === undefined) return styled([chunk("no tabs", palette.weak)]);
|
|
303
|
+
if (tab.list.rows.length === 0) {
|
|
304
|
+
const message = !tab.list.loaded
|
|
305
|
+
? "loading…"
|
|
306
|
+
: tab.kind === "pending"
|
|
307
|
+
? "nothing waits for you"
|
|
308
|
+
: tab.filters !== undefined && tab.filter !== undefined
|
|
309
|
+
? `nothing ${tab.filter} in ${tab.title.toLowerCase()}`
|
|
310
|
+
: `nothing in ${tab.title.toLowerCase()}`;
|
|
311
|
+
return styled([chunk("\n"), ...listTitle(tab, palette, listCells(state)), chunk(message, palette.weak)]);
|
|
312
|
+
}
|
|
313
|
+
const width = listCells(state);
|
|
314
|
+
const chunks: TextChunk[] = [chunk("\n"), ...listTitle(tab, palette, width)];
|
|
315
|
+
const window = listWindow(tab.list, Math.max(1, bodyHeight(state) - LIST_HEAD));
|
|
316
|
+
const titles = tab.kind !== "plugin";
|
|
317
|
+
const grouped = tab.list.rows.some((row) => row.group !== undefined || row.heading === true);
|
|
318
|
+
tab.list.rows.slice(window.start, window.end).forEach((row, offset) => {
|
|
319
|
+
if (offset > 0) chunks.push(chunk("\n"));
|
|
320
|
+
if (row.group !== undefined) {
|
|
321
|
+
chunks.push(...drawRow(row.group, false, palette, width, titles, { folder: true }));
|
|
322
|
+
chunks.push(chunk("\n"));
|
|
323
|
+
}
|
|
324
|
+
chunks.push(
|
|
325
|
+
...drawRow(row, window.start + offset === tab.list.cursor, palette, width, titles, {
|
|
326
|
+
indent:
|
|
327
|
+
row.heading === true
|
|
328
|
+
? 0
|
|
329
|
+
: grouped && row.bare !== true
|
|
330
|
+
? GROUP_INDENT
|
|
331
|
+
: 0,
|
|
332
|
+
...(row.heading === true || row.bare === true ? { folder: true } : {}),
|
|
333
|
+
}),
|
|
334
|
+
);
|
|
335
|
+
});
|
|
336
|
+
if (tab.list.loading) chunks.push(chunk("loading more…\n", palette.weak));
|
|
337
|
+
if (tab.list.error !== undefined) {
|
|
338
|
+
chunks.push(chunk(fit(tab.list.error, width), palette.error));
|
|
339
|
+
}
|
|
340
|
+
return styled(chunks);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** The line of the frame's top border: the row's id, state, badge and note. */
|
|
344
|
+
function objectLabel(row: TuiRow): string {
|
|
345
|
+
return [bareId(row.id), row.state, row.badge ?? "", row.note ?? ""]
|
|
346
|
+
.map((part) => part.trim())
|
|
347
|
+
.filter((part) => part !== "")
|
|
348
|
+
.join(" · ");
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** The top border of the page's frame, with the row's line cut to fit. */
|
|
352
|
+
function frameTop(label: string, width: number, palette: TuiPalette): TextChunk[] {
|
|
353
|
+
const shown = fit(label, Math.max(0, width - 4));
|
|
354
|
+
const dashes = Math.max(0, width - 4 - displayWidth(shown));
|
|
355
|
+
return [
|
|
356
|
+
chunk("╭─ ", palette.rule),
|
|
357
|
+
chunk(shown, palette.weak),
|
|
358
|
+
chunk(` ${"─".repeat(dashes)}`, palette.rule),
|
|
359
|
+
chunk("\n"),
|
|
360
|
+
];
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function frameBottom(palette: TuiPalette): TextChunk[] {
|
|
364
|
+
return [chunk("╰──", palette.rule), chunk("\n")];
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** One line inside the frame's left rail. */
|
|
368
|
+
function rail(chunks: readonly TextChunk[], palette: TuiPalette): TextChunk[] {
|
|
369
|
+
return [chunk("│ ", palette.rule), ...chunks, chunk("\n")];
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** The colour role of a mark's glyph. */
|
|
373
|
+
function markColour(row: TuiRow, palette: TuiPalette): string {
|
|
374
|
+
if (row.error !== undefined) return palette.error;
|
|
375
|
+
const mark = rowMark(row);
|
|
376
|
+
// A finished child is weak: the progress bar already says it is done, and its
|
|
377
|
+
// row should not draw the eye away from the work left (T-0305).
|
|
378
|
+
if (mark === "done" || mark === "none") return palette.weak;
|
|
379
|
+
return palette[MARK_GLYPHS[mark].colour];
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* The bar's cells as chunks across `width`: only the done share is filled, the
|
|
384
|
+
* rest of the track stays empty and cancelled children keep their dark red
|
|
385
|
+
* cells last, outside the done / total count.
|
|
386
|
+
*/
|
|
387
|
+
function progressBar(
|
|
388
|
+
progress: ReturnType<typeof childProgress>,
|
|
389
|
+
width: number,
|
|
390
|
+
palette: TuiPalette,
|
|
391
|
+
): TextChunk[] {
|
|
392
|
+
const cancelled = progress.entries.filter((entry) => cancelledRow(entry.row)).length;
|
|
393
|
+
const cells = progress.total + cancelled;
|
|
394
|
+
if (cells === 0) return [];
|
|
395
|
+
const done = Math.min(progress.done, progress.total);
|
|
396
|
+
const base = Math.floor(width / cells);
|
|
397
|
+
const extra = width % cells;
|
|
398
|
+
const chunks: TextChunk[] = [];
|
|
399
|
+
for (let at = 0; at < cells; at += 1) {
|
|
400
|
+
const count = base + (at < extra ? 1 : 0);
|
|
401
|
+
if (count === 0) continue;
|
|
402
|
+
if (at < done) chunks.push(chunk("█".repeat(count), palette.ok));
|
|
403
|
+
else if (at < progress.total) chunks.push(chunk(" ".repeat(count)));
|
|
404
|
+
else chunks.push(chunk("█".repeat(count), palette.cancelled));
|
|
405
|
+
}
|
|
406
|
+
return chunks;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/** The heading under the bar: the type name left, `done / total` right. */
|
|
410
|
+
function childHeading(
|
|
411
|
+
type: string,
|
|
412
|
+
done: number,
|
|
413
|
+
total: number,
|
|
414
|
+
width: number,
|
|
415
|
+
palette: TuiPalette,
|
|
416
|
+
): TextChunk[] {
|
|
417
|
+
const left = type === "" ? "" : type.toUpperCase();
|
|
418
|
+
const right = `${done} / ${total}`;
|
|
419
|
+
const gap = Math.max(1, width - displayWidth(left) - displayWidth(right));
|
|
420
|
+
return [chunk(fit(`${left}${" ".repeat(gap)}${right}`, width), palette.weak)];
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/** A child's id without its type or repository. */
|
|
424
|
+
function childId(row: TuiRow): string {
|
|
425
|
+
const bare = bareId(row.id);
|
|
426
|
+
const slash = bare.lastIndexOf("/");
|
|
427
|
+
return slash < 0 ? bare : bare.slice(slash + 1);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
interface ChildColumns {
|
|
431
|
+
/** Where the id column ends, counted from the connector's first cell. */
|
|
432
|
+
readonly end: number;
|
|
433
|
+
readonly state: number;
|
|
434
|
+
readonly badge: number;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/** Cells before the id: the connector and its space, then the glyph and its space. */
|
|
438
|
+
function leadWidth(entry: TuiChildEntry): number {
|
|
439
|
+
const connector = displayWidth(entry.connector);
|
|
440
|
+
return (connector === 0 ? 0 : connector + 1) + 2;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/** The fixed column widths of one child list, so every state starts in one place. */
|
|
444
|
+
function childColumns(entries: readonly TuiChildEntry[], width: number): ChildColumns {
|
|
445
|
+
const end = Math.max(0, ...entries.map((entry) => leadWidth(entry) + displayWidth(childId(entry.row))));
|
|
446
|
+
const lead = Math.max(0, ...entries.map(leadWidth));
|
|
447
|
+
const state = Math.max(0, ...entries.map((entry) => displayWidth(entry.row.state)));
|
|
448
|
+
const badge = Math.max(0, ...entries.map((entry) => displayWidth(entry.row.badge ?? "")));
|
|
449
|
+
// cursor, the lead, id, state and badge, with one space between columns.
|
|
450
|
+
const fixed = 2 + 1 + state + (badge === 0 ? 0 : badge + 1);
|
|
451
|
+
return { end: Math.min(end, Math.max(lead + 4, width - fixed)), state, badge };
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function padTo(text: string, width: number): string {
|
|
455
|
+
const shown = fit(text, width);
|
|
456
|
+
return shown + " ".repeat(Math.max(0, width - displayWidth(shown)));
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/** One child row: connector, glyph, id, state, badge, note and `also after`. */
|
|
460
|
+
function childRow(
|
|
461
|
+
entry: TuiChildEntry,
|
|
462
|
+
selected: boolean,
|
|
463
|
+
palette: TuiPalette,
|
|
464
|
+
width: number,
|
|
465
|
+
columns: ChildColumns,
|
|
466
|
+
): TextChunk[] {
|
|
467
|
+
const row = entry.row;
|
|
468
|
+
const tint = selected ? palette.tint : undefined;
|
|
469
|
+
const colour = markColour(row, palette);
|
|
470
|
+
const mark = rowMark(row);
|
|
471
|
+
const glyph = mark === "none" ? "○" : MARK_GLYPHS[mark].char;
|
|
472
|
+
const state = padTo(row.state, columns.state);
|
|
473
|
+
const badge = columns.badge === 0 ? "" : padTo(row.badge ?? "", columns.badge);
|
|
474
|
+
const notes = [row.note ?? "", entry.alsoAfter.length === 0 ? "" : `also after ${entry.alsoAfter.join(", ")}`]
|
|
475
|
+
.filter((part) => part !== "");
|
|
476
|
+
const chunks: TextChunk[] = [
|
|
477
|
+
chunk(selected ? "❯ " : " ", palette.accent, undefined, tint),
|
|
478
|
+
...(entry.connector === ""
|
|
479
|
+
? []
|
|
480
|
+
: [chunk(entry.connector + " ", palette.rule, undefined, tint)]),
|
|
481
|
+
chunk(`${glyph} `, colour, undefined, tint),
|
|
482
|
+
chunk(padTo(childId(row), Math.max(0, columns.end - leadWidth(entry))), selected ? palette.accent : palette.text, undefined, tint),
|
|
483
|
+
chunk(" ", undefined, undefined, tint),
|
|
484
|
+
chunk(state, colour, undefined, tint),
|
|
485
|
+
...(columns.badge === 0
|
|
486
|
+
? []
|
|
487
|
+
: [chunk(" ", undefined, undefined, tint), chunk(badge, palette.weak, undefined, tint)]),
|
|
488
|
+
...(notes.length === 0
|
|
489
|
+
? []
|
|
490
|
+
: [chunk(` ${notes.join(" ")}`, palette.weak, undefined, tint)]),
|
|
491
|
+
];
|
|
492
|
+
return truncateChunks(chunks, width);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/** The page's next level: the bar, its heading and one aligned line per child. */
|
|
496
|
+
function childrenContent(
|
|
497
|
+
object: TuiObject,
|
|
498
|
+
state: TuiState,
|
|
499
|
+
palette: TuiPalette,
|
|
500
|
+
width: number,
|
|
501
|
+
): TextChunk[] {
|
|
502
|
+
const children = object.children;
|
|
503
|
+
if (children === undefined || children.rows.length === 0) {
|
|
504
|
+
return [];
|
|
505
|
+
}
|
|
506
|
+
const progress = childProgress(children.rows, state.childLayout);
|
|
507
|
+
const shown = displayChildren(children.rows, state.childLayout);
|
|
508
|
+
const type = shown[0]?.row.type ?? "";
|
|
509
|
+
const columns = childColumns(shown, width);
|
|
510
|
+
const chunks: TextChunk[] = [
|
|
511
|
+
...rail(progressBar(progress, width, palette), palette),
|
|
512
|
+
...rail(childHeading(type, progress.done, progress.total, width, palette), palette),
|
|
513
|
+
];
|
|
514
|
+
const start = children.cursor >= CHILD_ROWS ? children.cursor - CHILD_ROWS + 1 : 0;
|
|
515
|
+
shown.slice(start, start + CHILD_ROWS).forEach((entry, offset) => {
|
|
516
|
+
const selected = children.focused && start + offset === children.cursor;
|
|
517
|
+
chunks.push(...rail(childRow(entry, selected, palette, width, columns), palette));
|
|
518
|
+
});
|
|
519
|
+
return chunks;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
function sectionTabs(object: TuiObject, palette: TuiPalette, width: number): TextChunk[] {
|
|
523
|
+
const chunks: TextChunk[] = [];
|
|
524
|
+
let rule = "";
|
|
525
|
+
let used = 0;
|
|
526
|
+
object.sections.forEach((section, index) => {
|
|
527
|
+
const label = `${section.title}${section.live ? " ●" : ""}`;
|
|
528
|
+
const gap = index > 0 ? " · " : "";
|
|
529
|
+
if (used + displayWidth(gap) + displayWidth(label) > width) return;
|
|
530
|
+
const active = index === object.active;
|
|
531
|
+
chunks.push(chunk(gap));
|
|
532
|
+
chunks.push(
|
|
533
|
+
chunk(
|
|
534
|
+
label,
|
|
535
|
+
active ? palette.accent : palette.weak,
|
|
536
|
+
active ? TextAttributes.BOLD : TextAttributes.NONE,
|
|
537
|
+
),
|
|
538
|
+
);
|
|
539
|
+
rule += `${" ".repeat(displayWidth(gap))}${(active ? "─" : " ").repeat(displayWidth(label))}`;
|
|
540
|
+
used += displayWidth(gap) + displayWidth(label);
|
|
541
|
+
});
|
|
542
|
+
chunks.push(chunk("\n"));
|
|
543
|
+
chunks.push(chunk(rule.trimEnd(), palette.rule));
|
|
544
|
+
chunks.push(chunk("\n"));
|
|
545
|
+
return chunks;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function sectionHint(
|
|
549
|
+
section: TuiSection,
|
|
550
|
+
following: boolean,
|
|
551
|
+
palette: TuiPalette,
|
|
552
|
+
width: number,
|
|
553
|
+
): TextChunk[] {
|
|
554
|
+
if (section.error !== undefined) {
|
|
555
|
+
return [chunk(`${fit(`${section.error} · r retries`, width)}\n`, palette.error)];
|
|
556
|
+
}
|
|
557
|
+
if (section.loading) return [chunk("loading…\n", palette.weak)];
|
|
558
|
+
if (section.capped && !section.full) {
|
|
559
|
+
return [chunk("Truncated · f loads all of it\n", palette.weak)];
|
|
560
|
+
}
|
|
561
|
+
if (section.live && following) return [chunk("following\n", palette.weak)];
|
|
562
|
+
return [];
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
function sectionContent(
|
|
566
|
+
state: TuiState,
|
|
567
|
+
section: TuiSection | undefined,
|
|
568
|
+
palette: TuiPalette,
|
|
569
|
+
): TextChunk[] {
|
|
570
|
+
if (section === undefined) {
|
|
571
|
+
return [chunk(state.object?.loading === true ? "loading…" : "no sections", palette.weak)];
|
|
572
|
+
}
|
|
573
|
+
if (!section.loaded) {
|
|
574
|
+
return [chunk(section.loading ? "loading…" : "not loaded", palette.weak)];
|
|
575
|
+
}
|
|
576
|
+
const viewport = sectionViewport(state);
|
|
577
|
+
const content = sectionLayout(state, section);
|
|
578
|
+
const tail = sectionTailLayout(state, section);
|
|
579
|
+
const total = content.length + tail.length;
|
|
580
|
+
const start = Math.min(Math.max(0, section.scroll), Math.max(0, total - 1));
|
|
581
|
+
const chunks: TextChunk[] = [];
|
|
582
|
+
for (let at = start; at < Math.min(start + viewport, total); at += 1) {
|
|
583
|
+
const line = at < content.length ? content[at] : tail[at - content.length];
|
|
584
|
+
if (line === undefined) continue;
|
|
585
|
+
chunks.push(...chunksOfLine(line, palette, at >= content.length), chunk("\n"));
|
|
586
|
+
}
|
|
587
|
+
return chunks;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
function objectContent(state: TuiState, palette: TuiPalette): StyledText {
|
|
591
|
+
const object = state.object;
|
|
592
|
+
if (object === undefined) {
|
|
593
|
+
// An openable cursor row is on the way; a row that names no object, or an empty list, asks.
|
|
594
|
+
const tab = state.tabs[state.active];
|
|
595
|
+
const under = tab?.list.rows[tab.list.cursor];
|
|
596
|
+
const waiting = state.followPending && under !== undefined && under.openable !== false;
|
|
597
|
+
return styled([
|
|
598
|
+
chunk("\n"),
|
|
599
|
+
chunk(waiting ? "loading…" : "select an object", palette.weak),
|
|
600
|
+
]);
|
|
601
|
+
}
|
|
602
|
+
const section = activeSection(state);
|
|
603
|
+
const width = sectionWidth(state);
|
|
604
|
+
const inside = Math.max(1, width - 2);
|
|
605
|
+
const chunks: TextChunk[] = [
|
|
606
|
+
...frameTop(objectLabel(object.row), width, palette),
|
|
607
|
+
...rail([], palette),
|
|
608
|
+
];
|
|
609
|
+
if (object.row.title !== "") {
|
|
610
|
+
for (const line of wrapText(object.row.title, inside)) {
|
|
611
|
+
chunks.push(...rail([chunk(line, palette.text)], palette));
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
const position = pagePosition(section, state);
|
|
615
|
+
const status =
|
|
616
|
+
object.error !== undefined
|
|
617
|
+
? { text: object.error, colour: palette.error }
|
|
618
|
+
: object.row.error !== undefined
|
|
619
|
+
? { text: object.row.error, colour: palette.error }
|
|
620
|
+
: object.unavailable !== undefined
|
|
621
|
+
? { text: object.unavailable, colour: palette.weak }
|
|
622
|
+
: position === undefined
|
|
623
|
+
? undefined
|
|
624
|
+
: { text: position, colour: palette.accent };
|
|
625
|
+
if (status !== undefined) {
|
|
626
|
+
chunks.push(...rail([chunk(fit(status.text, inside), status.colour)], palette));
|
|
627
|
+
}
|
|
628
|
+
chunks.push(...childrenContent(object, state, palette, inside));
|
|
629
|
+
chunks.push(...frameBottom(palette));
|
|
630
|
+
chunks.push(chunk("\n"));
|
|
631
|
+
chunks.push(...sectionTabs(object, palette, width));
|
|
632
|
+
chunks.push(
|
|
633
|
+
...(section === undefined
|
|
634
|
+
? sectionContent(state, section, palette)
|
|
635
|
+
: [
|
|
636
|
+
...sectionContent(state, section, palette),
|
|
637
|
+
...sectionHint(section, section.following, palette, width),
|
|
638
|
+
]),
|
|
639
|
+
);
|
|
640
|
+
return styled(chunks);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
function keyContent(state: TuiState, palette: TuiPalette): StyledText {
|
|
644
|
+
const width = Math.max(...KEY_LIST.map(([key]) => displayWidth(key)));
|
|
645
|
+
const room = Math.max(1, overlayTextWidth(state) - 2 - width - 2);
|
|
646
|
+
const lines: TextChunk[][] = [[chunk("keys\n", palette.accent, TextAttributes.BOLD)]];
|
|
647
|
+
KEY_GROUPS.forEach((group, at) => {
|
|
648
|
+
if (at > 0) lines.push([chunk("\n")]);
|
|
649
|
+
for (const [key, what] of group) {
|
|
650
|
+
const pad = " ".repeat(Math.max(0, width - displayWidth(key)));
|
|
651
|
+
lines.push([
|
|
652
|
+
chunk(` ${key}${pad} `, palette.accent),
|
|
653
|
+
chunk(`${fit(what, room)}\n`, palette.weak),
|
|
654
|
+
]);
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
const rows = helpViewport(state);
|
|
658
|
+
const start = Math.min(Math.max(0, state.helpScroll), Math.max(0, lines.length - rows));
|
|
659
|
+
return styled(lines.slice(start, start + rows).flat());
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
/** One line of the palette's body: a blank, a group label, or an entry. */
|
|
663
|
+
type PaletteLine =
|
|
664
|
+
| { readonly kind: "blank" }
|
|
665
|
+
| { readonly kind: "group"; readonly group: string }
|
|
666
|
+
| { readonly kind: "entry"; readonly entry: TuiPaletteEntry; readonly at: number };
|
|
667
|
+
|
|
668
|
+
/** The palette's body in drawing order: each group label over its entries, a blank line between groups. */
|
|
669
|
+
function paletteDisplayLines(entries: readonly TuiPaletteEntry[]): readonly PaletteLine[] {
|
|
670
|
+
const lines: PaletteLine[] = [];
|
|
671
|
+
let last: string | undefined;
|
|
672
|
+
entries.forEach((entry, at) => {
|
|
673
|
+
if (entry.group !== last) {
|
|
674
|
+
if (last !== undefined) lines.push({ kind: "blank" });
|
|
675
|
+
lines.push({ kind: "group", group: entry.groupTitle ?? entry.group });
|
|
676
|
+
last = entry.group;
|
|
677
|
+
}
|
|
678
|
+
lines.push({ kind: "entry", entry, at });
|
|
679
|
+
});
|
|
680
|
+
return lines;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
/** The object a palette entry acts on: the open object, for its actions. */
|
|
684
|
+
function paletteObject(state: TuiState, entry: TuiPaletteEntry): string {
|
|
685
|
+
return entry.group === "actions" && state.object !== undefined ? bareId(state.object.id) : "";
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
/** What a palette entry says after its name: the command's title, or the action's own detail. */
|
|
689
|
+
function paletteDetail(entry: TuiPaletteEntry): string {
|
|
690
|
+
return entry.group === "tui" ? entry.title : entryDetail(entry);
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
interface PaletteColumns {
|
|
694
|
+
readonly name: number;
|
|
695
|
+
readonly object: number;
|
|
696
|
+
readonly detail: number;
|
|
697
|
+
readonly key: number;
|
|
698
|
+
readonly hasObject: boolean;
|
|
699
|
+
readonly hasKey: boolean;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
/** The cells between two palette columns. */
|
|
703
|
+
const PALETTE_GAP = 2;
|
|
704
|
+
|
|
705
|
+
/** The column widths of a palette at `width` cells: name, object, detail and a right-aligned key. */
|
|
706
|
+
function paletteColumns(
|
|
707
|
+
state: TuiState,
|
|
708
|
+
entries: readonly TuiPaletteEntry[],
|
|
709
|
+
width: number,
|
|
710
|
+
): PaletteColumns {
|
|
711
|
+
const widest = (texts: readonly string[]): number =>
|
|
712
|
+
texts.reduce((most, text) => Math.max(most, displayWidth(text)), 0);
|
|
713
|
+
let hasObject = entries.some((entry) => paletteObject(state, entry) !== "");
|
|
714
|
+
const hasKey = entries.some((entry) => entry.key !== undefined);
|
|
715
|
+
const keyWidth = hasKey ? Math.min(8, Math.max(1, widest(entries.map((entry) => entry.key ?? "")))) : 0;
|
|
716
|
+
let name = Math.min(26, Math.max(1, widest(entries.map((entry) => entry.name))));
|
|
717
|
+
let object = hasObject ? Math.min(24, widest(entries.map((entry) => paletteObject(state, entry)))) : 0;
|
|
718
|
+
const gaps = 2 + PALETTE_GAP + (hasObject ? PALETTE_GAP : 0) + (hasKey ? PALETTE_GAP + keyWidth : 0);
|
|
719
|
+
let detail = width - gaps - name - object;
|
|
720
|
+
// A long name gives way first, then a long object, so the detail keeps some room.
|
|
721
|
+
const give = (from: number, floor: number): number => {
|
|
722
|
+
const cut = Math.min(from - floor, Math.max(0, 6 - detail));
|
|
723
|
+
detail += cut;
|
|
724
|
+
return from - cut;
|
|
725
|
+
};
|
|
726
|
+
if (detail < 6) name = give(name, 4);
|
|
727
|
+
if (detail < 6) object = give(object, 0);
|
|
728
|
+
if (object === 0 && hasObject) {
|
|
729
|
+
hasObject = false;
|
|
730
|
+
detail += PALETTE_GAP;
|
|
731
|
+
}
|
|
732
|
+
if (detail < 1 && name > 1) name = give(name, 1);
|
|
733
|
+
if (detail < 1) object = give(object, 0);
|
|
734
|
+
return { name, object, detail: Math.max(1, detail), key: keyWidth, hasObject: object > 0, hasKey };
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
/** One palette entry in its columns, the key at the right edge. */
|
|
738
|
+
function paletteEntryLine(
|
|
739
|
+
state: TuiState,
|
|
740
|
+
line: Extract<PaletteLine, { readonly kind: "entry" }>,
|
|
741
|
+
columns: PaletteColumns,
|
|
742
|
+
width: number,
|
|
743
|
+
palette: TuiPalette,
|
|
744
|
+
): TextChunk[] {
|
|
745
|
+
const { entry, at } = line;
|
|
746
|
+
const input = state.input;
|
|
747
|
+
const query = input?.kind === "palette" ? input.query : "";
|
|
748
|
+
const selected = input?.kind === "palette" && at === input.cursor;
|
|
749
|
+
const shown = fit(entry.name, columns.name);
|
|
750
|
+
const marked = new Set(matchPositions(query, entry));
|
|
751
|
+
const colour = selected ? palette.accent : palette.text;
|
|
752
|
+
const chunks: TextChunk[] = [chunk(selected ? "❯ " : " ", palette.accent)];
|
|
753
|
+
let used = 0;
|
|
754
|
+
for (const run of nameRuns(shown, marked)) {
|
|
755
|
+
used += displayWidth(run.text);
|
|
756
|
+
chunks.push(
|
|
757
|
+
run.marked
|
|
758
|
+
? chunk(run.text, palette.accent, TextAttributes.BOLD | TextAttributes.UNDERLINE)
|
|
759
|
+
: chunk(run.text, colour),
|
|
760
|
+
);
|
|
761
|
+
}
|
|
762
|
+
chunks.push(chunk(" ".repeat(Math.max(0, columns.name - used))));
|
|
763
|
+
if (columns.hasObject) {
|
|
764
|
+
const object = fit(paletteObject(state, entry), columns.object);
|
|
765
|
+
chunks.push(chunk(" ".repeat(PALETTE_GAP)));
|
|
766
|
+
chunks.push(chunk(object, palette.weak));
|
|
767
|
+
chunks.push(chunk(" ".repeat(Math.max(0, columns.object - displayWidth(object)))));
|
|
768
|
+
}
|
|
769
|
+
chunks.push(chunk(" ".repeat(PALETTE_GAP)));
|
|
770
|
+
const detail = fit(paletteDetail(entry), columns.detail);
|
|
771
|
+
chunks.push(chunk(detail, palette.weak));
|
|
772
|
+
if (columns.hasKey) {
|
|
773
|
+
chunks.push(chunk(" ".repeat(Math.max(0, columns.detail - displayWidth(detail)) + PALETTE_GAP)));
|
|
774
|
+
const key = fit(entry.key ?? "", columns.key);
|
|
775
|
+
chunks.push(chunk(" ".repeat(Math.max(0, columns.key - displayWidth(key))), undefined));
|
|
776
|
+
chunks.push(chunk(key, palette.text));
|
|
777
|
+
}
|
|
778
|
+
// Keep every entry the same width, so the key column stays at the right edge.
|
|
779
|
+
const drawn = chunks.reduce((sum, part) => sum + displayWidth(part.text), 0);
|
|
780
|
+
if (drawn < width) chunks.push(chunk(" ".repeat(width - drawn)));
|
|
781
|
+
chunks.push(chunk("\n"));
|
|
782
|
+
return chunks;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
/** The width inside an overlay's frame, its one-cell padding on each side taken. */
|
|
786
|
+
function overlayTextWidth(state: TuiState): number {
|
|
787
|
+
return Math.max(1, (overlayBox(state)?.width ?? OVERLAY_WIDTH) - 4);
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
/** An entry's name cut into runs, each wholly matched or wholly not. */
|
|
791
|
+
function nameRuns(
|
|
792
|
+
name: string,
|
|
793
|
+
marked: ReadonlySet<number>,
|
|
794
|
+
): { readonly text: string; readonly marked: boolean }[] {
|
|
795
|
+
const runs: { text: string; marked: boolean }[] = [];
|
|
796
|
+
graphemes(name).forEach((unit, place) => {
|
|
797
|
+
const on = marked.has(place);
|
|
798
|
+
const last = runs[runs.length - 1];
|
|
799
|
+
if (last !== undefined && last.marked === on) last.text += unit;
|
|
800
|
+
else runs.push({ text: unit, marked: on });
|
|
801
|
+
});
|
|
802
|
+
return runs;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
/** The palette or the note input, drawn in the box; undefined when neither is open. */
|
|
806
|
+
function inputContent(state: TuiState, palette: TuiPalette): StyledText | undefined {
|
|
807
|
+
const input = state.input;
|
|
808
|
+
if (input === undefined || input.kind === "confirm" || input.kind === "setting-confirm") return undefined;
|
|
809
|
+
const bar = "▏";
|
|
810
|
+
if (input.kind === "setting") {
|
|
811
|
+
const { setting, field } = input;
|
|
812
|
+
const chunks: TextChunk[] = [
|
|
813
|
+
chunk(`${sanitize(setting.name)}${setting.scope === "global" ? "" : ` (${sanitize(setting.scope)})`}\n`, palette.accent, TextAttributes.BOLD),
|
|
814
|
+
];
|
|
815
|
+
if (setting.description !== undefined) chunks.push(chunk(`${sanitize(setting.description)}\n`, palette.weak));
|
|
816
|
+
chunks.push(chunk(`value: ${settingText(setting.value)}\n`, palette.text));
|
|
817
|
+
chunks.push(chunk(`default: ${settingText(setting.default)}\n`, palette.text));
|
|
818
|
+
if (field === undefined) {
|
|
819
|
+
chunks.push(chunk("read-only · esc closes", palette.weak));
|
|
820
|
+
} else if (field.kind === "pick") {
|
|
821
|
+
field.options.forEach((option, at) => {
|
|
822
|
+
chunks.push(chunk(at === input.cursor ? "❯ " : " ", palette.accent));
|
|
823
|
+
chunks.push(chunk(option.label, at === input.cursor ? palette.accent : palette.text));
|
|
824
|
+
chunks.push(chunk(at === field.current ? " current\n" : "\n", palette.weak));
|
|
825
|
+
});
|
|
826
|
+
chunks.push(chunk("j/k or arrows move · enter picks · esc cancels", palette.weak));
|
|
827
|
+
} else {
|
|
828
|
+
chunks.push(chunk(`${input.text}${bar}\n`, palette.text));
|
|
829
|
+
chunks.push(chunk("enter sets · esc cancels", palette.weak));
|
|
830
|
+
}
|
|
831
|
+
return styled(chunks);
|
|
832
|
+
}
|
|
833
|
+
if (input.kind === "note") {
|
|
834
|
+
const chunks: TextChunk[] = [
|
|
835
|
+
chunk(`${input.action} · note${input.required ? " (required)" : ""}\n`, palette.accent, TextAttributes.BOLD),
|
|
836
|
+
chunk(`${input.text}${bar}\n`, palette.text),
|
|
837
|
+
chunk("enter sends · shift-enter or ctrl-j adds a line · esc cancels", palette.weak),
|
|
838
|
+
];
|
|
839
|
+
return styled(chunks);
|
|
840
|
+
}
|
|
841
|
+
if (input.kind === "answer") {
|
|
842
|
+
const chunks: TextChunk[] = [
|
|
843
|
+
chunk(`${input.answer.prompt}\n`, palette.accent, TextAttributes.BOLD),
|
|
844
|
+
];
|
|
845
|
+
input.answer.choices.forEach((choice, at) => {
|
|
846
|
+
chunks.push(chunk(at === input.cursor ? "❯ " : " ", palette.accent));
|
|
847
|
+
chunks.push(chunk(choice, at === input.cursor ? palette.accent : palette.text));
|
|
848
|
+
chunks.push(chunk("\n"));
|
|
849
|
+
});
|
|
850
|
+
chunks.push(chunk("j/k or arrows move · enter answers · esc cancels", palette.weak));
|
|
851
|
+
return styled(chunks);
|
|
852
|
+
}
|
|
853
|
+
if (input.kind === "themes") {
|
|
854
|
+
const chunks: TextChunk[] = [chunk("theme\n", palette.accent)];
|
|
855
|
+
const names = state.themeNames;
|
|
856
|
+
const rows = Math.max(1, (overlayBox(state)?.height ?? 5) - 4 - 1);
|
|
857
|
+
const start = Math.max(0, Math.min(input.cursor - Math.floor(rows / 2), names.length - rows));
|
|
858
|
+
names.slice(start, start + rows).forEach((name, offset) => {
|
|
859
|
+
const at = start + offset;
|
|
860
|
+
chunks.push(chunk(at === input.cursor ? "❯ " : " ", palette.accent));
|
|
861
|
+
chunks.push(chunk(name, at === input.cursor ? palette.accent : palette.text));
|
|
862
|
+
chunks.push(chunk(name === state.themeCurrent ? " in use\n" : "\n", palette.weak));
|
|
863
|
+
});
|
|
864
|
+
return styled(chunks);
|
|
865
|
+
}
|
|
866
|
+
if (input.kind === "args") {
|
|
867
|
+
const field = input.fields[input.at];
|
|
868
|
+
const chunks: TextChunk[] = [
|
|
869
|
+
chunk(`${input.action} · ${field?.name ?? ""} (${input.at + 1} of ${input.fields.length})\n`, palette.accent, TextAttributes.BOLD),
|
|
870
|
+
];
|
|
871
|
+
if (field?.description !== undefined) chunks.push(chunk(`${field.description}\n`, palette.weak));
|
|
872
|
+
if (field?.kind === "pick") {
|
|
873
|
+
field.options.forEach((option, at) => {
|
|
874
|
+
chunks.push(chunk(at === input.cursor ? "❯ " : " ", palette.accent));
|
|
875
|
+
chunks.push(chunk(option.label, at === input.cursor ? palette.accent : palette.text));
|
|
876
|
+
chunks.push(chunk(at === field.current ? " current\n" : "\n", palette.weak));
|
|
877
|
+
});
|
|
878
|
+
chunks.push(chunk(
|
|
879
|
+
field.optional === true && input.cursor < 0
|
|
880
|
+
? "j/k or arrows move · enter leaves it out · esc cancels"
|
|
881
|
+
: "j/k or arrows move · enter picks · esc cancels",
|
|
882
|
+
palette.weak,
|
|
883
|
+
));
|
|
884
|
+
} else if (field !== undefined) {
|
|
885
|
+
chunks.push(chunk(`${input.text}${bar}\n`, palette.text));
|
|
886
|
+
chunks.push(chunk(`${allowedText(field)}\n`, input.error === undefined ? palette.weak : palette.accent));
|
|
887
|
+
chunks.push(chunk("enter sends · esc cancels", palette.weak));
|
|
888
|
+
}
|
|
889
|
+
return styled(chunks);
|
|
890
|
+
}
|
|
891
|
+
if (input.kind === "pages") {
|
|
892
|
+
const chunks: TextChunk[] = [chunk(`page: ${input.query}${bar}\n`, palette.accent)];
|
|
893
|
+
const pages = pageEntries(state);
|
|
894
|
+
if (pages.length === 0) chunks.push(chunk("no page matches", palette.weak));
|
|
895
|
+
// The box holds fewer lines than a long table of contents: keep the cursor in view.
|
|
896
|
+
const rows = Math.max(1, (overlayBox(state)?.height ?? 5) - 4 - 1);
|
|
897
|
+
const start = Math.max(
|
|
898
|
+
0,
|
|
899
|
+
Math.min(input.cursor - Math.floor(rows / 2), pages.length - rows),
|
|
900
|
+
);
|
|
901
|
+
pages.slice(start, start + rows).forEach((entry, offset) => {
|
|
902
|
+
const at = start + offset;
|
|
903
|
+
chunks.push(chunk(at === input.cursor ? "❯ " : " ", palette.accent));
|
|
904
|
+
chunks.push(chunk(`${entry.label}\n`, at === input.cursor ? palette.accent : palette.text));
|
|
905
|
+
});
|
|
906
|
+
return styled(chunks);
|
|
907
|
+
}
|
|
908
|
+
const chunks: TextChunk[] = [chunk(`: ${input.query}${bar}\n`, palette.accent), chunk("\n")];
|
|
909
|
+
const entries = paletteEntries(state);
|
|
910
|
+
if (entries.length === 0) {
|
|
911
|
+
chunks.push(chunk("nothing matches", palette.weak));
|
|
912
|
+
return styled(chunks);
|
|
913
|
+
}
|
|
914
|
+
const lines = paletteDisplayLines(entries);
|
|
915
|
+
const columns = paletteColumns(state, entries, overlayTextWidth(state));
|
|
916
|
+
// The input line and the blank line under it stay put; only the body scrolls.
|
|
917
|
+
const rows = Math.max(0, (overlayBox(state)?.height ?? 5) - 4 - 2);
|
|
918
|
+
const selected = lines.findIndex((line) => line.kind === "entry" && line.at === input.cursor);
|
|
919
|
+
const start =
|
|
920
|
+
selected < rows
|
|
921
|
+
? 0
|
|
922
|
+
: Math.max(0, Math.min(selected - Math.floor(rows / 2), lines.length - rows));
|
|
923
|
+
for (const line of lines.slice(start, start + rows)) {
|
|
924
|
+
if (line.kind === "blank") chunks.push(chunk("\n"));
|
|
925
|
+
else if (line.kind === "group") chunks.push(chunk(`${line.group}\n`, palette.weak));
|
|
926
|
+
else chunks.push(...paletteEntryLine(state, line, columns, overlayTextWidth(state), palette));
|
|
927
|
+
}
|
|
928
|
+
return styled(chunks);
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
function confirmContent(state: TuiState, palette: TuiPalette): StyledText | undefined {
|
|
932
|
+
const text = confirmText(state);
|
|
933
|
+
if (text === undefined) return undefined;
|
|
934
|
+
return styled([
|
|
935
|
+
chunk(`${text}\n`, palette.accent, TextAttributes.BOLD),
|
|
936
|
+
chunk("y confirms · any other key cancels", palette.weak),
|
|
937
|
+
]);
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
/** The widest an overlay gets. */
|
|
941
|
+
export const OVERLAY_WIDTH = 80;
|
|
942
|
+
|
|
943
|
+
/** Where one overlay box sits, border included. */
|
|
944
|
+
export interface OverlayBox {
|
|
945
|
+
readonly left: number;
|
|
946
|
+
readonly top: number;
|
|
947
|
+
readonly width: number;
|
|
948
|
+
readonly height: number;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
/**
|
|
952
|
+
* The box of the open overlay, or undefined. The width is fixed while it is
|
|
953
|
+
* open; the box is centred horizontally. The palette keeps its top at a third
|
|
954
|
+
* of the height so the input line stays put as the matches change; the others
|
|
955
|
+
* are centred vertically.
|
|
956
|
+
*/
|
|
957
|
+
export function overlayBox(state: TuiState): OverlayBox | undefined {
|
|
958
|
+
const kind = state.keys ? "keys" : state.input?.kind;
|
|
959
|
+
if (kind === undefined) return undefined;
|
|
960
|
+
const width = Math.max(10, Math.min(OVERLAY_WIDTH, state.width - 4));
|
|
961
|
+
const lines = kind === "keys" ? HELP_LINES : kind === "confirm" || kind === "setting-confirm" ? 2 : inputLines(state);
|
|
962
|
+
// Border (2) and a one-cell margin of background (2) around the text.
|
|
963
|
+
const wanted = lines + 4;
|
|
964
|
+
const left = Math.max(0, Math.floor((state.width - width) / 2));
|
|
965
|
+
if (kind === "palette" || kind === "pages" || kind === "themes") {
|
|
966
|
+
const top = Math.floor(state.height / 3);
|
|
967
|
+
return { left, top, width, height: Math.max(5, Math.min(wanted, state.height - top)) };
|
|
968
|
+
}
|
|
969
|
+
const height = Math.max(5, Math.min(wanted, state.height));
|
|
970
|
+
return { left, top: Math.max(0, Math.floor((state.height - height) / 2)), width, height };
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
/** The line count the box needs for the input it draws. */
|
|
974
|
+
function inputLines(state: TuiState): number {
|
|
975
|
+
const input = state.input;
|
|
976
|
+
if (input?.kind === "args") {
|
|
977
|
+
const field = input.fields[input.at];
|
|
978
|
+
const body = field?.kind === "pick" ? field.options.length + 1 : 3;
|
|
979
|
+
return body + 1 + (field?.description === undefined ? 0 : 1);
|
|
980
|
+
}
|
|
981
|
+
if (input?.kind === "setting") {
|
|
982
|
+
const { setting, field } = input;
|
|
983
|
+
const body = field?.kind === "pick" ? field.options.length + 1 : 2;
|
|
984
|
+
return 3 + (setting.description === undefined ? 0 : 1) + body;
|
|
985
|
+
}
|
|
986
|
+
if (input?.kind === "note") return input.text.split("\n").length + 2;
|
|
987
|
+
if (input?.kind === "palette") {
|
|
988
|
+
const entries = paletteEntries(state);
|
|
989
|
+
return entries.length === 0 ? 3 : 2 + paletteDisplayLines(entries).length;
|
|
990
|
+
}
|
|
991
|
+
if (input?.kind === "answer") return input.answer.choices.length + 2;
|
|
992
|
+
if (input?.kind === "themes") return Math.max(1, state.themeNames.length) + 1;
|
|
993
|
+
if (input?.kind === "pages") return Math.max(1, pageEntries(state).length) + 1;
|
|
994
|
+
return 0;
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
/** Everything one state draws, as styled text, before any terminal sees it. */
|
|
998
|
+
export interface TuiDrawing {
|
|
999
|
+
readonly header: StyledText;
|
|
1000
|
+
readonly rule: StyledText;
|
|
1001
|
+
readonly divider: StyledText;
|
|
1002
|
+
readonly list: StyledText;
|
|
1003
|
+
readonly right: StyledText;
|
|
1004
|
+
readonly footer: StyledText;
|
|
1005
|
+
/** The `?` key list, the palette, the note or the confirmation, drawn in a filled box. */
|
|
1006
|
+
readonly overlay: StyledText | undefined;
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
/** The footer: keys in the text colour, their hints weak, separated by a dot. */
|
|
1010
|
+
function footerContent(state: TuiState, palette: TuiPalette): StyledText {
|
|
1011
|
+
const chunks: TextChunk[] = [chunk(" ")];
|
|
1012
|
+
footerSegments(state).forEach((segment, at) => {
|
|
1013
|
+
if (at > 0) chunks.push(chunk(" · ", palette.weak));
|
|
1014
|
+
if (segment.key !== undefined) chunks.push(chunk(`${segment.key} `, palette.text));
|
|
1015
|
+
chunks.push(chunk(segment.hint, palette.weak));
|
|
1016
|
+
});
|
|
1017
|
+
return styled(truncateChunks(chunks, Math.max(1, state.width - 2)));
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
/** The styled text of every area for one state; the view only places it. */
|
|
1021
|
+
export function drawState(
|
|
1022
|
+
state: TuiState,
|
|
1023
|
+
themeName: string | ThemeSelection = "auto",
|
|
1024
|
+
): TuiDrawing {
|
|
1025
|
+
const palette = paletteFor(state.theme, themeName);
|
|
1026
|
+
const tab = activeTab(state);
|
|
1027
|
+
const rowError = tab?.list.rows[tab.list.cursor]?.error;
|
|
1028
|
+
const notice = noticeText(state);
|
|
1029
|
+
const status = notice ?? statusText(state) ?? rowError;
|
|
1030
|
+
const width = Math.max(1, state.width - 3);
|
|
1031
|
+
return {
|
|
1032
|
+
header: headerContent(state, palette),
|
|
1033
|
+
rule: ruleContent(state, palette),
|
|
1034
|
+
divider: dividerContent(state, palette),
|
|
1035
|
+
footer:
|
|
1036
|
+
status === undefined
|
|
1037
|
+
? footerContent(state, palette)
|
|
1038
|
+
: styled([chunk(` ${fit(status, width)}`, palette.error)]),
|
|
1039
|
+
list: dimmed(
|
|
1040
|
+
listContent(state, activeTab(state), palette),
|
|
1041
|
+
state.connection === "unreachable",
|
|
1042
|
+
palette,
|
|
1043
|
+
),
|
|
1044
|
+
right: objectContent(state, palette),
|
|
1045
|
+
overlay: state.keys
|
|
1046
|
+
? keyContent(state, palette)
|
|
1047
|
+
: (inputContent(state, palette) ?? confirmContent(state, palette)),
|
|
1048
|
+
};
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
/** What the view exposes to the app. */
|
|
1052
|
+
export interface TuiView {
|
|
1053
|
+
render(state: TuiState): void;
|
|
1054
|
+
destroy(): void;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
/** Builds the render tree once and updates it on every state. */
|
|
1058
|
+
export function createTuiView(
|
|
1059
|
+
ctx: CliRenderer,
|
|
1060
|
+
theme: string | ThemeSelection | (() => ThemeSelection) = "auto",
|
|
1061
|
+
): TuiView {
|
|
1062
|
+
const root = new BoxRenderable(ctx, {
|
|
1063
|
+
id: "operad-tui",
|
|
1064
|
+
width: "100%",
|
|
1065
|
+
height: "100%",
|
|
1066
|
+
flexDirection: "column",
|
|
1067
|
+
});
|
|
1068
|
+
ctx.root.add(root);
|
|
1069
|
+
|
|
1070
|
+
const line = (id: string): TextRenderable =>
|
|
1071
|
+
new TextRenderable(ctx, {
|
|
1072
|
+
id,
|
|
1073
|
+
height: 1,
|
|
1074
|
+
flexShrink: 0,
|
|
1075
|
+
wrapMode: "none",
|
|
1076
|
+
truncate: true,
|
|
1077
|
+
});
|
|
1078
|
+
const header = line("operad-header");
|
|
1079
|
+
const headerRule = line("operad-header-rule");
|
|
1080
|
+
const footerRule = line("operad-footer-rule");
|
|
1081
|
+
const footer = line("operad-footer");
|
|
1082
|
+
const body = new BoxRenderable(ctx, {
|
|
1083
|
+
id: "operad-body",
|
|
1084
|
+
width: "100%",
|
|
1085
|
+
flexGrow: 1,
|
|
1086
|
+
flexDirection: "row",
|
|
1087
|
+
});
|
|
1088
|
+
const listPane = new BoxRenderable(ctx, {
|
|
1089
|
+
id: "operad-list-pane",
|
|
1090
|
+
height: "100%",
|
|
1091
|
+
width: "100%",
|
|
1092
|
+
flexShrink: 0,
|
|
1093
|
+
paddingLeft: LIST_X,
|
|
1094
|
+
paddingRight: 1,
|
|
1095
|
+
});
|
|
1096
|
+
const list = new TextRenderable(ctx, {
|
|
1097
|
+
id: "operad-list",
|
|
1098
|
+
width: "100%",
|
|
1099
|
+
height: "100%",
|
|
1100
|
+
wrapMode: "none",
|
|
1101
|
+
truncate: true,
|
|
1102
|
+
});
|
|
1103
|
+
const divider = new TextRenderable(ctx, {
|
|
1104
|
+
id: "operad-divider",
|
|
1105
|
+
width: 1,
|
|
1106
|
+
height: "100%",
|
|
1107
|
+
flexShrink: 0,
|
|
1108
|
+
wrapMode: "none",
|
|
1109
|
+
});
|
|
1110
|
+
const rightPane = new BoxRenderable(ctx, {
|
|
1111
|
+
id: "operad-right-pane",
|
|
1112
|
+
height: "100%",
|
|
1113
|
+
flexGrow: 1,
|
|
1114
|
+
paddingLeft: 1,
|
|
1115
|
+
});
|
|
1116
|
+
const right = new TextRenderable(ctx, {
|
|
1117
|
+
id: "operad-right",
|
|
1118
|
+
width: "100%",
|
|
1119
|
+
height: "100%",
|
|
1120
|
+
// The section is wrapped by `sectionWidth` before it reaches this
|
|
1121
|
+
// renderable, so a wrapped row must stay one row here.
|
|
1122
|
+
wrapMode: "none",
|
|
1123
|
+
truncate: true,
|
|
1124
|
+
});
|
|
1125
|
+
// The one closed box: the key list floats over the body.
|
|
1126
|
+
const overlayPane = new BoxRenderable(ctx, {
|
|
1127
|
+
id: "operad-keys",
|
|
1128
|
+
position: "absolute",
|
|
1129
|
+
left: 2,
|
|
1130
|
+
top: 2,
|
|
1131
|
+
width: 60,
|
|
1132
|
+
height: HELP_LINES + 4,
|
|
1133
|
+
border: true,
|
|
1134
|
+
borderStyle: "rounded",
|
|
1135
|
+
borderColor: toRgba(TUI_PALETTE.dark.rule),
|
|
1136
|
+
paddingX: 1,
|
|
1137
|
+
paddingY: 1,
|
|
1138
|
+
visible: false,
|
|
1139
|
+
shouldFill: true,
|
|
1140
|
+
});
|
|
1141
|
+
const overlay = new TextRenderable(ctx, {
|
|
1142
|
+
id: "operad-keys-text",
|
|
1143
|
+
width: "100%",
|
|
1144
|
+
height: "100%",
|
|
1145
|
+
wrapMode: "none",
|
|
1146
|
+
truncate: true,
|
|
1147
|
+
});
|
|
1148
|
+
|
|
1149
|
+
listPane.add(list);
|
|
1150
|
+
rightPane.add(right);
|
|
1151
|
+
overlayPane.add(overlay);
|
|
1152
|
+
body.add(listPane);
|
|
1153
|
+
body.add(divider);
|
|
1154
|
+
body.add(rightPane);
|
|
1155
|
+
root.add(header);
|
|
1156
|
+
root.add(headerRule);
|
|
1157
|
+
root.add(body);
|
|
1158
|
+
root.add(footerRule);
|
|
1159
|
+
root.add(footer);
|
|
1160
|
+
root.add(overlayPane);
|
|
1161
|
+
|
|
1162
|
+
return {
|
|
1163
|
+
render(state: TuiState): void {
|
|
1164
|
+
const themeName = typeof theme === "function" ? theme() : theme;
|
|
1165
|
+
const palette = paletteFor(state.theme, themeName);
|
|
1166
|
+
const wide = twoPane(state);
|
|
1167
|
+
const drawing = drawState(state, themeName);
|
|
1168
|
+
|
|
1169
|
+
header.content = drawing.header;
|
|
1170
|
+
headerRule.content = drawing.rule;
|
|
1171
|
+
footerRule.content = drawing.rule;
|
|
1172
|
+
footer.content = drawing.footer;
|
|
1173
|
+
|
|
1174
|
+
listPane.width = wide ? dividerX(state) : "100%";
|
|
1175
|
+
// On a narrow screen the open object takes the place of the list.
|
|
1176
|
+
const showObject = state.object !== undefined;
|
|
1177
|
+
listPane.visible = wide || !showObject;
|
|
1178
|
+
divider.visible = wide;
|
|
1179
|
+
rightPane.visible = wide || showObject;
|
|
1180
|
+
rightPane.paddingLeft = wide ? rightX(state) - dividerX(state) - 1 : LIST_X;
|
|
1181
|
+
|
|
1182
|
+
list.content = drawing.list;
|
|
1183
|
+
divider.content = drawing.divider;
|
|
1184
|
+
right.content = drawing.right;
|
|
1185
|
+
|
|
1186
|
+
overlayPane.visible = drawing.overlay !== undefined;
|
|
1187
|
+
overlayPane.borderColor = toRgba(palette.rule);
|
|
1188
|
+
overlayPane.backgroundColor = toRgba(palette.background);
|
|
1189
|
+
const place = overlayBox(state);
|
|
1190
|
+
if (place !== undefined) {
|
|
1191
|
+
overlayPane.left = place.left;
|
|
1192
|
+
overlayPane.top = place.top;
|
|
1193
|
+
overlayPane.width = place.width;
|
|
1194
|
+
overlayPane.height = place.height;
|
|
1195
|
+
}
|
|
1196
|
+
if (drawing.overlay !== undefined) overlay.content = drawing.overlay;
|
|
1197
|
+
|
|
1198
|
+
root.requestRender();
|
|
1199
|
+
},
|
|
1200
|
+
destroy(): void {
|
|
1201
|
+
root.destroyRecursively();
|
|
1202
|
+
},
|
|
1203
|
+
};
|
|
1204
|
+
}
|