@diagc/cli 1.6.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +8 -3
  2. package/assets/guide/git-graph.md +3 -0
  3. package/assets/guide/index.md +3 -3
  4. package/assets/skill/SKILL.md +1 -1
  5. package/assets/studio/assets/index-CB6jjAka.js +112 -0
  6. package/assets/studio/index.html +1 -1
  7. package/assets/viewer/index.html +23 -23
  8. package/dist/cli/parse.d.ts +8 -1
  9. package/dist/cli/parse.js +13 -1
  10. package/dist/cli/run.js +6 -2
  11. package/dist/cli.js +6 -2
  12. package/dist/commands/show.d.ts +1 -1
  13. package/dist/commands/show.js +12 -2
  14. package/dist/commands/tui.d.ts +1 -1
  15. package/dist/commands/tui.js +10 -2
  16. package/dist/text/ansi.js +11 -5
  17. package/dist/text/canvas.d.ts +9 -2
  18. package/dist/text/canvas.js +25 -7
  19. package/dist/text/dos.d.ts +69 -0
  20. package/dist/text/dos.js +93 -0
  21. package/dist/text/git.d.ts +52 -0
  22. package/dist/text/git.js +274 -0
  23. package/dist/text/glyphs.d.ts +4 -3
  24. package/dist/text/glyphs.js +18 -2
  25. package/dist/text/layout.d.ts +39 -1
  26. package/dist/text/layout.js +10 -7
  27. package/dist/text/legend.js +17 -13
  28. package/dist/text/paint.d.ts +6 -4
  29. package/dist/text/paint.js +164 -17
  30. package/dist/text/scene.d.ts +7 -0
  31. package/dist/text/scene.js +16 -4
  32. package/dist/tui/actions.d.ts +5 -0
  33. package/dist/tui/actions.js +17 -2
  34. package/dist/tui/app.d.ts +3 -0
  35. package/dist/tui/app.js +18 -5
  36. package/dist/tui/nav.d.ts +16 -10
  37. package/dist/tui/nav.js +26 -4
  38. package/dist/tui/overview.d.ts +4 -2
  39. package/dist/tui/overview.js +38 -8
  40. package/dist/tui/screen.d.ts +10 -0
  41. package/dist/tui/screen.js +105 -23
  42. package/dist/tui/state.d.ts +14 -10
  43. package/dist/tui/state.js +13 -4
  44. package/package.json +2 -2
  45. package/assets/studio/assets/index-DRsUukzt.js +0 -112
@@ -36,6 +36,23 @@ function toDots(r, scale, unit = BRAILLE) {
36
36
  return { x, y, width: right - x + 1, height: bottom - y + 1 };
37
37
  }
38
38
  const overlaps = (a, b) => a.x < b.x + b.width && b.x < a.x + a.width && a.y < b.y + b.height && b.y < a.y + a.height;
39
+ const within = (a, b) => a.x >= b.x && a.y >= b.y && a.x + a.width <= b.x + b.width && a.y + a.height <= b.y + b.height;
40
+ /** `r` less `by` dots each side. */
41
+ const inset = (r, by) => ({
42
+ x: r.x + by,
43
+ y: r.y + by,
44
+ width: r.width - 2 * by,
45
+ height: r.height - 2 * by,
46
+ });
47
+ /** The selected box, and whether it is an open group: one that holds other boxes. The
48
+ * canvas marks a group by its frame and title, and filling it would hide all it holds. */
49
+ function selection(layout, selected) {
50
+ const box = selected === undefined ? undefined : layout.boxes.get(selected);
51
+ if (box === undefined)
52
+ return undefined;
53
+ const group = [...layout.boxes].some(([id, b]) => id !== selected && within(b, box));
54
+ return { box, group };
55
+ }
39
56
  /** The window cut to the picture: past the picture's edge its outline would be lost. */
40
57
  function onPicture(window, picture) {
41
58
  const x = clamp(window.scroll.x, 0, picture.width);
@@ -48,18 +65,21 @@ function onPicture(window, picture) {
48
65
  };
49
66
  }
50
67
  /** The overview's cells, `place`'s size: each box's outline and the window's, what is
51
- * off screen dim and the selected box inverse, as it is on the canvas. */
68
+ * off screen dim and the selected box inverse, as it is on the canvas (a group, its
69
+ * frame). */
52
70
  export function overviewCells(layout, place, window, selected) {
53
71
  const dots = new Dots(place.width, place.height);
54
72
  for (const box of layout.boxes.values())
55
73
  dots.outline(toDots(box, place.scale));
56
74
  const screen = toDots(onPicture(window, layout), place.scale);
57
75
  dots.outline(screen);
58
- const box = selected === undefined ? undefined : layout.boxes.get(selected);
59
- const chosen = box === undefined ? undefined : toDots(box, place.scale);
76
+ const chosen = selection(layout, selected);
77
+ const dotted = chosen === undefined ? undefined : toDots(chosen.box, place.scale);
78
+ // a group's inside: its cells clear of its frame
79
+ const inside = dotted === undefined || chosen?.group !== true ? undefined : inset(dotted, 1);
60
80
  return Array.from({ length: place.height }, (_, row) => Array.from({ length: place.width }, (_, column) => {
61
81
  const cell = { x: column * 2, y: row * 4, width: 2, height: 4 };
62
- const style = chosen !== undefined && overlaps(cell, chosen)
82
+ const style = dotted !== undefined && overlaps(cell, dotted) && !(inside !== undefined && within(cell, inside))
63
83
  ? { inverse: true }
64
84
  : overlaps(cell, screen)
65
85
  ? {}
@@ -73,7 +93,8 @@ const SHARE_OF = { box: 1, line: 0.5, screen: 1, screenTint: 0.2, selected: 1 };
73
93
  const OFF_SCREEN = 0.4;
74
94
  /** The overview in pixels, `place`'s cells' worth: each box's outline and the lines
75
95
  * between them, what is off screen dimmed, the part on screen outlined and faintly
76
- * tinted, and the selected box filled in, as inverse fills it on the canvas. */
96
+ * tinted, and the selected box filled in, as inverse fills it on the canvas; a selected
97
+ * group framed heavy instead. */
77
98
  export function overviewPixels(layout, place, window, selected) {
78
99
  const { cell, scale } = place;
79
100
  const pixels = new Pixels(place.width * cell.width, place.height * cell.height);
@@ -95,9 +116,18 @@ export function overviewPixels(layout, place, window, selected) {
95
116
  pixels.dimOutside(screen, OFF_SCREEN);
96
117
  pixels.fill(screen, SHARE_OF.screenTint);
97
118
  pixels.outline(screen, SHARE_OF.screen);
98
- const box = selected === undefined ? undefined : layout.boxes.get(selected);
99
- if (box !== undefined)
100
- pixels.fill(toDots(box, scale, cell), SHARE_OF.selected);
119
+ const chosen = selection(layout, selected);
120
+ const dotted = chosen === undefined ? undefined : toDots(chosen.box, scale, cell);
121
+ if (dotted === undefined || chosen === undefined)
122
+ return pixels;
123
+ if (!chosen.group) {
124
+ pixels.fill(dotted, SHARE_OF.selected);
125
+ return pixels;
126
+ }
127
+ // a second line inside the first: heavy, as the canvas draws a selected frame
128
+ pixels.outline(dotted, SHARE_OF.selected);
129
+ if (dotted.width > 2 && dotted.height > 2)
130
+ pixels.outline(inset(dotted, 1), SHARE_OF.selected);
101
131
  return pixels;
102
132
  }
103
133
  /** Whether the screen cell `at` is on the overview, its border included. */
@@ -1,8 +1,10 @@
1
1
  import type { DiagramModel } from '@diagc/core/internal';
2
2
  import { type ColorMode } from '../text/ansi.js';
3
3
  import type { Cell, CellRect } from '../text/canvas.js';
4
+ import { type TextStyle } from '../text/dos.js';
4
5
  import type { Scene } from '../text/scene.js';
5
6
  import type { FrameImage, Graphics } from './kitty.js';
7
+ import type { View } from './nav.js';
6
8
  import { type OverviewPlace } from './overview.js';
7
9
  import type { TuiState } from './state.js';
8
10
  /** The details panel's columns, its separator included. */
@@ -20,6 +22,8 @@ export interface FrameInput {
20
22
  notice?: string;
21
23
  /** the terminal shows images: the overview goes as one */
22
24
  graphics?: Graphics;
25
+ /** the style the screen is drawn in; absent = the terminal's own */
26
+ style?: TextStyle;
23
27
  }
24
28
  /** The canvas area the picture is drawn in: the rows between the title and the status,
25
29
  * less the panel's columns when it sits beside the picture. `reduce` reads the same. */
@@ -31,6 +35,12 @@ export declare function canvasSize(state: TuiState, size: Size): {
31
35
  /** Where the overview goes on this screen, whether or not it is on. `reduce` reads the
32
36
  * same, for clicks. */
33
37
  export declare function overviewPlaceOf(state: TuiState, scene: Scene | undefined, size: Size): OverviewPlace | undefined;
38
+ /** The canvas as the scroll reads it: its size, and the corner the overview's frame
39
+ * covers while it is on, which a selected box is kept out of and the scroll may run
40
+ * past the picture to uncover. `reduce` and `settle` read it. */
41
+ export declare function viewOf(state: TuiState, scene: Scene | undefined, size: Size): View & {
42
+ top: number;
43
+ };
34
44
  /** Where the legend goes on this screen, its border included, whether or not it is on:
35
45
  * kept off the overview while that is on. `reduce` reads the same, for clicks. */
36
46
  export declare function legendPlaceOf(state: TuiState, scene: Scene | undefined, size: Size): CellRect | undefined;
@@ -1,4 +1,5 @@
1
1
  import { serialize } from '../text/ansi.js';
2
+ import { BLACK, CYAN, DESKTOP, GREY, RED, SHADOW, SHADOW_REACH, WHITE } from '../text/dos.js';
2
3
  import { UNICODE } from '../text/glyphs.js';
3
4
  import { legendCells, legendSize } from '../text/legend.js';
4
5
  import { subtitleOf } from '../text/vocabulary.js';
@@ -28,6 +29,8 @@ const HELP = [
28
29
  ['i', 'details of the box'],
29
30
  ['o', 'overview on / off'],
30
31
  ['L', 'legend on / off'],
32
+ ['H', 'a git graph across / down'],
33
+ ['s', 'DOS style on / off'],
31
34
  ['Shift-arrows, PgUp, PgDn', 'scroll'],
32
35
  ['Home, End, mouse wheel', 'scroll'],
33
36
  ['click, double-click, drag', 'select, fold, pan'],
@@ -38,7 +41,40 @@ const HELP = [
38
41
  ];
39
42
  const INVERSE = { inverse: true };
40
43
  const DIM = { dim: true };
41
- const blankRow = (columns) => Array.from({ length: columns }, () => ({ ch: ' ', style: {} }));
44
+ /** The terminal's own look: its colours, with inverse for the bars. */
45
+ const CLEAN = {
46
+ title: INVERSE,
47
+ status: {},
48
+ hint: DIM,
49
+ error: { fg: { ansi: 9 }, bold: true },
50
+ ground: {},
51
+ current: INVERSE,
52
+ panel: {},
53
+ rule: DIM,
54
+ dialog: {},
55
+ border: {},
56
+ frame: ['┌', '┐', '└', '┘', '─', '│'],
57
+ };
58
+ const BAR = { fg: BLACK, bg: GREY };
59
+ /** Turbo Vision's: a grey menu bar and status line over the blue desktop, the list's
60
+ * row and the panel a cyan window, the help a grey dialog in a double frame. */
61
+ const DOS = {
62
+ title: BAR,
63
+ status: BAR,
64
+ hint: BAR,
65
+ error: { ...BAR, fg: RED, bold: true },
66
+ ground: DESKTOP,
67
+ current: { fg: BLACK, bg: CYAN },
68
+ panel: { fg: BLACK, bg: CYAN },
69
+ rule: { fg: BLACK, bg: CYAN },
70
+ dialog: BAR,
71
+ border: { fg: WHITE, bg: GREY },
72
+ frame: ['╔', '╗', '╚', '╝', '═', '║'],
73
+ shadow: SHADOW,
74
+ ink: WHITE.rgb,
75
+ };
76
+ const chromeOf = (input) => (input.style === 'dos' ? DOS : CLEAN);
77
+ const blankRow = (columns, style = {}) => Array.from({ length: columns }, () => ({ ch: ' ', style }));
42
78
  /** Before cell `i` is overwritten: if it is half of a wide character, blank the other
43
79
  * half, so an overlay over a wide character never leaves the row a cell short or
44
80
  * long. The canvas's `unwide`, for rows. */
@@ -129,6 +165,14 @@ function pictureShown(state, scene, size) {
129
165
  export function overviewPlaceOf(state, scene, size) {
130
166
  return pictureShown(state, scene, size) ? overviewPlace(scene.layout, canvasSize(state, size)) : undefined;
131
167
  }
168
+ /** The canvas as the scroll reads it: its size, and the corner the overview's frame
169
+ * covers while it is on, which a selected box is kept out of and the scroll may run
170
+ * past the picture to uncover. `reduce` and `settle` read it. */
171
+ export function viewOf(state, scene, size) {
172
+ const canvas = canvasSize(state, size);
173
+ const place = state.diagram?.overview === true ? overviewPlaceOf(state, scene, size) : undefined;
174
+ return place === undefined ? canvas : { ...canvas, corner: { width: place.width + 2, height: place.height + 2 } };
175
+ }
132
176
  /** Where the legend goes on this screen, its border included, whether or not it is on:
133
177
  * kept off the overview while that is on. `reduce` reads the same, for clicks. */
134
178
  export function legendPlaceOf(state, scene, size) {
@@ -160,7 +204,7 @@ export function overviewImage(state, input, size) {
160
204
  const { width, height } = canvasSize(state, size);
161
205
  const window = { scroll: d.scroll, width, height };
162
206
  const pixels = overviewPixels(scene.layout, { ...place, cell: graphics.cell }, window, d.selected);
163
- return { place, width: pixels.width, height: pixels.height, rgba: pixels.rgba(graphics.ink) };
207
+ return { place, width: pixels.width, height: pixels.height, rgba: pixels.rgba(chromeOf(input).ink ?? graphics.ink) };
164
208
  }
165
209
  function titleOf(d, model) {
166
210
  if (model === undefined)
@@ -179,18 +223,20 @@ function titleOf(d, model) {
179
223
  return parts.join(' · ');
180
224
  }
181
225
  function statusOf(d, input) {
226
+ const chrome = chromeOf(input);
182
227
  if (d.search?.editing === true)
183
- return [`/${d.search.query}_`, {}];
228
+ return [`/${d.search.query}_`, chrome.status];
184
229
  if (d.message !== undefined)
185
- return [d.message.text, d.message.error ? { fg: { ansi: 9 }, bold: true } : {}];
230
+ return [d.message.text, d.message.error ? chrome.error : chrome.status];
186
231
  const node = d.selected === undefined ? undefined : input.model?.nodes.find((n) => n.id === d.selected);
187
232
  if (node === undefined)
188
- return ['arrows move · Enter fold · > go in · / search · i details · ? help · q quit', DIM];
233
+ return ['arrows move · Enter fold · > go in · / search · i details · ? help · q quit', chrome.hint];
189
234
  const subtitle = printable(subtitleOf(node, input.scene?.notation));
190
235
  const name = printable(node.name);
191
- return [`${name}${subtitle === '' ? '' : ` ${subtitle}`} · Enter fold · i details · ? help`, {}];
236
+ return [`${name}${subtitle === '' ? '' : ` ${subtitle}`} · Enter fold · i details · ? help`, chrome.status];
192
237
  }
193
238
  function drawPanel(rows, d, input, size) {
239
+ const { panel, rule } = chromeOf(input);
194
240
  const beside = size.columns >= PANEL_MIN_COLUMNS;
195
241
  const left = beside ? size.columns - PANEL_WIDTH : 0;
196
242
  const width = beside ? PANEL_WIDTH - 3 : size.columns - 2;
@@ -200,12 +246,12 @@ function drawPanel(rows, d, input, size) {
200
246
  for (let r = 1; r < size.rows - 1; r++) {
201
247
  const row = rows[r];
202
248
  for (let c = left; c < size.columns; c++)
203
- row[c] = { ch: ' ', style: {} };
249
+ row[c] = { ch: ' ', style: panel };
204
250
  if (beside)
205
- row[left] = { ch: '│', style: DIM };
251
+ row[left] = { ch: '│', style: rule };
206
252
  const line = lines[r - 1];
207
253
  if (line !== undefined)
208
- write(row, left + (beside ? 2 : 1), line, { style: r === 1 ? { bold: true } : {} });
254
+ write(row, left + (beside ? 2 : 1), line, { style: r === 1 ? { ...panel, bold: true } : panel });
209
255
  }
210
256
  }
211
257
  /** The overview, opaque over the canvas, in a border a cell wide around `place`; blank
@@ -244,7 +290,22 @@ function drawLegend(rows, scene, place) {
244
290
  cells.forEach((cell, c) => write(row, place.x + c, cell.ch, { style: cell.style }));
245
291
  });
246
292
  }
247
- function drawHelp(rows, area) {
293
+ /** A dialog's shadow, where the chrome casts one: two columns right of `box` and a row
294
+ * below, as the DOS style's boxes cast theirs. */
295
+ function shade(rows, box, shadow) {
296
+ if (shadow === undefined)
297
+ return;
298
+ const [right, bottom] = [box.x + box.width, box.y + box.height];
299
+ for (let y = box.y + SHADOW_REACH.y; y < bottom + SHADOW_REACH.y; y++) {
300
+ const row = rows[y];
301
+ for (let x = box.x + SHADOW_REACH.x; x < right + SHADOW_REACH.x; x++) {
302
+ const cell = row?.[x];
303
+ if (cell !== undefined && (x >= right || y >= bottom))
304
+ row[x] = { ch: cell.ch, style: { ...cell.style, ...shadow } };
305
+ }
306
+ }
307
+ }
308
+ function drawHelp(rows, area, chrome) {
248
309
  const keyWidth = Math.max(...HELP.map(([k]) => cellWidth(k)));
249
310
  const lines = HELP.map(([k, what]) => `${k}${' '.repeat(keyWidth - cellWidth(k))} ${what}`);
250
311
  const width = Math.min(area.width, Math.max(...lines.map(cellWidth)) + 4);
@@ -253,20 +314,37 @@ function drawHelp(rows, area) {
253
314
  return;
254
315
  const x = (area.width - width) >> 1;
255
316
  const y = area.top + ((area.height - height) >> 1);
317
+ const [tl, tr, bl, br, across, down] = chrome.frame;
256
318
  for (let r = 0; r < height; r++) {
257
319
  const row = rows[y + r];
258
320
  const edge = r === 0 || r === height - 1;
259
- const [l, fill, rt] = r === 0 ? ['┌', '─', '┐'] : r === height - 1 ? ['└', '─', '┘'] : ['│', ' ', '│'];
260
- write(row, x, `${l}${fill.repeat(width - 2)}${rt}`);
321
+ const [l, rt] = r === 0 ? [tl, tr] : r === height - 1 ? [bl, br] : [down, down];
322
+ write(row, x, l, { style: chrome.border });
323
+ write(row, x + 1, (edge ? across : ' ').repeat(width - 2), { style: edge ? chrome.border : chrome.dialog });
324
+ write(row, x + width - 1, rt, { style: chrome.border });
261
325
  if (!edge)
262
- write(row, x + 2, lines[r - 1] ?? '', { maxX: x + width - 1 });
326
+ write(row, x + 2, lines[r - 1] ?? '', { style: chrome.dialog, maxX: x + width - 1 });
327
+ }
328
+ write(rows[y], x + 2, ' Keys ', { style: { ...chrome.border, bold: true }, maxX: x + width - 1 });
329
+ shade(rows, { x, y, width, height }, chrome.shadow);
330
+ }
331
+ /** The canvas's cells that set no background of their own, laid on the chrome's ground:
332
+ * the picture's lies on it already, but not what lies over the picture. */
333
+ function onGround(rows, area, ground) {
334
+ if (ground.bg === undefined)
335
+ return;
336
+ for (const row of rows.slice(area.top, area.top + area.height)) {
337
+ row.forEach((cell, c) => {
338
+ if (cell.style.bg === undefined)
339
+ row[c] = { ch: cell.ch, style: { ...ground, ...cell.style } };
340
+ });
263
341
  }
264
- write(rows[y], x + 2, ' Keys ', { style: { bold: true }, maxX: x + width - 1 });
265
342
  }
266
343
  function composeDiagram(d, input, size, places) {
267
- const rows = Array.from({ length: size.rows }, () => blankRow(size.columns));
344
+ const chrome = chromeOf(input);
345
+ const rows = Array.from({ length: size.rows }, () => blankRow(size.columns, chrome.ground));
268
346
  const area = places.canvas;
269
- rows[0] = bar(size.columns, titleOf(d, input.model), INVERSE);
347
+ rows[0] = bar(size.columns, titleOf(d, input.model), chrome.title);
270
348
  if (input.scene === undefined || input.canvas === undefined)
271
349
  centred(rows, area, input.notice ?? 'Loading…');
272
350
  else if (input.scene.layout.boxes.size === 0)
@@ -280,10 +358,11 @@ function composeDiagram(d, input, size, places) {
280
358
  if (d.legend && places.legend !== undefined)
281
359
  drawLegend(rows, input.scene, places.legend);
282
360
  }
361
+ onGround(rows, area, chrome.ground);
283
362
  if (d.panel && size.rows > 2)
284
363
  drawPanel(rows, d, input, size);
285
364
  if (d.help)
286
- drawHelp(rows, area);
365
+ drawHelp(rows, area, chrome);
287
366
  if (size.rows > 1) {
288
367
  const [text, style] = statusOf(d, input);
289
368
  rows[size.rows - 1] = bar(size.columns, fitCells(text, Math.max(0, size.columns - 2)), style);
@@ -291,9 +370,10 @@ function composeDiagram(d, input, size, places) {
291
370
  return rows;
292
371
  }
293
372
  function composeList(state, input, size) {
294
- const rows = Array.from({ length: size.rows }, () => blankRow(size.columns));
373
+ const chrome = chromeOf(input);
374
+ const rows = Array.from({ length: size.rows }, () => blankRow(size.columns, chrome.ground));
295
375
  const count = state.names.length;
296
- rows[0] = bar(size.columns, `diagc · ${count} diagram${count === 1 ? '' : 's'}`, INVERSE);
376
+ rows[0] = bar(size.columns, `diagc · ${count} diagram${count === 1 ? '' : 's'}`, chrome.title);
297
377
  const area = { top: 1, width: size.columns, height: Math.max(0, size.rows - 2) };
298
378
  if (count === 0)
299
379
  centred(rows, area, input.notice ?? 'No diagrams under .diagrams/src');
@@ -302,15 +382,17 @@ function composeList(state, input, size) {
302
382
  for (let r = 0; r < area.height && first + r < count; r++) {
303
383
  const current = first + r === state.index;
304
384
  // the marker as well as the inverse bar: a terminal may show no attributes at all
305
- const row = current ? bar(size.columns, `› ${state.names[first + r]}`, INVERSE) : blankRow(size.columns);
385
+ const name = state.names[first + r];
386
+ const row = current ? bar(size.columns, `› ${name}`, chrome.current) : blankRow(size.columns, chrome.ground);
306
387
  if (!current)
307
- write(row, 3, state.names[first + r]);
388
+ write(row, 3, name, { style: chrome.ground });
308
389
  rows[area.top + r] = row;
309
390
  }
391
+ onGround(rows, area, chrome.ground);
310
392
  // with names to show, a notice is what the last pick ran into, said in the status row
311
393
  const [status, style] = count > 0 && input.notice !== undefined
312
- ? [input.notice, { fg: { ansi: 9 }, bold: true }]
313
- : ['Enter open · ↑↓ move · r reload · q quit', DIM];
394
+ ? [input.notice, chrome.error]
395
+ : ['Enter open · ↑↓ move · s style · r reload · q quit', chrome.hint];
314
396
  if (size.rows > 1)
315
397
  rows[size.rows - 1] = bar(size.columns, fitCells(status, Math.max(0, size.columns - 2)), style);
316
398
  return rows;
@@ -1,8 +1,10 @@
1
1
  import { type DiagramModel, type LayoutOverlay } from '@diagc/core/internal';
2
2
  import type { CellPoint, CellRect } from '../text/canvas.js';
3
+ import type { TextStyle } from '../text/dos.js';
3
4
  import { type Pins } from '../text/folds.js';
4
5
  import type { SceneInput, Scene } from '../text/scene.js';
5
6
  import type { UserInput } from './keys.js';
7
+ import { type View } from './nav.js';
6
8
  import type { OverviewPlace } from './overview.js';
7
9
  /** One open diagram, as the reader sees it. None of it is saved. */
8
10
  export interface DiagramState {
@@ -45,6 +47,8 @@ export interface DiagramState {
45
47
  };
46
48
  /** scroll the selection into view once the layout it waits for arrives (`settle`) */
47
49
  follow?: boolean;
50
+ /** a git graph turned across the screen (`H`); absent = down it */
51
+ horizontal?: true;
48
52
  }
49
53
  export interface TuiState {
50
54
  screen: 'list' | 'diagram';
@@ -53,6 +57,9 @@ export interface TuiState {
53
57
  /** the list's current row */
54
58
  index: number;
55
59
  diagram?: DiagramState;
60
+ /** the style the reader picked, with `--style` or `s`, for every diagram; absent =
61
+ * each diagram's own */
62
+ style?: TextStyle;
56
63
  }
57
64
  /** What an event is read against: the open diagram's model and laid-out picture, the
58
65
  * canvas's place on the screen, and when the event came (ms). */
@@ -60,16 +67,16 @@ export interface Ctx {
60
67
  model?: DiagramModel;
61
68
  overlay?: LayoutOverlay;
62
69
  scene?: Scene;
63
- /** the canvas: its first screen row and its size */
64
- view: {
70
+ /** the canvas: its first screen row, its size and the overview's corner (`viewOf`) */
71
+ view: View & {
65
72
  top: number;
66
- width: number;
67
- height: number;
68
73
  };
69
74
  /** where the overview goes on this screen, whether or not it is on */
70
75
  overview?: OverviewPlace;
71
76
  /** where the legend goes on this screen, its border included, whether or not it is on */
72
77
  legend?: CellRect;
78
+ /** the style the diagram is drawn in; absent = the terminal's own */
79
+ style?: TextStyle;
73
80
  at: number;
74
81
  }
75
82
  export type Effect = {
@@ -89,12 +96,9 @@ export interface Reduced {
89
96
  /** A diagram as it opens, and as a plane switch reopens it: the plane's own layers and
90
97
  * the folds its layout saved, as the published page opens it. */
91
98
  export declare function openDiagram(name: string, model: DiagramModel, overlay: LayoutOverlay | undefined, plane?: string): DiagramState;
92
- /** What to lay out for `state`. */
93
- export declare function sceneInput(state: DiagramState, model: DiagramModel, overlay: LayoutOverlay | undefined): SceneInput;
99
+ /** What to lay out for `state`, in `style`. */
100
+ export declare function sceneInput(state: DiagramState, model: DiagramModel, overlay: LayoutOverlay | undefined, style?: TextStyle): SceneInput;
94
101
  /** `state` fitted to a new picture: a selection the picture no longer draws is gone,
95
102
  * one that asked to be followed is scrolled to, and the scroll stays on the picture. */
96
- export declare function settle(state: DiagramState, scene: Scene, view: {
97
- width: number;
98
- height: number;
99
- }): DiagramState;
103
+ export declare function settle(state: DiagramState, scene: Scene, view: View): DiagramState;
100
104
  export declare function reduce(state: TuiState, event: UserInput, ctx: Ctx): Reduced;
package/dist/tui/state.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { presetLayers } from '@diagc/core/internal';
2
2
  import { readerPins } from '../text/folds.js';
3
- import { onKey, onMouse } from './actions.js';
3
+ import { onKey, onMouse, otherStyle } from './actions.js';
4
4
  import { clampScroll, follow } from './nav.js';
5
5
  /** A diagram as it opens, and as a plane switch reopens it: the plane's own layers and
6
6
  * the folds its layout saved, as the published page opens it. */
@@ -18,8 +18,8 @@ export function openDiagram(name, model, overlay, plane) {
18
18
  legend: model.legend !== undefined,
19
19
  };
20
20
  }
21
- /** What to lay out for `state`. */
22
- export function sceneInput(state, model, overlay) {
21
+ /** What to lay out for `state`, in `style`. */
22
+ export function sceneInput(state, model, overlay, style) {
23
23
  const root = state.path.at(-1);
24
24
  return {
25
25
  model,
@@ -28,6 +28,8 @@ export function sceneInput(state, model, overlay) {
28
28
  ...(overlay !== undefined ? { overlay } : {}),
29
29
  ...(state.plane !== undefined ? { plane: state.plane } : {}),
30
30
  ...(root !== undefined ? { root } : {}),
31
+ ...(style !== undefined ? { style } : {}),
32
+ ...(state.horizontal === true ? { horizontal: true } : {}),
31
33
  };
32
34
  }
33
35
  /** `state` fitted to a new picture: a selection the picture no longer draws is gone,
@@ -55,6 +57,8 @@ function reduceList(state, event) {
55
57
  return stay(Math.min(last, state.index + 1));
56
58
  if (event.name === 'r')
57
59
  return { state, effects: [{ kind: 'reload' }] };
60
+ if (event.name === 's')
61
+ return { state: { ...state, style: otherStyle(state.style) }, effects: [] };
58
62
  const name = state.names[state.index];
59
63
  if (event.name === 'enter' && name !== undefined)
60
64
  return { state, effects: [{ kind: 'open', name }] };
@@ -66,7 +70,12 @@ export function reduce(state, event, ctx) {
66
70
  const { message: _cleared, ...diagram } = state.diagram;
67
71
  const step = event.kind === 'mouse' ? onMouse(diagram, ctx, event) : onKey(diagram, ctx, event);
68
72
  return {
69
- state: { ...state, diagram: step.diagram, ...(step.toList === true ? { screen: 'list' } : {}) },
73
+ state: {
74
+ ...state,
75
+ diagram: step.diagram,
76
+ ...(step.toList === true ? { screen: 'list' } : {}),
77
+ ...(step.style !== undefined ? { style: step.style } : {}),
78
+ },
70
79
  effects: step.effects,
71
80
  };
72
81
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diagc/cli",
3
- "version": "1.6.0",
3
+ "version": "1.8.0",
4
4
  "description": "Author software-architecture diagrams as code, compile them to a validated model, edit them in a local studio, and publish pages and images.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "author": "Bogdan Frankovskyi",
@@ -45,7 +45,7 @@
45
45
  "fast-glob": "^3.3.0",
46
46
  "jiti": "^2.0.0",
47
47
  "playwright-core": "^1.62.0",
48
- "@diagc/core": "1.6.0"
48
+ "@diagc/core": "1.8.0"
49
49
  },
50
50
  "publishConfig": {
51
51
  "access": "public"