herdr-gentle-shell 1.8.0 → 1.8.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/DESIGN.md +299 -96
- package/README.md +83 -23
- package/docs/theme-sync.md +634 -181
- package/extensions/gentle-herdr-state.ts +145 -51
- package/extensions/herdr-theme-sync.ts +184 -159
- package/lib/customize-panel.js +602 -308
- package/lib/herdr-theme-apply.js +361 -0
- package/lib/herdr-theme-config.js +1133 -0
- package/lib/theme-projection.js +48 -9
- package/package.json +1 -1
package/lib/customize-panel.js
CHANGED
|
@@ -1,37 +1,39 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
// The `/herdr-gentle:customize` floating panel,
|
|
4
|
-
// (odd/tasks/
|
|
5
|
-
// Shell's own customize card (odd/tasks/customize-parity-done-idle.md T1, S1).
|
|
3
|
+
// The `/herdr-gentle:customize` floating panel, rebuilt after Gentle Shell's own
|
|
4
|
+
// customize card (odd/tasks/theme-sync-fix.md T4; S1/S2/S5/S6/S7).
|
|
6
5
|
//
|
|
7
|
-
// One left `CATEGORIES` list
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
6
|
+
// One left `CATEGORIES` list and one right pane headed `<Category> · n/m`. Each
|
|
7
|
+
// setting is ONE line with its options inline — `●` marks the stored option, `›`
|
|
8
|
+
// the cursor option while it is elsewhere, `○` the rest — so moving the cursor
|
|
9
|
+
// never applies anything and only Enter confirms (upstream's `applyOnMove:
|
|
10
|
+
// false` for every setting here). When a line's options do not fit, the panel
|
|
11
|
+
// scrolls sideways: a window that always contains the cursor option, muted `‹`
|
|
12
|
+
// and `›` markers where options hide, and an `n/m` counter; if not even one
|
|
13
|
+
// option fits, upstream's compact `‹ value ›` form takes over.
|
|
14
|
+
//
|
|
15
|
+
// Below the panes sits the Shell's Preview block: a headline naming the
|
|
16
|
+
// highlighted option and its preview title, then the sample lines, all painted
|
|
17
|
+
// with the host theme (the theme swatch keeps its own raw SGR, because it must
|
|
18
|
+
// show THAT theme's colours, not the active one).
|
|
14
19
|
//
|
|
15
20
|
// The host component contract (pi-coding-agent `custom`): the factory receives
|
|
16
21
|
// (hostTui, theme, keybindings, done) and returns
|
|
17
22
|
// { render(width), handleInput(data), handleMouse(event), invalidate() }.
|
|
18
23
|
// Selection keys and pointer hits only move local state and ask the host to
|
|
19
|
-
// repaint; Esc finishes with done(null) and Enter (or
|
|
20
|
-
//
|
|
21
|
-
//
|
|
24
|
+
// repaint; Esc finishes with done(null), and Enter (or an option click) awaits
|
|
25
|
+
// the injected `apply({ categoryId, settingId, optionId })`. The panel then
|
|
26
|
+
// swaps in the model that apply re-read, keeping the cursor by ids, and stays
|
|
27
|
+
// open unless apply answered `close: true` (the Moshi reload must not happen
|
|
28
|
+
// behind a mounted card). This module never writes, notifies, or reloads.
|
|
22
29
|
//
|
|
23
|
-
// The
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// The stored theme value is spelled by lib/theme-projection.js: the label a name
|
|
32
|
-
// reads as and the "no theme" spelling live there, so the panel and the store
|
|
33
|
-
// can never disagree about what `null` means.
|
|
34
|
-
const { normalizeThemeName, themeChoiceLabel } = require('./theme-projection.js');
|
|
30
|
+
// The model is categories -> settings -> options. Option ids are structural
|
|
31
|
+
// (`on`, `none`, `theme:<name>`) and never derived from a label, so an installed
|
|
32
|
+
// theme literally named `None` or `Off` stays selectable and pinnable.
|
|
33
|
+
|
|
34
|
+
// The stored theme value is normalised by lib/theme-projection.js, so the panel
|
|
35
|
+
// and the store can never disagree about what "no theme" means.
|
|
36
|
+
const { normalizeThemeName } = require('./theme-projection.js');
|
|
35
37
|
|
|
36
38
|
const ROLE = Object.freeze({
|
|
37
39
|
key: "accent",
|
|
@@ -44,8 +46,7 @@ const ROLE = Object.freeze({
|
|
|
44
46
|
error: "error",
|
|
45
47
|
});
|
|
46
48
|
|
|
47
|
-
// The palette
|
|
48
|
-
// module): theme ROLE NAMES only, so a missing, partial or throwing theme
|
|
49
|
+
// The palette: theme ROLE NAMES only, so a missing, partial or throwing theme
|
|
49
50
|
// degrades to plain text instead of breaking a render. Keys and titles are
|
|
50
51
|
// emphasized through the theme's own `bold`, which keeps them distinguishable
|
|
51
52
|
// in a monochrome terminal.
|
|
@@ -163,155 +164,110 @@ const CUSTOMIZE_TITLE = "Customize · Herdr Gentle Shell";
|
|
|
163
164
|
const CUSTOMIZE_CARD_PADDING = 4;
|
|
164
165
|
const CUSTOMIZE_NARROW_WIDTH = 60;
|
|
165
166
|
const CUSTOMIZE_MAX_HEIGHT = 24;
|
|
166
|
-
// The Shell's
|
|
167
|
-
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
//
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
//
|
|
176
|
-
//
|
|
177
|
-
|
|
178
|
-
|
|
167
|
+
// The Shell's option vocabulary: `●` is the stored option, `›` the cursor while
|
|
168
|
+
// it is not the stored one, `○` everything else.
|
|
169
|
+
const CUSTOMIZE_MARK_CURRENT = "●";
|
|
170
|
+
const CUSTOMIZE_MARK_CURSOR = "›";
|
|
171
|
+
const CUSTOMIZE_MARK_OTHER = "○";
|
|
172
|
+
const CUSTOMIZE_OPTION_GAP = " ";
|
|
173
|
+
// The pointer hint lives in the footer exactly like upstream's `Click · …`.
|
|
174
|
+
const CUSTOMIZE_CLICK_PREFIX = "Click · ";
|
|
175
|
+
|
|
176
|
+
// The three settings this package owns, with the upstream order of their two
|
|
177
|
+
// options and the static preview each option carries. `id` is the apply target
|
|
178
|
+
// the extension knows; it is structural, never the label.
|
|
179
|
+
const CUSTOMIZE_SIDEBAR_SAMPLE_ON = "● project gentle worker";
|
|
180
|
+
const CUSTOMIZE_SIDEBAR_SAMPLE_OFF = "native Herdr rows; no managed block";
|
|
181
|
+
const CUSTOMIZE_MOSHI_SAMPLE_ON = "ask finished";
|
|
182
|
+
const CUSTOMIZE_MOSHI_SAMPLE_OFF = "silent; no Moshi notification";
|
|
183
|
+
const CUSTOMIZE_SYNC_SAMPLE_ON = "Herdr follows the theme active in Pi";
|
|
184
|
+
const CUSTOMIZE_SYNC_SAMPLE_OFF = "Herdr keeps its last palette";
|
|
185
|
+
const CUSTOMIZE_THEME_NONE_SAMPLE = "no theme pinned; Herdr keeps its last palette";
|
|
186
|
+
|
|
187
|
+
const CUSTOMIZE_TOGGLES = Object.freeze({
|
|
188
|
+
sidebar: {
|
|
179
189
|
id: "sidebar",
|
|
180
190
|
setting: "Sidebar agent rows",
|
|
181
|
-
|
|
191
|
+
order: ["on", "off"],
|
|
192
|
+
// S5: the sample shows what the managed rows add, from the README's own
|
|
193
|
+
// description of the heading cell and the role words.
|
|
194
|
+
preview: (which) => ({
|
|
195
|
+
title: "static sidebar sample",
|
|
196
|
+
sample: which === "on" ? CUSTOMIZE_SIDEBAR_SAMPLE_ON : CUSTOMIZE_SIDEBAR_SAMPLE_OFF,
|
|
197
|
+
}),
|
|
198
|
+
unknownNote: "state unknown; Enter turns the rows on",
|
|
182
199
|
},
|
|
183
|
-
{
|
|
200
|
+
moshi: {
|
|
184
201
|
id: "moshi",
|
|
185
202
|
setting: "Notifications",
|
|
186
|
-
|
|
203
|
+
order: ["on", "off"],
|
|
204
|
+
preview: (which) => ({
|
|
205
|
+
title: "static notification sample",
|
|
206
|
+
sample: which === "on" ? CUSTOMIZE_MOSHI_SAMPLE_ON : CUSTOMIZE_MOSHI_SAMPLE_OFF,
|
|
207
|
+
}),
|
|
187
208
|
},
|
|
188
|
-
{
|
|
209
|
+
"theme-sync": {
|
|
189
210
|
id: "theme-sync",
|
|
190
211
|
setting: "Theme sync",
|
|
191
|
-
|
|
212
|
+
order: ["off", "on"],
|
|
213
|
+
preview: (which) => ({
|
|
214
|
+
title: "static sync sample",
|
|
215
|
+
sample: which === "on" ? CUSTOMIZE_SYNC_SAMPLE_ON : CUSTOMIZE_SYNC_SAMPLE_OFF,
|
|
216
|
+
}),
|
|
192
217
|
// An unreadable store is repairable with one key press instead of blocking
|
|
193
|
-
// the
|
|
194
|
-
// managed rows the other switches repair.
|
|
218
|
+
// the setting, so the note says what the action does.
|
|
195
219
|
unknownNote: "state unknown; Enter turns the sync on",
|
|
196
220
|
},
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
// The theme value is deliberately NOT a toggle: its one row opens the host's
|
|
200
|
-
// theme list, so it carries its own row id (`select`) and the panel never paints
|
|
201
|
-
// it as On/Off. With the sync on the active Pi theme owns Herdr's palette (S4),
|
|
202
|
-
// so the row is painted dim, explains itself and is refused by the extension.
|
|
203
|
-
const CUSTOMIZE_THEME_ROW_ID = "select";
|
|
204
|
-
const CUSTOMIZE_THEME_ROW_LABEL = "Select…";
|
|
205
|
-
const CUSTOMIZE_THEME_ROW_DESCRIPTION =
|
|
206
|
-
"Applies one Gentle Shell theme to Herdr; available only while Theme sync is off.";
|
|
207
|
-
const CUSTOMIZE_THEME_DISABLED_NOTE = "Turn Theme sync off to pick a specific theme.";
|
|
208
|
-
|
|
209
|
-
// Three categories. `Herdr Sidebar` owns the managed agent rows the plugin
|
|
210
|
-
// publishes and nothing else: the Moshi notification channel lives only under
|
|
211
|
-
// `Moshi notifications`, so the sidebar switch can never toggle it. `Herdr
|
|
212
|
-
// Theme` follows Moshi for the same reason: it owns the palette Herdr draws,
|
|
213
|
-
// both the sync toggle and the pinned value.
|
|
214
|
-
const CUSTOMIZE_CATEGORIES = [
|
|
215
|
-
{
|
|
216
|
-
id: "sidebar",
|
|
217
|
-
title: "Herdr Sidebar",
|
|
218
|
-
description: "The managed agent rows this plugin hands to the Herdr sidebar.",
|
|
219
|
-
switches: ["sidebar"],
|
|
220
|
-
},
|
|
221
|
-
{
|
|
222
|
-
id: "moshi",
|
|
223
|
-
title: "Moshi notifications",
|
|
224
|
-
description: "The Moshi notification channel this plugin owns.",
|
|
225
|
-
switches: ["moshi"],
|
|
226
|
-
},
|
|
227
|
-
{
|
|
228
|
-
id: "theme",
|
|
229
|
-
title: "Herdr Theme",
|
|
230
|
-
description: "The palette Herdr draws, either following Pi or pinned to one theme.",
|
|
231
|
-
switches: ["theme-sync", "theme"],
|
|
232
|
-
},
|
|
233
|
-
];
|
|
234
|
-
|
|
235
|
-
// One row per switch: it paints the stored value and carries the value Enter
|
|
236
|
-
// applies, so a single key press is the whole toggle. `Unknown` keeps the row
|
|
237
|
-
// actionable instead of blocking the repair, so an inconclusive check can
|
|
238
|
-
// always be re-run from here.
|
|
239
|
-
function toggleRow(definition, active) {
|
|
240
|
-
const current = active === "on" || active === "off" ? active : null;
|
|
241
|
-
return {
|
|
242
|
-
id: current === "on" ? "off" : "on",
|
|
243
|
-
switchId: definition.id,
|
|
244
|
-
setting: definition.setting,
|
|
245
|
-
description: definition.description,
|
|
246
|
-
current,
|
|
247
|
-
currentLabel: current === "on" ? "On" : current === "off" ? "Off" : "Unknown",
|
|
248
|
-
otherLabel: current === "on" ? "Off" : "On",
|
|
249
|
-
note: current === null
|
|
250
|
-
? (definition.unknownNote ?? "state unknown; Enter re-runs the managed rows")
|
|
251
|
-
: undefined,
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// The theme value row: the assigned name (or the inert `Off` label) on the
|
|
256
|
-
// stored pill and the list as the other one. `disabled` is exactly "the stored
|
|
257
|
-
// sync is on", and an unreadable store names neither a value nor a guess.
|
|
258
|
-
function themeRow(themeState) {
|
|
259
|
-
const readable = themeState.ok !== false;
|
|
260
|
-
const syncOn = readable && themeState.sync === true;
|
|
261
|
-
const assigned = readable ? normalizeThemeName(themeState.theme) : null;
|
|
262
|
-
return {
|
|
263
|
-
id: CUSTOMIZE_THEME_ROW_ID,
|
|
264
|
-
switchId: "theme",
|
|
265
|
-
setting: "Gentle Shell theme",
|
|
266
|
-
description: CUSTOMIZE_THEME_ROW_DESCRIPTION,
|
|
267
|
-
current: assigned,
|
|
268
|
-
currentLabel: themeChoiceLabel(assigned),
|
|
269
|
-
otherLabel: CUSTOMIZE_THEME_ROW_LABEL,
|
|
270
|
-
disabled: syncOn,
|
|
271
|
-
note: syncOn ? CUSTOMIZE_THEME_DISABLED_NOTE : undefined,
|
|
272
|
-
};
|
|
273
|
-
}
|
|
221
|
+
});
|
|
274
222
|
|
|
275
|
-
// The
|
|
276
|
-
// `
|
|
277
|
-
//
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
: { ok: false, sync: false, theme: null };
|
|
286
|
-
const themeSync = themeState.ok === false ? null : themeState.sync === true ? "on" : "off";
|
|
287
|
-
const current = {
|
|
288
|
-
sidebar: stored(sidebar),
|
|
289
|
-
moshi: stored(moshi) === "on" ? "on" : "off",
|
|
290
|
-
"theme-sync": themeSync,
|
|
291
|
-
};
|
|
292
|
-
const rowFor = (switchId) => (switchId === "theme"
|
|
293
|
-
? themeRow(themeState)
|
|
294
|
-
: toggleRow(CUSTOMIZE_SWITCHES.find((entry) => entry.id === switchId), current[switchId]));
|
|
295
|
-
return CUSTOMIZE_CATEGORIES.map((category) => ({
|
|
296
|
-
id: category.id,
|
|
297
|
-
title: category.title,
|
|
298
|
-
description: category.description,
|
|
299
|
-
rows: category.switches.map(rowFor),
|
|
300
|
-
}));
|
|
301
|
-
}
|
|
223
|
+
// The theme list's inert option. `none` is its ID and `None` its label: an
|
|
224
|
+
// installed theme called `None` keeps the ID `theme:None`, so the two can never
|
|
225
|
+
// collide and both stay selectable.
|
|
226
|
+
const CUSTOMIZE_THEME_SETTING_ID = "theme";
|
|
227
|
+
const CUSTOMIZE_THEME_NONE_ID = "none";
|
|
228
|
+
const CUSTOMIZE_THEME_NONE_LABEL = "None";
|
|
229
|
+
const CUSTOMIZE_THEME_OPTION_PREFIX = "theme:";
|
|
230
|
+
const CUSTOMIZE_THEME_UNAVAILABLE_NOTE = "Themes unavailable; use Pi /settings";
|
|
231
|
+
const CUSTOMIZE_THEME_DISABLED_NOTE = "Turn Theme sync off to pick a specific theme.";
|
|
232
|
+
const CUSTOMIZE_THEME_UNKNOWN_NOTE = "state unknown; Enter pins a theme";
|
|
302
233
|
|
|
303
234
|
// The key legend is ONE terminal row: the `key` spelling paints as the key
|
|
304
235
|
// role and the rest as its description. `short` is the compact form, and
|
|
305
236
|
// `priority` is the drop order, so the close key outlives every other hint.
|
|
306
237
|
// There is no `p profiles` entry: this plugin owns no profiles concept, and a
|
|
307
|
-
// dead key in the footer would be a lie.
|
|
308
|
-
//
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
238
|
+
// dead key in the footer would be a lie.
|
|
239
|
+
//
|
|
240
|
+
// Three variants, chosen like upstream's `footerHint` (lib/visual-customize-view.ts
|
|
241
|
+
// in gentle-shell): the legend names what the keys do RIGHT NOW. A narrow card
|
|
242
|
+
// that only lists categories opens them with `→`; a focused option row reads
|
|
243
|
+
// `←/→ choose` (the arrows move the cursor and only Enter applies); the
|
|
244
|
+
// categories pane keeps the pane-switching legend.
|
|
245
|
+
const CUSTOMIZE_FOOTER_VARIANTS = {
|
|
246
|
+
categories: [
|
|
247
|
+
{ key: "↑/↓", text: "↑/↓ categories", short: "↑/↓ move", priority: 70 },
|
|
248
|
+
{ key: "→", text: "→ open", short: "→ open", priority: 80 },
|
|
249
|
+
{ key: "Esc", text: "Esc close", short: "Esc close", priority: 100 },
|
|
250
|
+
],
|
|
251
|
+
choose: [
|
|
252
|
+
{ key: "←/→", text: "←/→ choose", short: "←/→ choose", priority: 70 },
|
|
253
|
+
{ key: "Enter", text: "Enter apply", short: "Enter apply", priority: 90 },
|
|
254
|
+
{ key: "↑/↓", text: "↑/↓ settings", short: "↑/↓ move", priority: 60 },
|
|
255
|
+
{ key: "Tab", text: "Tab panes", short: "Tab panes", priority: 50 },
|
|
256
|
+
{ key: "Esc", text: "Esc close", short: "Esc close", priority: 100 },
|
|
257
|
+
],
|
|
258
|
+
panes: [
|
|
259
|
+
{ key: "←/→", text: "←/→ or Tab panes", short: "←/→ panes", priority: 60 },
|
|
260
|
+
{ key: "↑/↓", text: "↑/↓ move", short: "↑/↓ move", priority: 70 },
|
|
261
|
+
{ key: "Enter", text: "Enter apply", short: "Enter apply", priority: 80 },
|
|
262
|
+
{ key: "Esc", text: "Esc close", short: "Esc close", priority: 100 },
|
|
263
|
+
],
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
function customizeFooterVariant(navOnly, pane, focusedSetting) {
|
|
267
|
+
if (navOnly) return CUSTOMIZE_FOOTER_VARIANTS.categories;
|
|
268
|
+
const onOptions = pane === "controls" && focusedSetting && Array.isArray(focusedSetting.options) && focusedSetting.options.length > 0;
|
|
269
|
+
return onOptions ? CUSTOMIZE_FOOTER_VARIANTS.choose : CUSTOMIZE_FOOTER_VARIANTS.panes;
|
|
270
|
+
}
|
|
315
271
|
|
|
316
272
|
function customizeStripAnsi(value) {
|
|
317
273
|
return String(value).replace(/\x1b\[[0-9;]*m/g, "").replace(/\x1b\]8;;.*?\x07/g, "");
|
|
@@ -373,28 +329,32 @@ function customizeCompose(helpers, theme, segments, size) {
|
|
|
373
329
|
return painted + " ".repeat(Math.max(0, size - customizeMeasure(helpers, clipped)));
|
|
374
330
|
}
|
|
375
331
|
|
|
376
|
-
// An ALREADY painted row
|
|
377
|
-
//
|
|
332
|
+
// An ALREADY painted row: pad it to `size` without repainting, measuring
|
|
333
|
+
// visible columns.
|
|
378
334
|
function customizePad(helpers, text, size) {
|
|
379
335
|
return text + " ".repeat(Math.max(0, size - customizeMeasure(helpers, text)));
|
|
380
336
|
}
|
|
381
337
|
|
|
382
338
|
// The legend stays on ONE row: the compaction (full tokens, then short tokens,
|
|
383
339
|
// then dropping the lowest-priority entries; display order never changes) and
|
|
384
|
-
// the key/description painting live in the palette above.
|
|
385
|
-
//
|
|
340
|
+
// the key/description painting live in the palette above. The `Click · ` prefix
|
|
341
|
+
// is part of the row, exactly like upstream's footer, and costs width before
|
|
342
|
+
// any entry is dropped. A legend still wider than the card is truncated
|
|
343
|
+
// UNPAINTED so a cut never lands inside an escape.
|
|
386
344
|
function customizeFooter(helpers, theme, entries, size) {
|
|
387
345
|
const measure = (text) => customizeMeasure(helpers, text);
|
|
388
|
-
const
|
|
346
|
+
const prefixWidth = measure(CUSTOMIZE_CLICK_PREFIX);
|
|
347
|
+
const legendWidth = Math.max(0, size - prefixWidth);
|
|
348
|
+
const plain = `${CUSTOMIZE_CLICK_PREFIX}${palette.legendRow(null, entries, legendWidth, measure)}`;
|
|
389
349
|
if (measure(plain) > size) return customizeFit(helpers, plain, Math.max(0, size));
|
|
390
|
-
return palette.legendRow(theme, entries,
|
|
350
|
+
return `${palette.description(theme, CUSTOMIZE_CLICK_PREFIX)}${palette.legendRow(theme, entries, legendWidth, measure)}`;
|
|
391
351
|
}
|
|
392
352
|
|
|
393
353
|
// Focused-row selection: a full-width band when the injected theme paints
|
|
394
354
|
// backgrounds, else an accent ▸ marker — never a hardcoded escape, so focus
|
|
395
355
|
// stays readable on a theme that answers neither.
|
|
396
|
-
function customizeSelect(helpers, theme,
|
|
397
|
-
const safe = String(
|
|
356
|
+
function customizeSelect(helpers, theme, text, size, focused) {
|
|
357
|
+
const safe = String(text).split("\n")[0] ?? "";
|
|
398
358
|
if (focused && theme && typeof theme.bg === "function") {
|
|
399
359
|
try {
|
|
400
360
|
const row = customizeFit(helpers, ` ${safe}`, Math.max(0, size));
|
|
@@ -449,51 +409,320 @@ function customizeIsKeyRelease(helpers, data) {
|
|
|
449
409
|
return false;
|
|
450
410
|
}
|
|
451
411
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
// the
|
|
455
|
-
//
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
412
|
+
/* ------------------------------------------------------------------- model */
|
|
413
|
+
|
|
414
|
+
// A preview is either the upstream `{ title, sample }` pair or nothing at all:
|
|
415
|
+
// an unreadable source says so instead of falling back to the active theme.
|
|
416
|
+
function customizePreviewValue(themePreview, name) {
|
|
417
|
+
if (typeof themePreview !== "function") return null;
|
|
418
|
+
let preview;
|
|
419
|
+
try {
|
|
420
|
+
preview = themePreview(name);
|
|
421
|
+
} catch {
|
|
422
|
+
return null;
|
|
423
|
+
}
|
|
424
|
+
if (!preview || typeof preview !== "object") return null;
|
|
425
|
+
if (typeof preview.title !== "string" || typeof preview.sample !== "string") return null;
|
|
426
|
+
return { title: preview.title, sample: preview.sample };
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function customizeOption(id, optionLabel, current, preview) {
|
|
430
|
+
return { id, label: optionLabel, current: current === true, preview: preview ?? null };
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// One boolean setting. `value` is the stored option ("on"/"off") or null when
|
|
434
|
+
// the state could not be read: an unreadable state marks NO option current and
|
|
435
|
+
// carries a note instead of guessing.
|
|
436
|
+
function customizeToggleSetting(definition, stored) {
|
|
437
|
+
const current = stored === "on" || stored === "off" ? stored : null;
|
|
438
|
+
return {
|
|
439
|
+
id: definition.id,
|
|
440
|
+
setting: definition.setting,
|
|
441
|
+
...(current === null ? { note: definition.unknownNote ?? "state unknown" } : {}),
|
|
442
|
+
options: definition.order.map((which) => customizeOption(
|
|
443
|
+
which,
|
|
444
|
+
which === "on" ? "On" : "Off",
|
|
445
|
+
current === which,
|
|
446
|
+
definition.preview(which),
|
|
447
|
+
)),
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// The one setting that is not a boolean: `None` plus one option per installed
|
|
452
|
+
// theme, in Pi's own order. Its options are disabled (still selectable) only
|
|
453
|
+
// while the stored sync is on, and an unavailable theme list shows one note
|
|
454
|
+
// with no options at all instead of an empty list that looks pickable.
|
|
455
|
+
function customizeThemeSetting(themeState, themeNames, themePreview) {
|
|
456
|
+
const readable = themeState.ok !== false;
|
|
457
|
+
const syncOn = readable && themeState.sync === true;
|
|
458
|
+
const assigned = readable ? normalizeThemeName(themeState.theme) : null;
|
|
459
|
+
const listed = Array.isArray(themeNames);
|
|
460
|
+
const options = listed
|
|
461
|
+
? [
|
|
462
|
+
customizeOption(
|
|
463
|
+
CUSTOMIZE_THEME_NONE_ID,
|
|
464
|
+
CUSTOMIZE_THEME_NONE_LABEL,
|
|
465
|
+
readable && assigned === null,
|
|
466
|
+
{ title: "static unassigned sample", sample: CUSTOMIZE_THEME_NONE_SAMPLE },
|
|
467
|
+
),
|
|
468
|
+
...themeNames.map((name) => customizeOption(
|
|
469
|
+
`${CUSTOMIZE_THEME_OPTION_PREFIX}${name}`,
|
|
470
|
+
name,
|
|
471
|
+
readable && assigned === name,
|
|
472
|
+
customizePreviewValue(themePreview, name),
|
|
473
|
+
)),
|
|
474
|
+
]
|
|
475
|
+
: [];
|
|
476
|
+
const notes = [];
|
|
477
|
+
if (!readable) notes.push(CUSTOMIZE_THEME_UNKNOWN_NOTE);
|
|
478
|
+
else if (syncOn) notes.push(CUSTOMIZE_THEME_DISABLED_NOTE);
|
|
479
|
+
if (!listed) notes.push(CUSTOMIZE_THEME_UNAVAILABLE_NOTE);
|
|
480
|
+
return {
|
|
481
|
+
id: CUSTOMIZE_THEME_SETTING_ID,
|
|
482
|
+
setting: "Gentle Shell theme",
|
|
483
|
+
...(syncOn ? { disabled: true } : {}),
|
|
484
|
+
...(notes.length ? { note: notes.join(" ") } : {}),
|
|
485
|
+
options,
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// The current stored values as the extension read them. A sidebar state of
|
|
490
|
+
// `unknown` (unresolvable plugin root or inconclusive `--check`) and an
|
|
491
|
+
// unreadable theme store are never guessed values. `themeNames` is the host's
|
|
492
|
+
// theme list (`null` when the host exposes none) and `themePreview(name)` the
|
|
493
|
+
// per-theme swatch.
|
|
494
|
+
function customizePanelModel({ sidebar, moshi, theme, themeNames, themePreview } = {}) {
|
|
495
|
+
const stored = (value) => (value === "on" || value === "off" ? value : null);
|
|
496
|
+
const themeState = theme && typeof theme === "object"
|
|
497
|
+
? theme
|
|
498
|
+
: { ok: false, sync: false, theme: null };
|
|
499
|
+
const themeSync = themeState.ok === false ? null : stored(themeState.sync === true ? "on" : "off");
|
|
500
|
+
const current = {
|
|
501
|
+
sidebar: stored(sidebar),
|
|
502
|
+
moshi: stored(moshi) === "on" ? "on" : "off",
|
|
503
|
+
};
|
|
504
|
+
return [
|
|
505
|
+
{
|
|
506
|
+
id: "sidebar",
|
|
507
|
+
title: "Herdr Sidebar",
|
|
508
|
+
settings: [customizeToggleSetting(CUSTOMIZE_TOGGLES.sidebar, current.sidebar)],
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
id: "moshi",
|
|
512
|
+
title: "Moshi notifications",
|
|
513
|
+
settings: [customizeToggleSetting(CUSTOMIZE_TOGGLES.moshi, current.moshi)],
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
id: "theme",
|
|
517
|
+
title: "Herdr Theme",
|
|
518
|
+
settings: [
|
|
519
|
+
customizeToggleSetting(CUSTOMIZE_TOGGLES["theme-sync"], themeSync),
|
|
520
|
+
customizeThemeSetting(themeState, themeNames, themePreview),
|
|
521
|
+
],
|
|
522
|
+
},
|
|
523
|
+
];
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/* ---------------------------------------------------------- setting line */
|
|
527
|
+
|
|
528
|
+
// One setting line: the name column, then every option inline. `●` is the
|
|
529
|
+
// stored option, `›` the cursor while it is not the stored one, `○` the rest.
|
|
530
|
+
//
|
|
531
|
+
// A body wider than the pane becomes a sideways window that always contains the
|
|
532
|
+
// cursor option: muted `‹`/`›` mark hidden options on either side and an `n/m`
|
|
533
|
+
// counter names the cursor. Not even one option fitting falls back to upstream's
|
|
534
|
+
// compact `‹ value ›` form. The line is then fitted with an ellipsis, so a
|
|
535
|
+
// still-too-wide value is visibly cut instead of reading like a complete one.
|
|
536
|
+
//
|
|
537
|
+
// `focused` marks the line the keys act on (visible in either pane, so the
|
|
538
|
+
// keyboard always shows its target); `active` adds the band, which only the
|
|
539
|
+
// controls pane paints. A DISABLED setting is painted in the dim role and is
|
|
540
|
+
// never offered the band, because the band is this card's promise that Enter
|
|
541
|
+
// applies it.
|
|
542
|
+
function customizeSettingLine(helpers, theme, setting, cursorAt, nameWidth, size, focused, active) {
|
|
543
|
+
const name = String(setting.setting);
|
|
462
544
|
const namePad = " ".repeat(Math.max(0, nameWidth - customizeMeasure(helpers, name)));
|
|
463
545
|
const prefix = focused ? "▸ " : " ";
|
|
464
|
-
const lead = `${
|
|
465
|
-
const
|
|
466
|
-
const
|
|
467
|
-
const
|
|
468
|
-
const
|
|
469
|
-
const
|
|
470
|
-
const
|
|
471
|
-
|
|
546
|
+
const lead = `${name}${namePad}${CUSTOMIZE_OPTION_GAP}`;
|
|
547
|
+
const bodyStart = 2 + customizeMeasure(helpers, lead);
|
|
548
|
+
const budget = Math.max(0, size - bodyStart);
|
|
549
|
+
const disabled = setting.disabled === true;
|
|
550
|
+
const options = Array.isArray(setting.options) ? setting.options : [];
|
|
551
|
+
const cursor = Math.min(Math.max(0, cursorAt), Math.max(0, options.length - 1));
|
|
552
|
+
const kinds = (option, index) => {
|
|
553
|
+
if (disabled) return "label";
|
|
554
|
+
const current = option.current === true;
|
|
555
|
+
const atCursor = focused && index === cursor;
|
|
556
|
+
return current || (atCursor && !current) ? "accent" : "description";
|
|
557
|
+
};
|
|
558
|
+
const marks = options.map((option, index) => ({
|
|
559
|
+
index,
|
|
560
|
+
text: `${option.current === true
|
|
561
|
+
? CUSTOMIZE_MARK_CURRENT
|
|
562
|
+
: (focused && index === cursor ? CUSTOMIZE_MARK_CURSOR : CUSTOMIZE_MARK_OTHER)} ${option.label}`,
|
|
563
|
+
kind: kinds(option, index),
|
|
564
|
+
}));
|
|
565
|
+
// Every option joined: the plain form when it fits, the window or the compact
|
|
566
|
+
// form otherwise.
|
|
567
|
+
const body = [];
|
|
568
|
+
const joined = marks.map((mark) => mark.text).join(CUSTOMIZE_OPTION_GAP);
|
|
569
|
+
if (customizeMeasure(helpers, joined) <= budget) {
|
|
570
|
+
marks.forEach((mark, index) => {
|
|
571
|
+
if (index > 0) body.push({ text: CUSTOMIZE_OPTION_GAP });
|
|
572
|
+
body.push({ text: mark.text, kind: mark.kind, option: mark.index });
|
|
573
|
+
});
|
|
574
|
+
} else if (marks.length) {
|
|
575
|
+
const counter = `${cursor + 1}/${options.length}`;
|
|
576
|
+
const windowAt = (first, last) => {
|
|
577
|
+
const segments = [];
|
|
578
|
+
if (first > 0) segments.push({ kind: "description", text: "‹ " });
|
|
579
|
+
for (let index = first; index <= last; index += 1) {
|
|
580
|
+
if (index > first) segments.push({ text: CUSTOMIZE_OPTION_GAP });
|
|
581
|
+
segments.push({ text: marks[index].text, kind: marks[index].kind, option: index });
|
|
582
|
+
}
|
|
583
|
+
if (last < marks.length - 1) segments.push({ kind: "description", text: " ›" });
|
|
584
|
+
segments.push({ kind: "description", text: ` ${counter}` });
|
|
585
|
+
return segments;
|
|
586
|
+
};
|
|
587
|
+
const widthOf = (segments) => customizeMeasure(helpers, segments.map((segment) => segment.text).join(""));
|
|
588
|
+
let first = cursor;
|
|
589
|
+
let last = cursor;
|
|
590
|
+
if (widthOf(windowAt(first, last)) <= budget) {
|
|
591
|
+
// Grow to the right first (what comes next), then to the left, so the
|
|
592
|
+
// window is stable and the cursor stays on screen in every frame.
|
|
593
|
+
for (;;) {
|
|
594
|
+
if (last + 1 < marks.length && widthOf(windowAt(first, last + 1)) <= budget) {
|
|
595
|
+
last += 1;
|
|
596
|
+
continue;
|
|
597
|
+
}
|
|
598
|
+
if (first - 1 >= 0 && widthOf(windowAt(first - 1, last)) <= budget) {
|
|
599
|
+
first -= 1;
|
|
600
|
+
continue;
|
|
601
|
+
}
|
|
602
|
+
break;
|
|
603
|
+
}
|
|
604
|
+
body.push(...windowAt(first, last));
|
|
605
|
+
} else {
|
|
606
|
+
// Upstream's compact fallback: one value between arrows plus the counter.
|
|
607
|
+
// The value keeps the ellipsis INSIDE the arrows (upstream truncates the
|
|
608
|
+
// whole line), so the card still names exactly the cursored option instead
|
|
609
|
+
// of showing a neighbouring value cut in half. A card too narrow for both
|
|
610
|
+
// keeps the value and drops the counter: naming the cursor wins.
|
|
611
|
+
let counterText = ` ${counter}`;
|
|
612
|
+
const arrows = 4;
|
|
613
|
+
let labelRoom = budget - arrows - customizeMeasure(helpers, counterText);
|
|
614
|
+
if (labelRoom < 2 && budget - arrows > labelRoom) {
|
|
615
|
+
counterText = "";
|
|
616
|
+
labelRoom = budget - arrows;
|
|
617
|
+
}
|
|
618
|
+
const shownLabel = labelRoom >= 1
|
|
619
|
+
? customizeFit(helpers, options[cursor].label, labelRoom)
|
|
620
|
+
: options[cursor].label;
|
|
621
|
+
body.push({ kind: disabled ? "label" : "accent", text: `‹ ${shownLabel} ›`, option: cursor });
|
|
622
|
+
if (counterText) body.push({ kind: "description", text: counterText });
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
const spans = [];
|
|
626
|
+
let column = bodyStart;
|
|
627
|
+
for (const segment of body) {
|
|
628
|
+
const width = customizeMeasure(helpers, segment.text);
|
|
629
|
+
if (typeof segment.option === "number") spans.push({ index: segment.option, start: column, end: column + width });
|
|
630
|
+
column += width;
|
|
631
|
+
}
|
|
632
|
+
const plain = `${prefix}${lead}${body.map((segment) => segment.text).join("")}`;
|
|
633
|
+
const nameEnd = Math.min(size, 2 + customizeMeasure(helpers, name));
|
|
472
634
|
if (active && !disabled && theme && typeof theme.bg === "function") {
|
|
473
635
|
try {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
if (
|
|
636
|
+
// The band is a full-width background, so it is only painted when nothing
|
|
637
|
+
// had to be cut: a band around a truncated line would hide the cut.
|
|
638
|
+
if (customizeFit(helpers, plain, Math.max(0, size)) === plain) {
|
|
639
|
+
const band = theme.bg("selectedBg", plain + " ".repeat(Math.max(0, size - customizeMeasure(helpers, plain))));
|
|
640
|
+
if (typeof band === "string") return { text: band, nameEnd, spans };
|
|
641
|
+
}
|
|
477
642
|
} catch {
|
|
478
643
|
// Fall through to the composed form below.
|
|
479
644
|
}
|
|
480
645
|
}
|
|
481
646
|
const segments = [
|
|
482
|
-
{ kind:
|
|
483
|
-
{ kind:
|
|
484
|
-
|
|
647
|
+
{ kind: disabled ? "label" : (focused ? "key" : "label"), text: prefix },
|
|
648
|
+
{ kind: disabled ? "label" : (focused ? "value" : "description"), text: lead },
|
|
649
|
+
...body,
|
|
485
650
|
];
|
|
486
|
-
|
|
487
|
-
return customizeCompose(helpers, theme, segments, size);
|
|
651
|
+
return { text: customizeCompose(helpers, theme, segments, size), nameEnd, spans };
|
|
488
652
|
}
|
|
489
653
|
|
|
490
|
-
|
|
654
|
+
/* -------------------------------------------------------------- component */
|
|
655
|
+
|
|
656
|
+
function createCustomizePanel({ helpers, hostTui, theme, rowsAvailable, model: initialModel, apply, done }) {
|
|
491
657
|
const state = {
|
|
492
658
|
pane: "categories",
|
|
659
|
+
model: Array.isArray(initialModel) ? initialModel : [],
|
|
493
660
|
cat: 0,
|
|
494
|
-
|
|
661
|
+
settingId: initialModel && initialModel[0] && initialModel[0].settings[0] ? initialModel[0].settings[0].id : null,
|
|
662
|
+
cursors: new Map(),
|
|
495
663
|
frame: null,
|
|
664
|
+
busy: false,
|
|
496
665
|
};
|
|
666
|
+
function settings() {
|
|
667
|
+
const category = state.model[state.cat];
|
|
668
|
+
return category && Array.isArray(category.settings) ? category.settings : [];
|
|
669
|
+
}
|
|
670
|
+
function settingIndex() {
|
|
671
|
+
const at = settings().findIndex((entry) => entry.id === state.settingId);
|
|
672
|
+
return at < 0 ? 0 : at;
|
|
673
|
+
}
|
|
674
|
+
function focusedSetting() {
|
|
675
|
+
return settings()[settingIndex()] || null;
|
|
676
|
+
}
|
|
677
|
+
// A setting is entered on its stored option (upstream `landOn`); an unknown
|
|
678
|
+
// state has no stored option, so it enters on the first one.
|
|
679
|
+
function landOn(setting) {
|
|
680
|
+
const at = setting && Array.isArray(setting.options) ? setting.options.findIndex((option) => option.current === true) : -1;
|
|
681
|
+
return at < 0 ? 0 : at;
|
|
682
|
+
}
|
|
683
|
+
function cursorIndex(setting) {
|
|
684
|
+
if (!setting || !Array.isArray(setting.options)) return 0;
|
|
685
|
+
const stored = state.cursors.get(setting.id);
|
|
686
|
+
const at = setting.options.findIndex((option) => option.id === stored);
|
|
687
|
+
return at < 0 ? landOn(setting) : at;
|
|
688
|
+
}
|
|
689
|
+
function setCursor(setting, index) {
|
|
690
|
+
const option = setting && Array.isArray(setting.options) ? setting.options[index] : null;
|
|
691
|
+
if (option) state.cursors.set(setting.id, option.id);
|
|
692
|
+
}
|
|
693
|
+
// Every setting starts on its stored option, so a fresh frame never shows a
|
|
694
|
+
// cursor on a value nobody chose.
|
|
695
|
+
for (const category of state.model) {
|
|
696
|
+
for (const setting of category.settings || []) setCursor(setting, landOn(setting));
|
|
697
|
+
}
|
|
698
|
+
// The cursor survives a model swap by ID, which is why option ids are
|
|
699
|
+
// structural: after applying `off` the cursor stays on `off`, and only an
|
|
700
|
+
// option that no longer exists re-lands on the stored one.
|
|
701
|
+
function replaceModel(next) {
|
|
702
|
+
if (!Array.isArray(next) || next.length === 0) return;
|
|
703
|
+
const previousId = state.model[state.cat] ? state.model[state.cat].id : null;
|
|
704
|
+
const at = next.findIndex((category) => category.id === previousId);
|
|
705
|
+
state.model = next;
|
|
706
|
+
state.cat = at < 0 ? Math.min(state.cat, next.length - 1) : at;
|
|
707
|
+
const seen = new Set();
|
|
708
|
+
for (const category of next) {
|
|
709
|
+
for (const setting of category.settings || []) {
|
|
710
|
+
seen.add(setting.id);
|
|
711
|
+
const stored = state.cursors.get(setting.id);
|
|
712
|
+
const keep = stored !== undefined && Array.isArray(setting.options)
|
|
713
|
+
&& setting.options.some((option) => option.id === stored);
|
|
714
|
+
if (!keep) {
|
|
715
|
+
const landed = setting.options ? setting.options[landOn(setting)] : null;
|
|
716
|
+
if (landed) state.cursors.set(setting.id, landed.id);
|
|
717
|
+
else state.cursors.delete(setting.id);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
for (const id of [...state.cursors.keys()]) if (!seen.has(id)) state.cursors.delete(id);
|
|
722
|
+
if (!settings().some((setting) => setting.id === state.settingId)) {
|
|
723
|
+
state.settingId = settings()[0] ? settings()[0].id : null;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
497
726
|
function availableRows() {
|
|
498
727
|
try {
|
|
499
728
|
if (typeof rowsAvailable === "function") {
|
|
@@ -505,77 +734,68 @@ function createCustomizePanel({ helpers, hostTui, theme, rowsAvailable, model, d
|
|
|
505
734
|
}
|
|
506
735
|
return CUSTOMIZE_MAX_HEIGHT;
|
|
507
736
|
}
|
|
508
|
-
function focused() {
|
|
509
|
-
const category = model[state.cat];
|
|
510
|
-
return { category, row: category.rows[state.row[state.cat]] || null };
|
|
511
|
-
}
|
|
512
|
-
// What the card describes on its own row: the setting the values pane holds
|
|
513
|
-
// the focus on, or the category while the left list owns it.
|
|
514
|
-
function focusedDescription() {
|
|
515
|
-
const category = model[state.cat];
|
|
516
|
-
const row = state.pane === "values" ? focused().row : null;
|
|
517
|
-
return row
|
|
518
|
-
? { title: row.setting, description: row.description }
|
|
519
|
-
: { title: category.title, description: category.description };
|
|
520
|
-
}
|
|
521
737
|
function render(width) {
|
|
522
738
|
const w = typeof width === "number" && Number.isFinite(width) ? Math.floor(width) : 0;
|
|
523
739
|
state.frame = null;
|
|
524
740
|
if (w <= 0) return [];
|
|
525
741
|
const height = availableRows();
|
|
526
742
|
if (!height) return [];
|
|
527
|
-
const title = CUSTOMIZE_TITLE;
|
|
528
743
|
// A card needs two border rows. At extreme dimensions keep a read-only
|
|
529
744
|
// heading rather than activatable invisible controls.
|
|
530
745
|
if (w < CUSTOMIZE_CARD_PADDING + 1 || height < 4) {
|
|
531
|
-
return [
|
|
746
|
+
return [CUSTOMIZE_TITLE, "Enlarge terminal"].slice(0, Math.min(height, 2))
|
|
532
747
|
.map((line) => customizeFit(helpers, line, w, ""));
|
|
533
748
|
}
|
|
534
749
|
const inner = w - CUSTOMIZE_CARD_PADDING;
|
|
535
750
|
const narrow = w < CUSTOMIZE_NARROW_WIDTH;
|
|
536
|
-
const navOnly = narrow && state.pane === "categories" && model.length > 1;
|
|
751
|
+
const navOnly = narrow && state.pane === "categories" && state.model.length > 1;
|
|
537
752
|
// The left column fits every category title plus the focus prefix:
|
|
538
753
|
// truncating a category name is never acceptable, the right pane may clip.
|
|
539
|
-
const leftNeed = model.reduce(
|
|
754
|
+
const leftNeed = state.model.reduce(
|
|
540
755
|
(need, entry) => Math.max(need, 2 + customizeMeasure(helpers, entry.title)),
|
|
541
756
|
0,
|
|
542
757
|
);
|
|
543
|
-
const leftWidth = narrow ? 0 : Math.min(24, Math.max(leftNeed, Math.floor(inner * 0.28)));
|
|
758
|
+
const leftWidth = narrow ? 0 : Math.min(24, Math.max(leftNeed, Math.max(14, Math.floor(inner * 0.28))));
|
|
544
759
|
const rightWidth = inner - leftWidth - (leftWidth ? 3 : 0);
|
|
545
|
-
|
|
546
|
-
|
|
760
|
+
// Upstream's preview height rule: 6 / 3 / 1 / 0 lines by overlay height,
|
|
761
|
+
// deducted from the content height inside the same card.
|
|
762
|
+
const previewLines = height >= 18 ? 6 : height >= 11 ? 3 : height >= 8 ? 1 : 0;
|
|
547
763
|
const showHeading = height >= 6;
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
const
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
const
|
|
555
|
-
|
|
556
|
-
//
|
|
557
|
-
const
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
764
|
+
const showTopGap = height >= 12;
|
|
765
|
+
const showBottomGap = height >= 9;
|
|
766
|
+
const chrome = 1 + (showHeading ? 2 : 0) + (showTopGap ? 1 : 0) + (showBottomGap ? 1 : 0);
|
|
767
|
+
const contentHeight = Math.max(1, height - 2 - chrome - previewLines);
|
|
768
|
+
const category = state.model[state.cat] || { id: null, title: "Settings", settings: [] };
|
|
769
|
+
const entries = category.settings || [];
|
|
770
|
+
const focusedAt = settingIndex();
|
|
771
|
+
// Right pane rows: one line per setting plus, when the state cannot name a
|
|
772
|
+
// value, one muted note under it.
|
|
773
|
+
const rightLines = [];
|
|
774
|
+
entries.forEach((setting, index) => {
|
|
775
|
+
rightLines.push({ kind: "setting", index, setting });
|
|
776
|
+
if (setting.note) rightLines.push({ kind: "note", text: setting.note });
|
|
777
|
+
});
|
|
778
|
+
const focusedLine = rightLines.findIndex((line) => line.kind === "setting" && line.index === focusedAt);
|
|
779
|
+
const position = navOnly ? state.cat : Math.max(0, focusedLine);
|
|
780
|
+
const listLength = navOnly ? state.model.length : rightLines.length;
|
|
561
781
|
const start = Math.min(Math.max(0, position - contentHeight + 1), Math.max(0, listLength - contentHeight));
|
|
562
|
-
const navStart = Math.min(Math.max(0, state.cat - contentHeight + 1), Math.max(0, model.length - contentHeight));
|
|
563
|
-
const nameWidth =
|
|
564
|
-
|
|
565
|
-
0,
|
|
782
|
+
const navStart = Math.min(Math.max(0, state.cat - contentHeight + 1), Math.max(0, state.model.length - contentHeight));
|
|
783
|
+
const nameWidth = Math.min(
|
|
784
|
+
20,
|
|
785
|
+
entries.reduce((need, setting) => Math.max(need, customizeMeasure(helpers, setting.setting)), 0),
|
|
566
786
|
);
|
|
567
|
-
const
|
|
787
|
+
const paintCell = (text, size, kind) => customizePaint(helpers, theme, kind, text, size);
|
|
568
788
|
const compose = (segments, size) => customizeCompose(helpers, theme, segments, size);
|
|
569
789
|
const divider = palette.paint(theme, "border", "│");
|
|
570
|
-
const join = (left, right) => leftWidth
|
|
790
|
+
const join = (left, right) => (leftWidth
|
|
571
791
|
? `${left}${" ".repeat(Math.max(0, leftWidth - customizeMeasure(helpers, left)))} ${divider} ${right}`
|
|
572
|
-
: right;
|
|
792
|
+
: right);
|
|
573
793
|
const lines = [];
|
|
574
794
|
const hits = [];
|
|
575
|
-
|
|
576
|
-
const escGap = Math.max(1, inner - customizeMeasure(helpers,
|
|
795
|
+
const titleRow = CUSTOMIZE_TITLE;
|
|
796
|
+
const escGap = Math.max(1, inner - customizeMeasure(helpers, titleRow) - 3);
|
|
577
797
|
lines.push(compose([
|
|
578
|
-
{ kind: "title", text:
|
|
798
|
+
{ kind: "title", text: titleRow },
|
|
579
799
|
{ text: " ".repeat(escGap) },
|
|
580
800
|
{ kind: "key", text: "esc" },
|
|
581
801
|
], inner));
|
|
@@ -585,59 +805,88 @@ function createCustomizePanel({ helpers, hostTui, theme, rowsAvailable, model, d
|
|
|
585
805
|
: [
|
|
586
806
|
{ kind: "title", text: category.title },
|
|
587
807
|
{ kind: "label", text: " · " },
|
|
588
|
-
{ kind: "count", text:
|
|
808
|
+
{ kind: "count", text: entries.length ? `${focusedAt + 1}/${entries.length}` : "empty" },
|
|
589
809
|
];
|
|
590
810
|
lines.push(join(
|
|
591
|
-
leftWidth ?
|
|
811
|
+
leftWidth ? paintCell("CATEGORIES", leftWidth, "key") : "",
|
|
592
812
|
compose(heading, rightWidth),
|
|
593
813
|
));
|
|
594
814
|
}
|
|
815
|
+
if (showTopGap) lines.push("");
|
|
595
816
|
for (let i = 0; i < contentHeight; i += 1) {
|
|
596
817
|
const navIndex = navStart + i;
|
|
597
|
-
const nav = model[navIndex];
|
|
818
|
+
const nav = state.model[navIndex];
|
|
598
819
|
const at = start + i;
|
|
599
|
-
const item = navOnly ? (model[at] || null) : (rightLines[at] || null);
|
|
820
|
+
const item = navOnly ? (state.model[at] || null) : (rightLines[at] || null);
|
|
600
821
|
// The card paints the top border above content line 0, so a content row's
|
|
601
822
|
// rendered row is its index + 1.
|
|
602
823
|
const y = lines.length + 1;
|
|
824
|
+
const rightStart = 2 + (leftWidth ? leftWidth + 3 : 0);
|
|
603
825
|
const left = nav
|
|
604
826
|
? customizeSelect(helpers, theme, nav.title, leftWidth, navOnly ? at === state.cat : navIndex === state.cat && state.pane === "categories")
|
|
605
827
|
: "";
|
|
606
828
|
let right = "";
|
|
607
829
|
if (navOnly) {
|
|
608
830
|
right = item ? customizeSelect(helpers, theme, item.title, rightWidth, at === state.cat) : "";
|
|
609
|
-
|
|
610
|
-
|
|
831
|
+
if (item) hits.push({ kind: "category", index: at, y, x: rightStart + 2, end: rightStart + rightWidth });
|
|
832
|
+
} else if (item && item.kind === "setting") {
|
|
833
|
+
const rendered = customizeSettingLine(
|
|
611
834
|
helpers,
|
|
612
835
|
theme,
|
|
613
|
-
item.
|
|
836
|
+
item.setting,
|
|
837
|
+
cursorIndex(item.setting),
|
|
614
838
|
nameWidth,
|
|
615
839
|
rightWidth,
|
|
616
|
-
at ===
|
|
617
|
-
at ===
|
|
840
|
+
at === position,
|
|
841
|
+
at === position && state.pane === "controls",
|
|
618
842
|
);
|
|
843
|
+
right = rendered.text;
|
|
844
|
+
// A click on the name only moves the focus; a click on an option applies
|
|
845
|
+
// exactly that option.
|
|
846
|
+
if (rendered.nameEnd > 2) {
|
|
847
|
+
hits.push({ kind: "setting", index: item.index, y, x: rightStart + 2, end: rightStart + rendered.nameEnd });
|
|
848
|
+
}
|
|
849
|
+
for (const span of rendered.spans) {
|
|
850
|
+
hits.push({ kind: "option", index: item.index, option: span.index, y, x: rightStart + span.start, end: rightStart + span.end });
|
|
851
|
+
}
|
|
619
852
|
} else if (item && item.kind === "note") {
|
|
620
|
-
right =
|
|
853
|
+
right = paintCell(item.text, rightWidth, "description");
|
|
621
854
|
} else if (rightLines.length === 0) {
|
|
622
|
-
right =
|
|
855
|
+
right = paintCell("No settings available", rightWidth, "description");
|
|
623
856
|
}
|
|
624
857
|
lines.push(join(left, right));
|
|
625
858
|
// Pointer hits cover the pane text only: a click on a border, the title,
|
|
626
859
|
// the heading or the footer hits nothing and is ignored.
|
|
627
|
-
const rightStart = 2 + (leftWidth ? leftWidth + 3 : 0);
|
|
628
860
|
if (leftWidth && nav) hits.push({ kind: "category", index: navIndex, y, x: 2, end: 2 + leftWidth });
|
|
629
|
-
if (navOnly && item) hits.push({ kind: "category", index: at, y, x: rightStart + 2, end: rightStart + rightWidth });
|
|
630
|
-
else if (item && item.kind === "row") hits.push({ kind: "row", index: item.index, y, x: rightStart + 2, end: rightStart + rightWidth });
|
|
631
861
|
}
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
]
|
|
862
|
+
// The Preview block: a spacer, the accent headline naming the highlighted
|
|
863
|
+
// option and its preview title, then the muted sample lines — the upstream
|
|
864
|
+
// placement, height and roles. No separate `<Category> — <description>` row
|
|
865
|
+
// exists any more: the preview title IS the description.
|
|
866
|
+
if (previewLines >= 3) {
|
|
867
|
+
const setting = entries[focusedAt] || null;
|
|
868
|
+
const option = !navOnly && setting && Array.isArray(setting.options) ? setting.options[cursorIndex(setting)] : null;
|
|
869
|
+
const preview = option ? option.preview : null;
|
|
870
|
+
lines.push("");
|
|
871
|
+
const headline = navOnly
|
|
872
|
+
? "→ controls · Esc close"
|
|
873
|
+
: preview && option
|
|
874
|
+
? `Preview · ${option.label} · ${preview.title}`
|
|
875
|
+
: "Preview unavailable";
|
|
876
|
+
lines.push(paintCell(headline, inner, "accent"));
|
|
877
|
+
const sample = navOnly
|
|
878
|
+
? [""]
|
|
879
|
+
: preview
|
|
880
|
+
? preview.sample.split("\n")
|
|
881
|
+
: ["No read-only sample for this choice"];
|
|
882
|
+
for (let i = 0; i < previewLines - 2; i += 1) lines.push(paintCell(sample[i] ?? "", inner, "description"));
|
|
883
|
+
} else if (previewLines === 1) {
|
|
884
|
+
lines.push(paintCell(navOnly ? "→ controls · Esc close" : "Preview omitted · enlarge terminal", inner, "description"));
|
|
638
885
|
}
|
|
886
|
+
if (showBottomGap) lines.push("");
|
|
639
887
|
if (showHeading) {
|
|
640
|
-
|
|
888
|
+
const footerEntries = customizeFooterVariant(navOnly, state.pane, entries[focusedAt] || null);
|
|
889
|
+
lines.push(customizePad(helpers, customizeFooter(helpers, theme, footerEntries, inner), inner));
|
|
641
890
|
}
|
|
642
891
|
const shown = lines.slice(0, Math.max(0, height - 2));
|
|
643
892
|
state.frame = { width: w, height: shown.length + 2, hits: hits.filter((hit) => hit.y <= shown.length) };
|
|
@@ -650,68 +899,109 @@ function createCustomizePanel({ helpers, hostTui, theme, rowsAvailable, model, d
|
|
|
650
899
|
// A repaint failure never breaks navigation.
|
|
651
900
|
}
|
|
652
901
|
}
|
|
902
|
+
// The one action that can write: it runs behind a busy guard (a second Enter
|
|
903
|
+
// while the first apply is in flight does nothing), swaps in the model apply
|
|
904
|
+
// read back, and closes only when the extension asked for it — the Moshi
|
|
905
|
+
// reload must never run behind a mounted card.
|
|
906
|
+
function runApply(setting, option) {
|
|
907
|
+
if (state.busy || !setting || !option) return;
|
|
908
|
+
state.busy = true;
|
|
909
|
+
let pending;
|
|
910
|
+
try {
|
|
911
|
+
pending = typeof apply === "function"
|
|
912
|
+
? apply({ categoryId: state.model[state.cat] ? state.model[state.cat].id : null, settingId: setting.id, optionId: option.id })
|
|
913
|
+
: Promise.resolve(null);
|
|
914
|
+
} catch {
|
|
915
|
+
state.busy = false;
|
|
916
|
+
requestPaint();
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
919
|
+
Promise.resolve(pending).then((result) => {
|
|
920
|
+
state.busy = false;
|
|
921
|
+
if (result && result.model) replaceModel(result.model);
|
|
922
|
+
if (result && result.close === true) {
|
|
923
|
+
done(null);
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
requestPaint();
|
|
927
|
+
}, () => {
|
|
928
|
+
state.busy = false;
|
|
929
|
+
requestPaint();
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
function enterControls() {
|
|
933
|
+
state.pane = "controls";
|
|
934
|
+
const setting = focusedSetting();
|
|
935
|
+
if (setting) setCursor(setting, landOn(setting));
|
|
936
|
+
}
|
|
653
937
|
function handleInput(data) {
|
|
654
938
|
if (customizeIsKeyRelease(helpers, data)) return;
|
|
655
939
|
if (customizeKeyMatches(helpers, data, ["escape", "ctrl+c"])) {
|
|
656
940
|
done(null);
|
|
657
941
|
return;
|
|
658
942
|
}
|
|
659
|
-
if (
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
943
|
+
if (state.busy) return;
|
|
944
|
+
const length = state.pane === "categories" ? state.model.length : settings().length;
|
|
945
|
+
if (!length) return;
|
|
946
|
+
const setting = focusedSetting();
|
|
947
|
+
const step = state.pane === "controls" && setting && Array.isArray(setting.options) && setting.options.length
|
|
948
|
+
? (customizeKeyMatches(helpers, data, ["left"]) ? -1 : customizeKeyMatches(helpers, data, ["right"]) ? 1 : 0)
|
|
949
|
+
: 0;
|
|
950
|
+
if (step === -1 && cursorIndex(setting) === 0) {
|
|
951
|
+
// Left past the first option leaves the controls, exactly like upstream.
|
|
952
|
+
state.pane = "categories";
|
|
953
|
+
} else if (step) {
|
|
954
|
+
const next = cursorIndex(setting) + step;
|
|
955
|
+
// Every setting defers to Enter (`applyOnMove: false`): a step that would
|
|
956
|
+
// leave the option range changes nothing and writes nothing.
|
|
957
|
+
if (next >= 0 && next < setting.options.length) setCursor(setting, next);
|
|
958
|
+
} else if (customizeKeyMatches(helpers, data, ["left"]) || (customizeKeyMatches(helpers, data, ["tab"]) && state.pane === "controls")) {
|
|
959
|
+
state.pane = "categories";
|
|
960
|
+
} else if (customizeKeyMatches(helpers, data, ["right"]) || (customizeKeyMatches(helpers, data, ["tab"]) && state.pane === "categories")) {
|
|
961
|
+
enterControls();
|
|
962
|
+
} else if (customizeKeyMatches(helpers, data, ["up", "k"])) {
|
|
963
|
+
if (state.pane === "categories") state.cat = (state.cat + state.model.length - 1) % state.model.length;
|
|
666
964
|
else {
|
|
667
|
-
const
|
|
668
|
-
|
|
965
|
+
const list = settings();
|
|
966
|
+
const at = (settingIndex() + list.length - 1) % list.length;
|
|
967
|
+
state.settingId = list[at].id;
|
|
968
|
+
setCursor(list[at], landOn(list[at]));
|
|
669
969
|
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
}
|
|
673
|
-
if (customizeKeyMatches(helpers, data, ["down", "j"])) {
|
|
674
|
-
if (state.pane === "categories") state.cat = (state.cat + 1) % model.length;
|
|
970
|
+
} else if (customizeKeyMatches(helpers, data, ["down", "j"])) {
|
|
971
|
+
if (state.pane === "categories") state.cat = (state.cat + 1) % state.model.length;
|
|
675
972
|
else {
|
|
676
|
-
const
|
|
677
|
-
|
|
973
|
+
const list = settings();
|
|
974
|
+
const at = (settingIndex() + 1) % list.length;
|
|
975
|
+
state.settingId = list[at].id;
|
|
976
|
+
setCursor(list[at], landOn(list[at]));
|
|
678
977
|
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
const current = focused();
|
|
684
|
-
done({
|
|
685
|
-
categoryId: current.category.id,
|
|
686
|
-
switchId: current.row ? current.row.switchId : current.category.id,
|
|
687
|
-
valueId: current.row ? current.row.id : null,
|
|
688
|
-
});
|
|
978
|
+
} else if (customizeKeyMatches(helpers, data, ["enter", "return", "space"]) && state.pane === "categories") {
|
|
979
|
+
enterControls();
|
|
980
|
+
} else if (customizeKeyMatches(helpers, data, ["enter", "return", "space"])) {
|
|
981
|
+
runApply(setting, setting && Array.isArray(setting.options) ? setting.options[cursorIndex(setting)] : null);
|
|
689
982
|
}
|
|
983
|
+
requestPaint();
|
|
690
984
|
}
|
|
691
|
-
// Pointer contract: x/y are local to this component's rendered frame, the
|
|
692
|
-
//
|
|
693
|
-
//
|
|
694
|
-
//
|
|
695
|
-
// which is also the answer for a click on a border, the title, the heading
|
|
696
|
-
// or the footer.
|
|
697
|
-
//
|
|
698
|
-
// The reported `width`/`height` are the box the host rendered, which the
|
|
699
|
-
// overlay may have clipped shorter than the rows this panel budgeted. The hit
|
|
700
|
-
// test therefore reads the frame it rendered and only clamps the row into it:
|
|
701
|
-
// a geometry comparison the user cannot see must never swallow a real click.
|
|
985
|
+
// Pointer contract: x/y are local to this component's rendered frame, the card
|
|
986
|
+
// border included. A press only captures the gesture; the click that follows
|
|
987
|
+
// activates the hit, so a drag never applies an option by accident, and a move
|
|
988
|
+
// only carries the focus. Anything outside a pane's text is ignored.
|
|
702
989
|
function focusHit(hit) {
|
|
703
990
|
if (hit.kind === "category") {
|
|
704
991
|
if (state.pane === "categories" && state.cat === hit.index) return false;
|
|
705
992
|
state.cat = hit.index;
|
|
706
993
|
state.pane = "categories";
|
|
994
|
+
state.settingId = settings()[0] ? settings()[0].id : null;
|
|
707
995
|
return true;
|
|
708
996
|
}
|
|
709
|
-
const
|
|
710
|
-
|
|
711
|
-
if (
|
|
712
|
-
state.pane
|
|
713
|
-
state.
|
|
714
|
-
|
|
997
|
+
const list = settings();
|
|
998
|
+
const setting = list[hit.index];
|
|
999
|
+
if (!setting) return false;
|
|
1000
|
+
const changed = state.pane !== "controls" || state.settingId !== setting.id || hit.kind === "option";
|
|
1001
|
+
state.pane = "controls";
|
|
1002
|
+
state.settingId = setting.id;
|
|
1003
|
+
if (hit.kind === "option") setCursor(setting, hit.option);
|
|
1004
|
+
return changed;
|
|
715
1005
|
}
|
|
716
1006
|
function handleMouse(event) {
|
|
717
1007
|
if (!event) return undefined;
|
|
@@ -725,17 +1015,21 @@ function createCustomizePanel({ helpers, hostTui, theme, rowsAvailable, model, d
|
|
|
725
1015
|
if (!hit) return undefined;
|
|
726
1016
|
if (moving) return { handled: true, render: focusHit(hit) };
|
|
727
1017
|
if (event.type === "press") return { handled: true, capture: true, render: false };
|
|
728
|
-
|
|
1018
|
+
if (state.busy) return { handled: true, render: false };
|
|
729
1019
|
if (hit.kind === "category") {
|
|
730
1020
|
state.cat = hit.index;
|
|
731
1021
|
state.pane = "categories";
|
|
1022
|
+
state.settingId = settings()[0] ? settings()[0].id : null;
|
|
1023
|
+
// A narrow card has no category column: selecting one opens its settings.
|
|
1024
|
+
if (frame.width < CUSTOMIZE_NARROW_WIDTH) enterControls();
|
|
732
1025
|
return { handled: true, render: true, focus: true };
|
|
733
1026
|
}
|
|
734
|
-
const
|
|
735
|
-
if (!
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
1027
|
+
const setting = settings()[hit.index];
|
|
1028
|
+
if (!setting) return undefined;
|
|
1029
|
+
focusHit(hit);
|
|
1030
|
+
if (hit.kind === "option") {
|
|
1031
|
+
runApply(setting, setting.options ? setting.options[hit.option] : null);
|
|
1032
|
+
}
|
|
739
1033
|
return { handled: true, render: true, focus: true };
|
|
740
1034
|
}
|
|
741
1035
|
function invalidate() {}
|