@diagc/cli 1.6.0 → 1.7.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.
@@ -1,5 +1,6 @@
1
1
  import { parseColor } from './ansi.js';
2
2
  import { Canvas } from './canvas.js';
3
+ import { BLACK, castShadows, CYAN, DESKTOP, dosFill, dosSlots, inkOn, mixed, WHITE, YELLOW } from './dos.js';
3
4
  import { DOWN, LEFT, RIGHT, UP } from './glyphs.js';
4
5
  import { STEP, towardBox } from './layout.js';
5
6
  import { kindLook, typeLook } from './vocabulary.js';
@@ -22,26 +23,56 @@ export const rgb = (css) => {
22
23
  const parsed = css === undefined ? undefined : parseColor(css);
23
24
  return parsed === undefined ? undefined : { rgb: parsed };
24
25
  };
25
- /** A node's accent, as the renderer resolves it: its own colour, the one its notation
26
- * gives it (a lane's, a bone's), the model's colour for its type (or for every type),
27
- * then the notation's for the type. */
28
- export function accentCss(model, node, notation, accents) {
26
+ /** A node's own colour, as the renderer resolves it: its own, the one its notation
27
+ * gives it (a lane's, a bone's), the model's for its type (or for every type). */
28
+ export function colorCss(model, node, accents) {
29
29
  const typeColor = node.type !== undefined ? model.typeColors?.[node.type] : undefined;
30
- const byNotation = accents.nodes.get(node.id);
31
- return node.color ?? byNotation ?? typeColor ?? model.typeColors?.['*'] ?? typeLook(node.type, notation).accent;
30
+ return node.color ?? accents.nodes.get(node.id) ?? typeColor ?? model.typeColors?.['*'];
31
+ }
32
+ /** A node's accent: its own colour, then the notation's for the type. */
33
+ export function accentCss(model, node, notation, accents) {
34
+ return colorCss(model, node, accents) ?? typeLook(node.type, notation).accent;
32
35
  }
36
+ /** A node's own colour (`colorCss`), as the CSS a terminal has to read. */
37
+ const ownCss = (p, id) => colorCss(p.scene.input.model, p.scene.nodes.get(id).node, p.scene.accents);
33
38
  /** How a box's border is drawn: heavy when selected (and for a fork bar), dashed
34
- * for a boundary, in the node's accent. */
39
+ * for a boundary, in the node's accent. In DOS a frame is double: a box's white on its
40
+ * fill, an open group's in its own colour, never the palette's, and the selection's
41
+ * yellow. */
35
42
  function borderInk(p, id) {
36
43
  const box = p.scene.boxes.get(id);
44
+ if (p.dos !== undefined) {
45
+ const weight = box.shape === 'bar' ? 'heavy' : box.dashed ? 'dashed' : 'double';
46
+ const fg = id === p.selected ? YELLOW : isFrame(p.scene, id) ? (rgb(ownCss(p, id)) ?? WHITE) : WHITE;
47
+ return { weight, style: { fg } };
48
+ }
37
49
  const fg = rgb(accentCss(p.scene.input.model, p.scene.nodes.get(id).node, p.scene.notation, p.scene.accents));
38
50
  const weight = id === p.selected || box.shape === 'bar' ? 'heavy' : box.dashed ? 'dashed' : 'light';
39
51
  return { weight, style: fg !== undefined ? { fg } : {} };
40
52
  }
53
+ /** The corner a box's shape gives its frame; DOS has square ones only. */
54
+ const cornerOf = (p, id) => p.dos === undefined ? CORNER[p.scene.boxes.get(id).shape] : undefined;
41
55
  /** An open container's frame. Its title is written later (`drawTitle`). */
42
56
  function drawFrame(p, id, g) {
43
57
  const ink = borderInk(p, id);
44
- p.canvas.rect(g, ink.weight, ink.style, CORNER[p.scene.boxes.get(id).shape]);
58
+ p.canvas.rect(g, ink.weight, ink.style, cornerOf(p, id));
59
+ }
60
+ /** A box's fill in the DOS style (`dosFill`) and its ink; the small print is the ink 70%
61
+ * over the fill. */
62
+ function cardOf(p, slots, id) {
63
+ const fill = dosFill(p.scene.boxes.get(id).shape, ownCss(p, id), p.scene.nodes.get(id).node.type, slots);
64
+ const ink = inkOn(fill.rgb);
65
+ const small = { fg: mixed(ink.rgb, fill.rgb, 0.7) };
66
+ return { fill, ink, lines: { title: { bold: true }, subtitle: small, note: small, row: {} } };
67
+ }
68
+ /** A DOS box's ground: its fill under the whole box, a table's head cyan. */
69
+ function groundCard(p, box, g, card) {
70
+ p.canvas.ground(g, { bg: card.fill, fg: card.ink });
71
+ if (box.shape !== 'table')
72
+ return;
73
+ const head = box.lines.findIndex((line) => line.role === 'row');
74
+ const height = head < 0 ? box.lines.length : head;
75
+ p.canvas.ground({ x: g.x + 1, y: g.y + 1, width: g.width - 2, height }, { bg: CYAN, fg: BLACK });
45
76
  }
46
77
  /** An open container's title, in its top border. Written after the edges: a line that
47
78
  * crosses the border there loses a cell, where the other way round the title would
@@ -59,7 +90,10 @@ function drawBox(p, id, g, weight) {
59
90
  const ink = { ...borderInk(p, id), ...(weight !== undefined ? { weight } : {}) };
60
91
  const rule = (y) => p.canvas.segment({ x: g.x, y }, { x: g.x + g.width - 1, y }, ink.weight, ink.style);
61
92
  p.canvas.clear({ x: g.x + 1, y: g.y + 1, width: g.width - 2, height: g.height - 2 });
62
- p.canvas.rect(g, ink.weight, ink.style, CORNER[box.shape]);
93
+ const card = p.dos === undefined ? undefined : cardOf(p, p.dos, id);
94
+ if (card !== undefined)
95
+ groundCard(p, box, g, card);
96
+ p.canvas.rect(g, ink.weight, ink.style, cornerOf(p, id));
63
97
  let y = g.y + 1;
64
98
  if (box.shape === 'cylinder')
65
99
  rule(y++);
@@ -70,7 +104,9 @@ function drawBox(p, id, g, weight) {
70
104
  ruled = true;
71
105
  }
72
106
  const x = line.role === 'row' ? g.x + 2 : g.x + Math.floor((g.width - cellWidth(line.text)) / 2);
73
- const style = line.role === 'title' && id === p.selected ? { bold: true, inverse: true } : LINE_STYLE[line.role];
107
+ const style = line.role === 'title' && id === p.selected
108
+ ? { bold: true, inverse: true }
109
+ : (card?.lines ?? LINE_STYLE)[line.role];
74
110
  p.canvas.text({ x, y: y++ }, line.text, style, g.x + g.width - 1);
75
111
  }
76
112
  }
@@ -116,12 +152,14 @@ function drawEnd(p, edge, end) {
116
152
  const box = p.scene.layout.boxes.get(end === 'start' ? edge.from : edge.to);
117
153
  const mark = end === 'start' ? (look.start ?? 'none') : look.end;
118
154
  const ink = edgeInk(p, edge);
155
+ // in DOS a mark is white of its own, not the ground's, to stay bright in a shadow
156
+ const style = p.dos === undefined ? ink.style : { fg: WHITE, ...ink.style };
119
157
  if (mark === 'none')
120
158
  join(p, at, box, ink);
121
159
  else if (mark === 'arrow')
122
- p.canvas.put(at, p.glyphs.arrow(arrowOf(at, prev, box)), ink.style);
160
+ p.canvas.put(at, p.glyphs.arrow(arrowOf(at, prev, box)), style);
123
161
  else
124
- p.canvas.put(at, p.glyphs.mark(mark), ink.style);
162
+ p.canvas.put(at, p.glyphs.mark(mark), style);
125
163
  }
126
164
  const isFrame = (scene, id) => {
127
165
  const vn = scene.nodes.get(id);
@@ -150,6 +188,9 @@ function drawFishRoute(p, points, ink) {
150
188
  */
151
189
  function paintFish(p, fish, edges) {
152
190
  const { layout } = p.scene;
191
+ const boxes = [...layout.boxes].filter(([id]) => id !== fish.head && !fish.words.has(id));
192
+ if (p.dos !== undefined)
193
+ castShadows(p.canvas, [layout.boxes.get(fish.head), ...boxes.map(([, g]) => g)]);
153
194
  for (const edge of edges)
154
195
  drawFishRoute(p, layout.routes.get(edge.id).points, edgeInk(p, edge));
155
196
  drawBox(p, fish.head, layout.boxes.get(fish.head), 'heavy');
@@ -164,19 +205,28 @@ function paintFish(p, fish, edges) {
164
205
  for (const line of lines)
165
206
  p.canvas.text(line, line.text, style);
166
207
  }
167
- for (const [id, g] of layout.boxes)
168
- if (id !== fish.head && !fish.words.has(id))
169
- drawBox(p, id, g);
208
+ for (const [id, g] of boxes)
209
+ drawBox(p, id, g);
170
210
  }
211
+ /** An edge's label: in its line's ink, or in DOS yellow. */
212
+ const labelStyle = (p, edge) => {
213
+ const { style } = edgeInk(p, edge);
214
+ return p.dos === undefined ? style : { ...style, fg: YELLOW };
215
+ };
171
216
  /**
172
217
  * The scene as a canvas, in layers: open containers' frames from the outside in,
173
218
  * then the edges' lines, then the boxes over them (a box clears what is under it)
174
219
  * and the frames' titles, then edge labels and the ends of the edges, last so
175
- * nothing covers an arrowhead.
220
+ * nothing covers an arrowhead. In the DOS style (the scene's `style`) it all lies on
221
+ * the desktop, the boxes' shadows laid on it first.
176
222
  */
177
223
  export function paint(scene, options) {
178
224
  const { layout } = scene;
179
225
  const p = { canvas: new Canvas(layout.width, layout.height), scene, ...options };
226
+ if (scene.input.style === 'dos') {
227
+ p.dos = dosSlots(scene.input.model, scene.notation);
228
+ p.canvas.ground({ x: 0, y: 0, width: layout.width, height: layout.height }, DESKTOP);
229
+ }
180
230
  const drawn = [...scene.nodes.keys()].flatMap((id) => {
181
231
  const g = layout.boxes.get(id);
182
232
  return g === undefined ? [] : [{ id, g, frame: isFrame(scene, id) }];
@@ -186,6 +236,8 @@ export function paint(scene, options) {
186
236
  paintFish(p, layout.fish, edges);
187
237
  return p.canvas;
188
238
  }
239
+ if (p.dos !== undefined)
240
+ castShadows(p.canvas, drawn.filter((d) => !d.frame).map((d) => d.g));
189
241
  for (const { id, g, frame } of drawn)
190
242
  if (frame)
191
243
  drawFrame(p, id, g);
@@ -200,7 +252,7 @@ export function paint(scene, options) {
200
252
  for (const edge of edges) {
201
253
  const label = layout.routes.get(edge.id).label;
202
254
  if (label !== undefined)
203
- p.canvas.text(label, label.text, edgeInk(p, edge).style);
255
+ p.canvas.text(label, label.text, labelStyle(p, edge));
204
256
  drawEnd(p, edge, 'start');
205
257
  drawEnd(p, edge, 'end');
206
258
  }
@@ -1,6 +1,7 @@
1
1
  import { type CompiledView, type DiagramModel, type HierarchyIndex, type LayoutOverlay, type NotationId, type ViewNode } from '@diagc/core/internal';
2
2
  import { type Accents } from './accents.js';
3
3
  import { type BoxText } from './content.js';
4
+ import { type TextStyle } from './dos.js';
4
5
  import { type Pins } from './folds.js';
5
6
  import type { Glyphs } from './glyphs.js';
6
7
  import { type TextLayout } from './layout.js';
@@ -16,6 +17,9 @@ export interface SceneInput {
16
17
  pins: Pins;
17
18
  /** draw this container's interior only (the drill view) */
18
19
  root?: string;
20
+ /** the style it is drawn in; absent = the terminal's own. DOS's boxes cast shadows,
21
+ * which the picture leaves room for at its right and its foot. */
22
+ style?: TextStyle;
19
23
  }
20
24
  /** A laid-out view: everything painting and the TUI's navigation read. */
21
25
  export interface Scene {
@@ -1,6 +1,7 @@
1
1
  import { activeNotation, buildHierarchy, compileView, defined, defaultLayoutDirection, FISHBONE_NOTATION, layoutPlaneKey, presetLayers, } from '@diagc/core/internal';
2
2
  import { notationAccents } from './accents.js';
3
3
  import { boxText, edgeText } from './content.js';
4
+ import { SHADOW_REACH } from './dos.js';
4
5
  import { fishCells } from './fish.js';
5
6
  import { withNeverFolds } from './folds.js';
6
7
  import { layoutCells } from './layout.js';
@@ -12,6 +13,11 @@ function directionOf(input) {
12
13
  const saved = input.overlay?.settings?.[layoutPlaneKey(input.model, input.plane)]?.direction;
13
14
  return saved !== undefined && DIRECTIONS.has(saved) ? saved : defaultLayoutDirection(input.model);
14
15
  }
16
+ /** How the scene is laid out: its plane's flow, and room for DOS's shadows. */
17
+ const flowOf = (input) => ({
18
+ direction: directionOf(input),
19
+ ...(input.style === 'dos' ? { shadow: SHADOW_REACH } : {}),
20
+ });
15
21
  export async function buildScene(input, glyphs) {
16
22
  const { model, plane } = input;
17
23
  const notation = activeNotation(model.planes, plane, model.notation);
@@ -40,9 +46,11 @@ export async function buildScene(input, glyphs) {
40
46
  walk(root, undefined);
41
47
  const labels = new Map(view.layoutEdges.map((e) => [e.id, edgeText(e, glyphs)]));
42
48
  // A fishbone is the fish, as on the page, whatever way the plane's settings say to flow.
43
- const layout = notation === FISHBONE_NOTATION
49
+ const laid = notation === FISHBONE_NOTATION
44
50
  ? fishCells(model, view, boxes)
45
- : await layoutCells(view, boxes, directionOf(input), labels);
51
+ : await layoutCells(view, boxes, flowOf(input), labels);
52
+ const room = input.style === 'dos' && laid.boxes.size > 0;
53
+ const layout = room ? { ...laid, width: laid.width + SHADOW_REACH.x, height: laid.height + SHADOW_REACH.y } : laid;
46
54
  const accents = notationAccents(model, plane, notation, view.edges);
47
55
  const scene = { input, view, layout, boxes, nodes, parentOf, hierarchy, accents, ...defined({ notation }) };
48
56
  const legend = legendOf(scene, glyphs);
@@ -1,3 +1,4 @@
1
+ import type { TextStyle } from '../text/dos.js';
1
2
  import type { Key, Mouse } from './keys.js';
2
3
  import { type Ctx, type DiagramState, type Effect } from './state.js';
3
4
  export interface Step {
@@ -5,6 +6,10 @@ export interface Step {
5
6
  effects: Effect[];
6
7
  /** back to the list of diagrams */
7
8
  toList?: boolean;
9
+ /** the style the reader switched to, for this diagram and every one after it */
10
+ style?: TextStyle;
8
11
  }
12
+ /** The style `s` switches to from `style`: DOS from the terminal's own, and back. */
13
+ export declare const otherStyle: (style: TextStyle | undefined) => TextStyle;
9
14
  export declare function onKey(d: DiagramState, ctx: Ctx, key: Key): Step;
10
15
  export declare function onMouse(d: DiagramState, ctx: Ctx, mouse: Mouse): Step;
@@ -3,6 +3,8 @@ import { onLegend } from './legend.js';
3
3
  import { clampScroll, follow, hitTest, nearest, readingOrder } from './nav.js';
4
4
  import { onOverview, overviewJump } from './overview.js';
5
5
  import { openDiagram } from './state.js';
6
+ /** The style `s` switches to from `style`: DOS from the terminal's own, and back. */
7
+ export const otherStyle = (style) => (style === 'dos' ? 'clean' : 'dos');
6
8
  /** A second press on the same cell within this many ms is a double click. */
7
9
  const DOUBLE_CLICK_MS = 400;
8
10
  /** Rows a wheel notch scrolls; a sideways notch scrolls twice as many columns. */
@@ -217,6 +219,7 @@ const KEYS = {
217
219
  o: (d, ctx) => toggleOverview(d, ctx),
218
220
  L: (d, ctx) => toggleLegend(d, ctx),
219
221
  '?': (d) => stay({ ...d, help: !d.help }),
222
+ s: (d, ctx) => ({ diagram: d, effects: [{ kind: 'relayout' }], style: otherStyle(ctx.style) }),
220
223
  r: (d) => ({ diagram: d, effects: [{ kind: 'reload' }] }),
221
224
  q: (d) => ({ diagram: d, effects: [{ kind: 'quit' }] }),
222
225
  escape: (d) => escape(d),
package/dist/tui/app.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { ColorMode } from '../text/ansi.js';
2
+ import { type TextStyle } from '../text/dos.js';
2
3
  import type { Terminal } from './terminal.js';
3
4
  /** A diagram's source compiled (or failed to), or its layout changed. */
4
5
  export interface Change {
@@ -19,6 +20,8 @@ export interface TuiOptions {
19
20
  name?: string;
20
21
  watch: WatchStarter;
21
22
  color: ColorMode;
23
+ /** the style to draw every diagram in; absent = each diagram's own */
24
+ style?: TextStyle;
22
25
  now?: () => number;
23
26
  }
24
27
  /** The studio's compile-watch loop, for the TUI: sources compile into artifacts as they
package/dist/tui/app.js CHANGED
@@ -5,13 +5,14 @@ import { watch as chokidarWatch } from 'chokidar';
5
5
  import { errMessage, isLayoutOverlay } from '@diagc/core/internal';
6
6
  import { discoverDiagrams } from '../publish/discover.js';
7
7
  import { lockedResolverFor } from '../snapshots.js';
8
+ import { styleOf } from '../text/dos.js';
8
9
  import { UNICODE } from '../text/glyphs.js';
9
10
  import { paint } from '../text/paint.js';
10
11
  import { buildScene } from '../text/scene.js';
11
12
  import { startWatch } from '../watch.js';
12
13
  import { isReply, parseInput } from './keys.js';
13
14
  import { CELL_SIZE_QUERY, graphicsOf, hear, imageChange, TERMINAL_QUERY } from './kitty.js';
14
- import { canvasSize, composeFrame, frameText, legendPlaceOf, overviewImage, overviewPlaceOf } from './screen.js';
15
+ import { composeFrame, frameText, legendPlaceOf, overviewImage, overviewPlaceOf, viewOf } from './screen.js';
15
16
  import { openDiagram, reduce, sceneInput, settle } from './state.js';
16
17
  /** What makes the process end while the TUI owns the terminal; each gives it back. */
17
18
  const ENDINGS = ['SIGINT', 'SIGTERM', 'SIGHUP', 'uncaughtException', 'unhandledRejection'];
@@ -90,6 +91,8 @@ class App {
90
91
  };
91
92
  constructor(options) {
92
93
  this.options = options;
94
+ if (options.style !== undefined)
95
+ this.state.style = options.style;
93
96
  }
94
97
  run() {
95
98
  return new Promise((resolve, reject) => {
@@ -148,6 +151,14 @@ class App {
148
151
  size() {
149
152
  return { columns: this.options.terminal.columns, rows: this.options.terminal.rows };
150
153
  }
154
+ /** The style the screen is drawn in: the reader's pick, else the open diagram's own.
155
+ * Without colour it is the terminal's own, DOS being its colours more than its lines. */
156
+ style() {
157
+ if (this.options.color === 'none' || this.options.color === 'mono')
158
+ return 'clean';
159
+ const own = this.state.screen === 'diagram' && this.model !== undefined ? styleOf(this.model) : 'clean';
160
+ return this.state.style ?? own;
161
+ }
151
162
  draw() {
152
163
  if (this.finished)
153
164
  return;
@@ -158,6 +169,7 @@ class App {
158
169
  ...(this.canvas !== undefined ? { canvas: this.canvas } : {}),
159
170
  ...(this.notice !== undefined ? { notice: this.notice } : {}),
160
171
  ...(graphics !== undefined ? { graphics } : {}),
172
+ style: this.style(),
161
173
  };
162
174
  const size = this.size();
163
175
  const lines = composeFrame(this.state, input, size, this.options.color);
@@ -293,7 +305,7 @@ class App {
293
305
  return this.draw();
294
306
  let scene;
295
307
  try {
296
- scene = await buildScene(sceneInput(d, this.model, this.overlay), UNICODE);
308
+ scene = await buildScene(sceneInput(d, this.model, this.overlay, this.style()), UNICODE);
297
309
  }
298
310
  catch (e) {
299
311
  this.state = { ...this.state, diagram: { ...d, message: { text: errMessage(e), error: true } } };
@@ -303,7 +315,7 @@ class App {
303
315
  return;
304
316
  this.scene = scene;
305
317
  // the state as it is now: keys pressed while elk worked have moved it on
306
- this.state = { ...this.state, diagram: settle(this.state.diagram, scene, canvasSize(this.state, this.size())) };
318
+ this.state = { ...this.state, diagram: settle(this.state.diagram, scene, viewOf(this.state, scene, this.size())) };
307
319
  this.repaint();
308
320
  this.draw();
309
321
  }
@@ -333,9 +345,10 @@ class App {
333
345
  model: this.model,
334
346
  overlay: this.overlay,
335
347
  scene: this.scene,
336
- view: canvasSize(this.state, size),
348
+ view: viewOf(this.state, this.scene, size),
337
349
  overview: overviewPlaceOf(this.state, this.scene, size),
338
350
  legend: legendPlaceOf(this.state, this.scene, size),
351
+ style: this.style(),
339
352
  at: (this.options.now ?? Date.now)(),
340
353
  };
341
354
  const { state, effects } = reduce(this.state, event, ctx);
@@ -357,7 +370,7 @@ class App {
357
370
  if (this.state.diagram !== undefined && this.scene !== undefined) {
358
371
  this.state = {
359
372
  ...this.state,
360
- diagram: settle(this.state.diagram, this.scene, canvasSize(this.state, this.size())),
373
+ diagram: settle(this.state.diagram, this.scene, viewOf(this.state, this.scene, this.size())),
361
374
  };
362
375
  }
363
376
  this.draw();
package/dist/tui/nav.d.ts CHANGED
@@ -1,6 +1,16 @@
1
1
  import type { CellPoint } from '../text/canvas.js';
2
2
  import type { BoxGeometry } from '../text/layout.js';
3
3
  export type Direction = 'up' | 'down' | 'left' | 'right';
4
+ /** The window onto the picture: its size, and the bottom-right corner of it the
5
+ * overview covers while it is on. */
6
+ export interface View {
7
+ width: number;
8
+ height: number;
9
+ corner?: {
10
+ width: number;
11
+ height: number;
12
+ };
13
+ }
4
14
  /** The box to go to from `from` in `dir`: of those whose centre lies that way, the
5
15
  * nearest, where being off to the side counts double. */
6
16
  export declare function nearest(boxes: ReadonlyMap<string, BoxGeometry>, from: string, dir: Direction): string | undefined;
@@ -9,17 +19,13 @@ export declare function readingOrder(boxes: ReadonlyMap<string, BoxGeometry>): s
9
19
  /** The box a click at (x, y) means: the smallest that holds the cell, so a click
10
20
  * inside a child picks the child, not the container around it. */
11
21
  export declare function hitTest(boxes: ReadonlyMap<string, BoxGeometry>, x: number, y: number): string | undefined;
12
- /** The scroll that brings `box` into a view of `view`'s size, moving as little as it can. */
13
- export declare function follow(scroll: CellPoint, box: BoxGeometry, view: {
14
- width: number;
15
- height: number;
16
- }): CellPoint;
22
+ /** The scroll that brings `box` into `view`, out from under the overview, moving as
23
+ * little as it can. */
24
+ export declare function follow(scroll: CellPoint, box: BoxGeometry, view: View): CellPoint;
17
25
  /** `scroll` kept where the view still shows content: never before the start, never so
18
- * far that the view is past the end. */
26
+ * far that the view is past the end, but for the overview's corner: as far past the
27
+ * right and the bottom as that covers, so nothing has to stay under it. */
19
28
  export declare function clampScroll(scroll: CellPoint, content: {
20
29
  width: number;
21
30
  height: number;
22
- }, view: {
23
- width: number;
24
- height: number;
25
- }): CellPoint;
31
+ }, view: View): CellPoint;
package/dist/tui/nav.js CHANGED
@@ -64,16 +64,38 @@ function followAxis(at, start, size, span) {
64
64
  return high - span;
65
65
  return at;
66
66
  }
67
- /** The scroll that brings `box` into a view of `view`'s size, moving as little as it can. */
67
+ /** `scroll` moved on until `box` and its margin are clear of the view's corner: up or
68
+ * left of it, whichever is the shorter move that keeps the box's start on screen. */
69
+ function clearCorner(scroll, box, view) {
70
+ if (view.corner === undefined)
71
+ return scroll;
72
+ const left = box.x + box.width + MARGIN - (scroll.x + view.width - view.corner.width);
73
+ const up = box.y + box.height + MARGIN - (scroll.y + view.height - view.corner.height);
74
+ if (left <= 0 || up <= 0)
75
+ return scroll;
76
+ const byX = box.x >= scroll.x + left ? left : Infinity;
77
+ const byY = box.y >= scroll.y + up ? up : Infinity;
78
+ if (byX === Infinity && byY === Infinity)
79
+ return scroll;
80
+ return byY <= byX ? { x: scroll.x, y: scroll.y + byY } : { x: scroll.x + byX, y: scroll.y };
81
+ }
82
+ /** The scroll that brings `box` into `view`, out from under the overview, moving as
83
+ * little as it can. */
68
84
  export function follow(scroll, box, view) {
69
- return {
85
+ const seen = {
70
86
  x: followAxis(scroll.x, box.x, box.width, view.width),
71
87
  y: followAxis(scroll.y, box.y, box.height, view.height),
72
88
  };
89
+ return clearCorner(seen, box, view);
73
90
  }
74
91
  /** `scroll` kept where the view still shows content: never before the start, never so
75
- * far that the view is past the end. */
92
+ * far that the view is past the end, but for the overview's corner: as far past the
93
+ * right and the bottom as that covers, so nothing has to stay under it. */
76
94
  export function clampScroll(scroll, content, view) {
77
95
  const clamp = (v, max) => Math.max(0, Math.min(v, Math.max(0, max)));
78
- return { x: clamp(scroll.x, content.width - view.width), y: clamp(scroll.y, content.height - view.height) };
96
+ const room = view.corner ?? { width: 0, height: 0 };
97
+ return {
98
+ x: clamp(scroll.x, content.width + room.width - view.width),
99
+ y: clamp(scroll.y, content.height + room.height - view.height),
100
+ };
79
101
  }
@@ -31,11 +31,13 @@ export type PixelPlace = OverviewPlace & {
31
31
  cell: CellPixels;
32
32
  };
33
33
  /** The overview's cells, `place`'s size: each box's outline and the window's, what is
34
- * off screen dim and the selected box inverse, as it is on the canvas. */
34
+ * off screen dim and the selected box inverse, as it is on the canvas (a group, its
35
+ * frame). */
35
36
  export declare function overviewCells(layout: TextLayout, place: OverviewPlace, window: PictureWindow, selected?: string): Cell[][];
36
37
  /** The overview in pixels, `place`'s cells' worth: each box's outline and the lines
37
38
  * between them, what is off screen dimmed, the part on screen outlined and faintly
38
- * tinted, and the selected box filled in, as inverse fills it on the canvas. */
39
+ * tinted, and the selected box filled in, as inverse fills it on the canvas; a selected
40
+ * group framed heavy instead. */
39
41
  export declare function overviewPixels(layout: TextLayout, place: PixelPlace, window: PictureWindow, selected?: string): Pixels;
40
42
  /** Whether the screen cell `at` is on the overview, its border included. */
41
43
  export declare function onOverview(place: OverviewPlace, at: CellPoint): boolean;
@@ -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;