@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.
- package/README.md +8 -3
- package/assets/guide/git-graph.md +3 -0
- package/assets/guide/index.md +3 -3
- package/assets/skill/SKILL.md +1 -1
- package/assets/studio/assets/index-CB6jjAka.js +112 -0
- package/assets/studio/index.html +1 -1
- package/assets/viewer/index.html +23 -23
- package/dist/cli/parse.d.ts +8 -1
- package/dist/cli/parse.js +13 -1
- package/dist/cli/run.js +6 -2
- package/dist/cli.js +6 -2
- package/dist/commands/show.d.ts +1 -1
- package/dist/commands/show.js +12 -2
- package/dist/commands/tui.d.ts +1 -1
- package/dist/commands/tui.js +10 -2
- package/dist/text/ansi.js +11 -5
- package/dist/text/canvas.d.ts +9 -2
- package/dist/text/canvas.js +25 -7
- package/dist/text/dos.d.ts +69 -0
- package/dist/text/dos.js +93 -0
- package/dist/text/git.d.ts +52 -0
- package/dist/text/git.js +274 -0
- package/dist/text/glyphs.d.ts +4 -3
- package/dist/text/glyphs.js +18 -2
- package/dist/text/layout.d.ts +39 -1
- package/dist/text/layout.js +10 -7
- package/dist/text/legend.js +17 -13
- package/dist/text/paint.d.ts +6 -4
- package/dist/text/paint.js +164 -17
- package/dist/text/scene.d.ts +7 -0
- package/dist/text/scene.js +16 -4
- package/dist/tui/actions.d.ts +5 -0
- package/dist/tui/actions.js +17 -2
- package/dist/tui/app.d.ts +3 -0
- package/dist/tui/app.js +18 -5
- package/dist/tui/nav.d.ts +16 -10
- package/dist/tui/nav.js +26 -4
- package/dist/tui/overview.d.ts +4 -2
- package/dist/tui/overview.js +38 -8
- package/dist/tui/screen.d.ts +10 -0
- package/dist/tui/screen.js +105 -23
- package/dist/tui/state.d.ts +14 -10
- package/dist/tui/state.js +13 -4
- package/package.json +2 -2
- package/assets/studio/assets/index-DRsUukzt.js +0 -112
package/dist/text/paint.js
CHANGED
|
@@ -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
|
|
26
|
-
* gives it (a lane's, a bone's), the model's
|
|
27
|
-
|
|
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
|
-
|
|
31
|
-
|
|
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,
|
|
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.
|
|
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
|
|
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)),
|
|
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),
|
|
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,119 @@ 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
|
|
168
|
-
|
|
169
|
-
|
|
208
|
+
for (const [id, g] of boxes)
|
|
209
|
+
drawBox(p, id, g);
|
|
210
|
+
}
|
|
211
|
+
/** Text or a line in a node's own colour (`ownCss`), where it has one. */
|
|
212
|
+
const ownInk = (p, id) => {
|
|
213
|
+
const fg = rgb(ownCss(p, id));
|
|
214
|
+
return fg !== undefined ? { fg } : {};
|
|
215
|
+
};
|
|
216
|
+
/** Every cell a link or a lane's tail runs through, as `x,y`. */
|
|
217
|
+
function linedCells(p, git, edges) {
|
|
218
|
+
const lined = new Set();
|
|
219
|
+
const run = (a, b) => {
|
|
220
|
+
const [dx, dy] = [Math.sign(b.x - a.x), Math.sign(b.y - a.y)];
|
|
221
|
+
for (let i = 0; i <= Math.abs(b.x - a.x) + Math.abs(b.y - a.y); i++)
|
|
222
|
+
lined.add(`${a.x + i * dx},${a.y + i * dy}`);
|
|
223
|
+
};
|
|
224
|
+
for (const edge of edges) {
|
|
225
|
+
const { points } = p.scene.layout.routes.get(edge.id);
|
|
226
|
+
for (let i = 1; i < points.length; i++)
|
|
227
|
+
run(points[i - 1], points[i]);
|
|
228
|
+
}
|
|
229
|
+
for (const tail of git.tails)
|
|
230
|
+
run(tail.from, tail.to);
|
|
231
|
+
return lined;
|
|
232
|
+
}
|
|
233
|
+
/** A stage's frame, dim and dashed, or heavy when it is selected. It is stroked cell by
|
|
234
|
+
* cell and gives way where a line runs through it, so a lane's line runs in front of
|
|
235
|
+
* the frame rather than meeting it in a junction. */
|
|
236
|
+
function drawStageFrame(p, id, lined) {
|
|
237
|
+
const g = p.scene.layout.boxes.get(id);
|
|
238
|
+
const [weight, ink] = id === p.selected ? ['heavy', ownInk(p, id)] : ['dashed', { ...ownInk(p, id), dim: true }];
|
|
239
|
+
const [right, bottom] = [g.x + g.width - 1, g.y + g.height - 1];
|
|
240
|
+
const stroke = (x, y, mask) => {
|
|
241
|
+
if (!lined.has(`${x},${y}`))
|
|
242
|
+
p.canvas.stroke({ x, y }, mask, weight, ink);
|
|
243
|
+
};
|
|
244
|
+
for (let x = g.x; x <= right; x++) {
|
|
245
|
+
const mask = (x > g.x ? LEFT : 0) | (x < right ? RIGHT : 0);
|
|
246
|
+
for (const y of [g.y, bottom])
|
|
247
|
+
stroke(x, y, mask);
|
|
248
|
+
}
|
|
249
|
+
for (let y = g.y; y <= bottom; y++) {
|
|
250
|
+
const mask = (y > g.y ? UP : 0) | (y < bottom ? DOWN : 0);
|
|
251
|
+
for (const x of [g.x, right])
|
|
252
|
+
stroke(x, y, mask);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/** A lane's tail, cell by cell down the screen, where a one-cell segment would read as
|
|
256
|
+
* one across it. */
|
|
257
|
+
function drawTail(p, git, tail) {
|
|
258
|
+
const ink = ownInk(p, tail.lane);
|
|
259
|
+
if (!git.down)
|
|
260
|
+
return p.canvas.segment(tail.from, tail.to, 'dashed', ink);
|
|
261
|
+
for (let y = tail.from.y; y <= tail.to.y; y++)
|
|
262
|
+
p.canvas.stroke({ x: tail.from.x, y }, UP | DOWN, 'dashed', ink);
|
|
170
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* A git graph as its lanes (git.ts): the stages' frames first, then the links
|
|
266
|
+
* and the lanes' tails, then each commit's dot over the lines that meet it, its tag
|
|
267
|
+
* bold beside it, the lanes' names, the stages' titles in their frames' top borders,
|
|
268
|
+
* and last the boxes of what is on no lane. A dot, tag, name or title is selected in
|
|
269
|
+
* reverse, a stage's frame heavy.
|
|
270
|
+
*/
|
|
271
|
+
function paintGit(p, git, edges) {
|
|
272
|
+
const { layout } = p.scene;
|
|
273
|
+
const own = (id) => ownInk(p, id);
|
|
274
|
+
const chosen = (id, style) => (id === p.selected ? { ...style, inverse: true } : style);
|
|
275
|
+
const boxes = [...layout.boxes].filter(([id]) => !git.dots.has(id) && !git.names.has(id) && !git.stages.has(id));
|
|
276
|
+
if (p.dos !== undefined)
|
|
277
|
+
castShadows(p.canvas, boxes.map(([, g]) => g));
|
|
278
|
+
const lined = linedCells(p, git, edges);
|
|
279
|
+
for (const id of git.stages.keys())
|
|
280
|
+
drawStageFrame(p, id, lined);
|
|
281
|
+
for (const edge of edges) {
|
|
282
|
+
const { points } = layout.routes.get(edge.id);
|
|
283
|
+
const ink = edgeInk(p, edge);
|
|
284
|
+
for (let i = 1; i < points.length; i++)
|
|
285
|
+
p.canvas.segment(points[i - 1], points[i], ink.weight, ink.style);
|
|
286
|
+
}
|
|
287
|
+
for (const tail of git.tails)
|
|
288
|
+
drawTail(p, git, tail);
|
|
289
|
+
for (const [id, dot] of git.dots)
|
|
290
|
+
p.canvas.put(dot, p.glyphs.start, chosen(id, own(id)));
|
|
291
|
+
for (const [id, tag] of git.tags)
|
|
292
|
+
p.canvas.text(tag, tag.text, chosen(id, { ...own(id), bold: true }));
|
|
293
|
+
for (const [id, name] of git.names)
|
|
294
|
+
p.canvas.text(name, name.text, chosen(id, { ...own(id), bold: true }));
|
|
295
|
+
for (const [id, title] of git.stages) {
|
|
296
|
+
const g = layout.boxes.get(id);
|
|
297
|
+
p.canvas.text(title, ` ${title.text} `, chosen(id, { ...own(id), bold: true }), g.x + g.width - 2);
|
|
298
|
+
}
|
|
299
|
+
for (const [id, g] of boxes)
|
|
300
|
+
drawBox(p, id, g);
|
|
301
|
+
}
|
|
302
|
+
/** An edge's label: in its line's ink, or in DOS yellow. */
|
|
303
|
+
const labelStyle = (p, edge) => {
|
|
304
|
+
const { style } = edgeInk(p, edge);
|
|
305
|
+
return p.dos === undefined ? style : { ...style, fg: YELLOW };
|
|
306
|
+
};
|
|
171
307
|
/**
|
|
172
308
|
* The scene as a canvas, in layers: open containers' frames from the outside in,
|
|
173
309
|
* then the edges' lines, then the boxes over them (a box clears what is under it)
|
|
174
310
|
* and the frames' titles, then edge labels and the ends of the edges, last so
|
|
175
|
-
* nothing covers an arrowhead.
|
|
311
|
+
* nothing covers an arrowhead. In the DOS style (the scene's `style`) it all lies on
|
|
312
|
+
* the desktop, the boxes' shadows laid on it first.
|
|
176
313
|
*/
|
|
177
314
|
export function paint(scene, options) {
|
|
178
315
|
const { layout } = scene;
|
|
179
316
|
const p = { canvas: new Canvas(layout.width, layout.height), scene, ...options };
|
|
317
|
+
if (scene.input.style === 'dos') {
|
|
318
|
+
p.dos = dosSlots(scene.input.model, scene.notation);
|
|
319
|
+
p.canvas.ground({ x: 0, y: 0, width: layout.width, height: layout.height }, DESKTOP);
|
|
320
|
+
}
|
|
180
321
|
const drawn = [...scene.nodes.keys()].flatMap((id) => {
|
|
181
322
|
const g = layout.boxes.get(id);
|
|
182
323
|
return g === undefined ? [] : [{ id, g, frame: isFrame(scene, id) }];
|
|
@@ -186,6 +327,12 @@ export function paint(scene, options) {
|
|
|
186
327
|
paintFish(p, layout.fish, edges);
|
|
187
328
|
return p.canvas;
|
|
188
329
|
}
|
|
330
|
+
if (layout.git !== undefined) {
|
|
331
|
+
paintGit(p, layout.git, edges);
|
|
332
|
+
return p.canvas;
|
|
333
|
+
}
|
|
334
|
+
if (p.dos !== undefined)
|
|
335
|
+
castShadows(p.canvas, drawn.filter((d) => !d.frame).map((d) => d.g));
|
|
189
336
|
for (const { id, g, frame } of drawn)
|
|
190
337
|
if (frame)
|
|
191
338
|
drawFrame(p, id, g);
|
|
@@ -200,7 +347,7 @@ export function paint(scene, options) {
|
|
|
200
347
|
for (const edge of edges) {
|
|
201
348
|
const label = layout.routes.get(edge.id).label;
|
|
202
349
|
if (label !== undefined)
|
|
203
|
-
p.canvas.text(label, label.text,
|
|
350
|
+
p.canvas.text(label, label.text, labelStyle(p, edge));
|
|
204
351
|
drawEnd(p, edge, 'start');
|
|
205
352
|
drawEnd(p, edge, 'end');
|
|
206
353
|
}
|
package/dist/text/scene.d.ts
CHANGED
|
@@ -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,12 @@ 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;
|
|
23
|
+
/** a git graph across the screen, its lanes rows, as the page draws it; absent = down
|
|
24
|
+
* the screen, its lanes columns, as a terminal reads a history */
|
|
25
|
+
horizontal?: boolean;
|
|
19
26
|
}
|
|
20
27
|
/** A laid-out view: everything painting and the TUI's navigation read. */
|
|
21
28
|
export interface Scene {
|
package/dist/text/scene.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { activeNotation, buildHierarchy, compileView, defined, defaultLayoutDirection, FISHBONE_NOTATION, layoutPlaneKey, presetLayers, } from '@diagc/core/internal';
|
|
1
|
+
import { activeNotation, buildHierarchy, compileView, defined, defaultLayoutDirection, FISHBONE_NOTATION, GIT_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';
|
|
7
|
+
import { gitCells } from './git.js';
|
|
6
8
|
import { layoutCells } from './layout.js';
|
|
7
9
|
import { legendOf } from './legend.js';
|
|
8
10
|
import { hidesKind } from './vocabulary.js';
|
|
@@ -12,6 +14,11 @@ function directionOf(input) {
|
|
|
12
14
|
const saved = input.overlay?.settings?.[layoutPlaneKey(input.model, input.plane)]?.direction;
|
|
13
15
|
return saved !== undefined && DIRECTIONS.has(saved) ? saved : defaultLayoutDirection(input.model);
|
|
14
16
|
}
|
|
17
|
+
/** How the scene is laid out: its plane's flow, and room for DOS's shadows. */
|
|
18
|
+
const flowOf = (input) => ({
|
|
19
|
+
direction: directionOf(input),
|
|
20
|
+
...(input.style === 'dos' ? { shadow: SHADOW_REACH } : {}),
|
|
21
|
+
});
|
|
15
22
|
export async function buildScene(input, glyphs) {
|
|
16
23
|
const { model, plane } = input;
|
|
17
24
|
const notation = activeNotation(model.planes, plane, model.notation);
|
|
@@ -39,10 +46,15 @@ export async function buildScene(input, glyphs) {
|
|
|
39
46
|
for (const root of view.roots)
|
|
40
47
|
walk(root, undefined);
|
|
41
48
|
const labels = new Map(view.layoutEdges.map((e) => [e.id, edgeText(e, glyphs)]));
|
|
42
|
-
// A fishbone is the fish
|
|
43
|
-
|
|
49
|
+
// A fishbone is the fish and a git graph its lanes, whatever way the plane's
|
|
50
|
+
// settings say to flow.
|
|
51
|
+
const laid = notation === FISHBONE_NOTATION
|
|
44
52
|
? fishCells(model, view, boxes)
|
|
45
|
-
:
|
|
53
|
+
: notation === GIT_NOTATION
|
|
54
|
+
? gitCells(model, view, boxes, defined({ plane, across: input.horizontal }))
|
|
55
|
+
: await layoutCells(view, boxes, flowOf(input), labels);
|
|
56
|
+
const room = input.style === 'dos' && laid.boxes.size > 0;
|
|
57
|
+
const layout = room ? { ...laid, width: laid.width + SHADOW_REACH.x, height: laid.height + SHADOW_REACH.y } : laid;
|
|
46
58
|
const accents = notationAccents(model, plane, notation, view.edges);
|
|
47
59
|
const scene = { input, view, layout, boxes, nodes, parentOf, hierarchy, accents, ...defined({ notation }) };
|
|
48
60
|
const legend = legendOf(scene, glyphs);
|
package/dist/tui/actions.d.ts
CHANGED
|
@@ -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;
|
package/dist/tui/actions.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { GIT_NOTATION } from '@diagc/core/internal';
|
|
1
2
|
import { neverFolds } from '../text/vocabulary.js';
|
|
2
3
|
import { onLegend } from './legend.js';
|
|
3
4
|
import { clampScroll, follow, hitTest, nearest, readingOrder } from './nav.js';
|
|
4
5
|
import { onOverview, overviewJump } from './overview.js';
|
|
5
6
|
import { openDiagram } from './state.js';
|
|
7
|
+
/** The style `s` switches to from `style`: DOS from the terminal's own, and back. */
|
|
8
|
+
export const otherStyle = (style) => (style === 'dos' ? 'clean' : 'dos');
|
|
6
9
|
/** A second press on the same cell within this many ms is a double click. */
|
|
7
10
|
const DOUBLE_CLICK_MS = 400;
|
|
8
11
|
/** Rows a wheel notch scrolls; a sideways notch scrolls twice as many columns. */
|
|
@@ -87,8 +90,18 @@ function switchPlane(d, ctx, step) {
|
|
|
87
90
|
const at = Math.max(0, planes.findIndex((p) => p.id === (d.plane ?? planes[0].id)));
|
|
88
91
|
const plane = planes[(at + step + planes.length) % planes.length];
|
|
89
92
|
// what the reader has open or shut stays as it was; the view is the new plane's
|
|
90
|
-
const { panel, overview, legend } = d;
|
|
91
|
-
|
|
93
|
+
const { panel, overview, legend, horizontal } = d;
|
|
94
|
+
const kept = { panel, overview, legend, ...(horizontal === true ? { horizontal } : {}) };
|
|
95
|
+
return relayout({ ...openDiagram(d.name, ctx.model, ctx.overlay, plane.id), ...kept });
|
|
96
|
+
}
|
|
97
|
+
/** A git graph turned across the screen, or back down it, the selection kept in view;
|
|
98
|
+
* anything else says it does not turn, or the key would seem to do nothing. */
|
|
99
|
+
function turnGit(d, ctx) {
|
|
100
|
+
if (ctx.scene?.notation !== GIT_NOTATION)
|
|
101
|
+
return say(d, 'only a git graph turns across the screen');
|
|
102
|
+
const { horizontal, ...rest } = d;
|
|
103
|
+
const turned = horizontal === true ? rest : { ...rest, horizontal: true };
|
|
104
|
+
return relayout({ ...turned, scroll: { x: 0, y: 0 }, ...(d.selected !== undefined ? { follow: true } : {}) });
|
|
92
105
|
}
|
|
93
106
|
function toggleLayer(d, ctx, n) {
|
|
94
107
|
const layer = ctx.model?.layers[n - 1];
|
|
@@ -216,7 +229,9 @@ const KEYS = {
|
|
|
216
229
|
i: (d) => stay({ ...d, panel: !d.panel }),
|
|
217
230
|
o: (d, ctx) => toggleOverview(d, ctx),
|
|
218
231
|
L: (d, ctx) => toggleLegend(d, ctx),
|
|
232
|
+
H: (d, ctx) => turnGit(d, ctx),
|
|
219
233
|
'?': (d) => stay({ ...d, help: !d.help }),
|
|
234
|
+
s: (d, ctx) => ({ diagram: d, effects: [{ kind: 'relayout' }], style: otherStyle(ctx.style) }),
|
|
220
235
|
r: (d) => ({ diagram: d, effects: [{ kind: 'reload' }] }),
|
|
221
236
|
q: (d) => ({ diagram: d, effects: [{ kind: 'quit' }] }),
|
|
222
237
|
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 {
|
|
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,
|
|
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:
|
|
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,
|
|
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
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
/**
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|
package/dist/tui/overview.d.ts
CHANGED
|
@@ -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;
|