flagstaff 1.0.3 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -4
- package/dist/builtins.js +1 -1
- package/dist/diff.d.ts +7 -0
- package/dist/diff.js +40 -0
- package/dist/log-tail.d.ts +15 -0
- package/dist/log-tail.js +45 -0
- package/dist/loop.d.ts +8 -2
- package/dist/loop.js +2 -1
- package/dist/markdown.d.ts +23 -0
- package/dist/markdown.js +110 -0
- package/dist/projection.d.ts +16 -0
- package/dist/projection.js +58 -10
- package/dist/schema.json +1 -1
- package/dist/tab-bar.d.ts +13 -0
- package/dist/tab-bar.js +28 -0
- package/dist/tasks.js +1 -2
- package/package.json +26 -6
package/README.md
CHANGED
|
@@ -167,6 +167,76 @@ table([['ora', '99'], ['log-update', '99']], { head: ['host', 'tests'] });
|
|
|
167
167
|
No layout engine, and there will not be one: these measure with `width()`, wrap with
|
|
168
168
|
`wrap()`, and join strings.
|
|
169
169
|
|
|
170
|
+
### A log tail and a tab bar
|
|
171
|
+
|
|
172
|
+
Two output-only components for screens built on flagstaff — controlroom's panes, or a plain
|
|
173
|
+
scrolling terminal. Neither reads a key.
|
|
174
|
+
|
|
175
|
+
```js
|
|
176
|
+
import { logTail } from 'flagstaff/log-tail';
|
|
177
|
+
import { tabBar } from 'flagstaff/tab-bar';
|
|
178
|
+
|
|
179
|
+
hoist(logTail({ height: 5 }), rt, { lines: [{ step: 'Installing' }, 'npm install', 'added 12 packages'] });
|
|
180
|
+
hoist(tabBar(), rt, { tabs: ['Status', 'Tail logs', 'Visualizer'], active: 1 });
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
| component | on a terminal | everywhere else |
|
|
184
|
+
| :-- | :-- | :-- |
|
|
185
|
+
| `logTail` | the last _n_ rows, `┊` before each line, `◆` on the step in progress — pinned to the top once it scrolls out | the whole stream, **appended**: each new line printed once, nothing repainted |
|
|
186
|
+
| `tabBar` | `Status · Tail logs · Visualizer`, the active tab styled through roundel's `heading` (bracketed without colour) | the active tab's label |
|
|
187
|
+
|
|
188
|
+
Importing either registers its built-in (`log-tail`, `tab-bar`) through the same public
|
|
189
|
+
`register()` a plugin uses, so a plugin can replace it; the `┊` and `◆` marks are the `tail`
|
|
190
|
+
and `step` glyphs. The task list's pending mark is the `pending` glyph too — a space unless a
|
|
191
|
+
plugin sets one, `◻` say.
|
|
192
|
+
|
|
193
|
+
### A streamed reply and a diff
|
|
194
|
+
|
|
195
|
+
Two components for chat-style programs, where a model's reply arrives a token at a time and an
|
|
196
|
+
edit is shown before it is written.
|
|
197
|
+
|
|
198
|
+
```js
|
|
199
|
+
import { markdown } from 'flagstaff/markdown';
|
|
200
|
+
import { diff } from 'flagstaff/diff';
|
|
201
|
+
|
|
202
|
+
let text = '';
|
|
203
|
+
const reply = hoist(markdown(), rt, { text });
|
|
204
|
+
for await (const token of stream) reply.update({ text: (text += token) });
|
|
205
|
+
reply.lower({ text, done: true });
|
|
206
|
+
|
|
207
|
+
hoist(diff(), rt, { diff: patch }).lower();
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
| component | on a terminal | everywhere else |
|
|
211
|
+
| :-- | :-- | :-- |
|
|
212
|
+
| `markdown` | the reply so far: headings, lists, emphasis, inline code and fenced code styled through roundel; with no colour, the source as written | the markdown's own source, **committed a block at a time** — each block printed once, when a later line closes it |
|
|
213
|
+
| `diff` | old and new line numbers on every line, removals and additions coloured | the diff unchanged, byte for byte |
|
|
214
|
+
|
|
215
|
+
A block is committed only by a complete line — a blank line, a heading, a fence, a closing
|
|
216
|
+
fence — so wherever the stream is cut, the blocks committed so far are the whole reply's first
|
|
217
|
+
blocks; the suite cuts a fixture at every byte offset and holds that. There is no syntax
|
|
218
|
+
highlighting inside a fence. `markdownBlocks(text, done)` is exported for a program that
|
|
219
|
+
places committed blocks itself, as controlroom's inline screen does.
|
|
220
|
+
|
|
221
|
+
### Writing a whole frame
|
|
222
|
+
|
|
223
|
+
`hoist` repaints one component. A program that lays several out in one frame paints the frame
|
|
224
|
+
through the same writer `hoist` uses:
|
|
225
|
+
|
|
226
|
+
```js
|
|
227
|
+
import { frameWriter } from 'flagstaff/loop';
|
|
228
|
+
|
|
229
|
+
const frame = frameWriter(process.stdout);
|
|
230
|
+
frame.paint(['Status · Tail logs', '┊ npm install', '┊ added 12 packages']);
|
|
231
|
+
frame.paint(['Status · Tail logs', '┊ npm install', '┊ added 13 packages']); // rewrites one row
|
|
232
|
+
frame.release(); // the frame stays on screen as scrollback
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
`paint` writes only the rows that changed since the last paint, inside one synchronized-output
|
|
236
|
+
block (`ESC[?2026h … ESC[?2026l`), so a terminal that supports it never shows a half-drawn
|
|
237
|
+
frame and one that does not ignores the two sequences. It is the only grid-writing code in the
|
|
238
|
+
family: controlroom composites through it rather than painting on its own.
|
|
239
|
+
|
|
170
240
|
### Bringing a corpus with you
|
|
171
241
|
|
|
172
242
|
The ecosystem already has ~80 spinner styles and eight border sets, as plain JSON. Neither
|
|
@@ -204,7 +274,7 @@ printed before the rendering that would justify it:
|
|
|
204
274
|
```text
|
|
205
275
|
nyan — 1 spinner, 0 borders, 0 components, 0 glyphs, 0 tokens
|
|
206
276
|
spinner nyan
|
|
207
|
-
tty ␛[?25l≋ working␛[1G␛[0J…
|
|
277
|
+
tty ␛[?25l␛[?2026h≋ working␛[?2026l␛[?2026h␛[1G␛[0J…
|
|
208
278
|
pipe ~nyan~ working⏎ ✔ done⏎
|
|
209
279
|
…
|
|
210
280
|
nyan: ok
|
|
@@ -253,7 +323,7 @@ Everything else stays: `ora({ text, spinner, color, indent, prefixText, suffixTe
|
|
|
253
323
|
the `spinners` corpus, the stream hooks that keep a `console.log` above the frame, the
|
|
254
324
|
synchronized-output sequences, the render deferral, the stdin discarder.
|
|
255
325
|
|
|
256
|
-
What changes is the bill. ora 9.4.1 ships
|
|
326
|
+
What changes is the bill. ora 9.4.1 ships 114,102 B of JavaScript across **seventeen
|
|
257
327
|
packages** — ora, chalk, cli-spinners, string-width, log-symbols, cli-cursor,
|
|
258
328
|
restore-cursor, onetime, mimic-function, signal-exit, is-interactive, is-unicode-supported,
|
|
259
329
|
stdin-discarder, yoctocolors, strip-ansi, ansi-regex, get-east-asian-width. `flagstaff/ora`
|
|
@@ -444,7 +514,7 @@ export, with its types, is on [flagstaff.interlace.tools](https://flagstaff.inte
|
|
|
444
514
|
|
|
445
515
|
Plugins register under the `tokens`, `glyphs`, `spinners`, `borders`, `components` keys, against the one schema the whole family shares.
|
|
446
516
|
|
|
447
|
-
|
|
517
|
+
`controlroom` builds on it, and it builds on `closeout`, `linegauge`, `paratext`, `roundel`.
|
|
448
518
|
|
|
449
519
|
## The family
|
|
450
520
|
|
|
@@ -463,7 +533,7 @@ takes a dependency from outside the family.
|
|
|
463
533
|
| [seniority](https://seniority.interlace.tools/docs) | Configuration precedence and discovery, with provenance | cosmiconfig, dotenv and rc |
|
|
464
534
|
| [closeout](https://closeout.interlace.tools/docs) | Exit handlers, terminal restore and a bounded shutdown | signal-exit, exit-hook and restore-cursor |
|
|
465
535
|
| [bellpull](https://bellpull.interlace.tools/docs) | Subprocesses, and which executable actually ran | cross-spawn and which |
|
|
466
|
-
| [controlroom](https://burgee.interlace.tools/docs/packages/controlroom) |
|
|
536
|
+
| [controlroom](https://burgee.interlace.tools/docs/packages/controlroom) | Full-screen, keyboard-driven terminal screens | ink, graded by ink's own suite |
|
|
467
537
|
|
|
468
538
|
Every migration guide, and the family-wide [compatibility](https://burgee.interlace.tools/docs/compatibility)
|
|
469
539
|
and [benchmarks](https://burgee.interlace.tools/docs/benchmarks) pages, are on
|
package/dist/builtins.js
CHANGED
|
@@ -3,7 +3,7 @@ const LINE_INTERVAL = 130;
|
|
|
3
3
|
export const builtins = {
|
|
4
4
|
name: 'flagstaff',
|
|
5
5
|
contract: 1,
|
|
6
|
-
glyphs: { running: '…', ok: '✔', fail: '✖', warn: '⚠', info: 'ℹ' },
|
|
6
|
+
glyphs: { running: '…', ok: '✔', fail: '✖', warn: '⚠', info: 'ℹ', pending: ' ', tail: '┊', step: '◆' },
|
|
7
7
|
spinners: {
|
|
8
8
|
dots: { frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'], interval: DOTS_INTERVAL, static: '…' },
|
|
9
9
|
line: { frames: ['-', '\\', '|', '/'], interval: LINE_INTERVAL, static: '…' },
|
package/dist/diff.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Component } from './plugin.js';
|
|
2
|
+
export interface DiffState {
|
|
3
|
+
/** A unified diff, as `git diff` or `diff -u` prints it. */
|
|
4
|
+
diff: string;
|
|
5
|
+
}
|
|
6
|
+
/** A unified diff: unchanged off a terminal, numbered and coloured on one. */
|
|
7
|
+
export declare function diff(): Component<DiffState>;
|
package/dist/diff.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { error, hint, muted, ok } from 'roundel/tokens';
|
|
2
|
+
const HUNK = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
|
|
3
|
+
function rows(diff) {
|
|
4
|
+
let old = 0;
|
|
5
|
+
let next = 0;
|
|
6
|
+
let oldLeft = 0;
|
|
7
|
+
let newLeft = 0;
|
|
8
|
+
return diff.split('\n').map((line) => {
|
|
9
|
+
const mark = line[0];
|
|
10
|
+
if ((oldLeft > 0 || newLeft > 0) && mark !== '\\') {
|
|
11
|
+
const inOld = mark !== '+';
|
|
12
|
+
const inNew = mark !== '-';
|
|
13
|
+
const paint = inOld ? error : ok;
|
|
14
|
+
const row = { old: inOld ? String(old) : '', new: inNew ? String(next) : '', text: inOld && inNew ? line : paint(line) };
|
|
15
|
+
old += Number(inOld);
|
|
16
|
+
oldLeft -= Number(inOld);
|
|
17
|
+
next += Number(inNew);
|
|
18
|
+
newLeft -= Number(inNew);
|
|
19
|
+
return row;
|
|
20
|
+
}
|
|
21
|
+
const hunk = HUNK.exec(line);
|
|
22
|
+
if (hunk !== null) {
|
|
23
|
+
[old, oldLeft, next, newLeft] = [Number(hunk[1]), Number(hunk[2] ?? 1), Number(hunk[3]), Number(hunk[4] ?? 1)];
|
|
24
|
+
return { old: '', new: '', text: hint(line) };
|
|
25
|
+
}
|
|
26
|
+
return { old: '', new: '', text: muted(line) };
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const body = (diff) => (diff.endsWith('\n') ? diff.slice(0, -1) : diff);
|
|
30
|
+
export function diff() {
|
|
31
|
+
return {
|
|
32
|
+
name: 'diff',
|
|
33
|
+
static: (state) => body(state.diff),
|
|
34
|
+
frame: (_t, state) => {
|
|
35
|
+
const numbered = rows(body(state.diff));
|
|
36
|
+
const gutter = Math.max(...numbered.map((row) => Math.max(row.old.length, row.new.length)));
|
|
37
|
+
return numbered.map((row) => `${muted(`${row.old.padStart(gutter)} ${row.new.padStart(gutter)} │`)} ${row.text}`).join('\n');
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Component } from './plugin.js';
|
|
2
|
+
/** One entry of the stream: a line of output, or the start of a step. */
|
|
3
|
+
export type LogLine = string | {
|
|
4
|
+
step: string;
|
|
5
|
+
};
|
|
6
|
+
export interface LogTailState {
|
|
7
|
+
/** Every entry the stream has produced so far, oldest first. */
|
|
8
|
+
lines: readonly LogLine[];
|
|
9
|
+
}
|
|
10
|
+
export interface LogTailOptions {
|
|
11
|
+
/** Rows the tail shows on a terminal. Default 5; anything below 1 is 1. */
|
|
12
|
+
height?: number;
|
|
13
|
+
}
|
|
14
|
+
/** A log tail: the whole stream, appended, off a terminal; its last `height` rows on one. */
|
|
15
|
+
export declare function logTail({ height }?: LogTailOptions): Component<LogTailState>;
|
package/dist/log-tail.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { heading, muted } from 'roundel/tokens';
|
|
2
|
+
import { glyph, register } from './plugin.js';
|
|
3
|
+
const HEIGHT = 5;
|
|
4
|
+
const tail = (text) => ({ text: `${muted(glyph('tail'))} ${text}`, current: false });
|
|
5
|
+
function rows(entry, current) {
|
|
6
|
+
if (typeof entry === 'string')
|
|
7
|
+
return entry.split('\n').map(tail);
|
|
8
|
+
const [first, ...rest] = entry.step.split('\n');
|
|
9
|
+
const mark = current ? heading(glyph('step')) : muted(glyph('step'));
|
|
10
|
+
return [{ text: `${mark} ${current ? heading(first) : first}`, current }, ...rest.map(tail)];
|
|
11
|
+
}
|
|
12
|
+
export function logTail({ height = HEIGHT } = {}) {
|
|
13
|
+
const shown = Math.max(1, Math.floor(height));
|
|
14
|
+
return {
|
|
15
|
+
name: 'log-tail',
|
|
16
|
+
static: ({ lines }) => lines
|
|
17
|
+
.flatMap((entry) => rows(entry, false))
|
|
18
|
+
.map((row) => row.text)
|
|
19
|
+
.join('\n'),
|
|
20
|
+
frame: (_t, { lines }) => {
|
|
21
|
+
const current = lines.findLastIndex((entry) => typeof entry !== 'string');
|
|
22
|
+
let window = [];
|
|
23
|
+
for (let i = lines.length - 1; i >= 0 && window.length < shown; i -= 1)
|
|
24
|
+
window = [...rows(lines[i], i === current), ...window];
|
|
25
|
+
window = window.slice(-shown);
|
|
26
|
+
if (current >= 0 && !window.some((row) => row.current))
|
|
27
|
+
window = [...rows(lines[current], true).slice(0, 1), ...window.slice(window.length - (shown - 1))];
|
|
28
|
+
return window.map((row) => row.text).join('\n');
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const builtin = logTail();
|
|
33
|
+
register({
|
|
34
|
+
name: 'flagstaff',
|
|
35
|
+
components: {
|
|
36
|
+
'log-tail': {
|
|
37
|
+
static: builtin.static,
|
|
38
|
+
frame: builtin.frame,
|
|
39
|
+
sample: {
|
|
40
|
+
running: { lines: [{ step: 'Installing packages' }, 'npm install', 'added 12 packages'] },
|
|
41
|
+
done: { lines: [{ step: 'Installing packages' }, 'npm install', 'added 12 packages', { step: 'Done' }] },
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
});
|
package/dist/loop.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { type ModeOptions, type OutputMode, type Runtime as PolicyRuntime } from 'roundel/policy';
|
|
8
8
|
import { type Component } from './plugin.js';
|
|
9
|
-
import { type Clock, type Writer } from './projection.js';
|
|
9
|
+
import { type Clock, frameWriter, type Writer } from './projection.js';
|
|
10
10
|
/** What the loop needs from the world: the policy's slice plus the two streams and a clock. */
|
|
11
11
|
export interface Runtime extends PolicyRuntime {
|
|
12
12
|
stdout: Writer;
|
|
@@ -27,4 +27,10 @@ export interface ManualClock extends Clock {
|
|
|
27
27
|
}
|
|
28
28
|
/** A clock that moves only when told (R9): the same frames every run, so a spinner snapshots. */
|
|
29
29
|
export declare function manualClock(start?: number): ManualClock;
|
|
30
|
-
|
|
30
|
+
/**
|
|
31
|
+
* The frame-writing seam (controlroom R3, R15): a whole frame of lines in, the changed rows
|
|
32
|
+
* out in one synchronized-output block. Exported from here, beside `hoist`, because it is the
|
|
33
|
+
* same repaint `hoist` uses on a terminal — a compositor gets the loop's bytes, not a copy.
|
|
34
|
+
*/
|
|
35
|
+
export { frameWriter };
|
|
36
|
+
export type { Clock, FrameWriter, Writer } from './projection.js';
|
package/dist/loop.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { outputMode } from 'roundel/policy';
|
|
2
|
-
import { jsonProjection, staticProjection, ttyProjection } from './projection.js';
|
|
2
|
+
import { frameWriter, jsonProjection, staticProjection, ttyProjection } from './projection.js';
|
|
3
3
|
function projectionFor(mode, component, rt) {
|
|
4
4
|
if (mode === 'tty')
|
|
5
5
|
return ttyProjection(component, rt.stdout, rt.clock);
|
|
@@ -65,3 +65,4 @@ export function manualClock(start = 0) {
|
|
|
65
65
|
},
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
|
+
export { frameWriter };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Component } from './plugin.js';
|
|
2
|
+
export interface MarkdownState {
|
|
3
|
+
/** Everything the stream has produced so far. */
|
|
4
|
+
text: string;
|
|
5
|
+
/** The stream has ended: the last block is committed too. */
|
|
6
|
+
done?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export type MarkdownBlockKind = 'heading' | 'paragraph' | 'list' | 'code';
|
|
9
|
+
export interface MarkdownBlock {
|
|
10
|
+
kind: MarkdownBlockKind;
|
|
11
|
+
/** The block's source, its lines as they arrived. */
|
|
12
|
+
source: string;
|
|
13
|
+
/** Where the block's source ends in the stream: `text.slice(0, end)` is committed. */
|
|
14
|
+
end: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The blocks committed so far. Only complete lines are read — a line is complete when a
|
|
18
|
+
* newline follows it, or when the stream is `done` — which is what makes the answer the same
|
|
19
|
+
* wherever the stream was cut.
|
|
20
|
+
*/
|
|
21
|
+
export declare function markdownBlocks(text: string, done?: boolean): MarkdownBlock[];
|
|
22
|
+
/** Markdown streamed in: its committed source off a terminal, the document so far drawn on one. */
|
|
23
|
+
export declare function markdown(): Component<MarkdownState>;
|
package/dist/markdown.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { command, heading, muted, value } from 'roundel/tokens';
|
|
2
|
+
const FENCE = /^ {0,3}(`{3,}|~{3,})/;
|
|
3
|
+
const HEADING = /^ {0,3}#{1,6}(?=[ \t]|$)/;
|
|
4
|
+
const BLANK = /^[ \t]*$/;
|
|
5
|
+
const ITEM = /^ {0,3}(?:[-*+]|\d{1,9}[.)])[ \t]/;
|
|
6
|
+
function closes(line, fence) {
|
|
7
|
+
const run = FENCE.exec(line)?.[1];
|
|
8
|
+
return run !== undefined && run[0] === fence[0] && run.length >= fence.length && BLANK.test(line.slice(line.indexOf(run) + run.length));
|
|
9
|
+
}
|
|
10
|
+
function starts(line, open) {
|
|
11
|
+
if (FENCE.test(line))
|
|
12
|
+
return 'code';
|
|
13
|
+
if (HEADING.test(line))
|
|
14
|
+
return 'heading';
|
|
15
|
+
if (ITEM.test(line))
|
|
16
|
+
return open?.kind === 'list' ? undefined : 'list';
|
|
17
|
+
return open === undefined ? 'paragraph' : undefined;
|
|
18
|
+
}
|
|
19
|
+
function extend(open, line, end) {
|
|
20
|
+
open.lines.push(line);
|
|
21
|
+
open.end = end;
|
|
22
|
+
}
|
|
23
|
+
class Splitter {
|
|
24
|
+
committed = [];
|
|
25
|
+
#open;
|
|
26
|
+
commit() {
|
|
27
|
+
const open = this.#open;
|
|
28
|
+
if (open !== undefined)
|
|
29
|
+
this.committed.push({ kind: open.kind, source: open.lines.join('\n'), end: open.end });
|
|
30
|
+
this.#open = undefined;
|
|
31
|
+
}
|
|
32
|
+
line(line, end) {
|
|
33
|
+
const open = this.#open;
|
|
34
|
+
if (open?.kind === 'code') {
|
|
35
|
+
extend(open, line, end);
|
|
36
|
+
if (closes(line, open.fence))
|
|
37
|
+
this.commit();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (BLANK.test(line)) {
|
|
41
|
+
this.commit();
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const kind = starts(line, open);
|
|
45
|
+
if (kind === undefined) {
|
|
46
|
+
extend(open, line, end);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
this.commit();
|
|
50
|
+
const opened = { kind, lines: [], end, fence: FENCE.exec(line)?.[1] ?? '' };
|
|
51
|
+
this.#open = opened;
|
|
52
|
+
extend(opened, line, end);
|
|
53
|
+
if (kind === 'heading')
|
|
54
|
+
this.commit();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export function markdownBlocks(text, done = false) {
|
|
58
|
+
const splitter = new Splitter();
|
|
59
|
+
const lines = text.split('\n');
|
|
60
|
+
if (!done || lines.at(-1) === '')
|
|
61
|
+
lines.pop();
|
|
62
|
+
let end = -1;
|
|
63
|
+
for (const line of lines) {
|
|
64
|
+
end += line.length + 1;
|
|
65
|
+
splitter.line(line, end);
|
|
66
|
+
}
|
|
67
|
+
if (done)
|
|
68
|
+
splitter.commit();
|
|
69
|
+
return splitter.committed;
|
|
70
|
+
}
|
|
71
|
+
function styled(paint, text, plain) {
|
|
72
|
+
const painted = paint(text);
|
|
73
|
+
return painted === text ? plain : painted;
|
|
74
|
+
}
|
|
75
|
+
const INLINE = /(?<ticks>`+)(?<code>[^`]|[^`][\s\S]*?[^`])\k<ticks>(?!`)|\*\*(?<strong>\S(?:.*?\S)?)\*\*|(?<!\w)__(?<strongU>\S(?:.*?\S)?)__(?!\w)|\*(?<em>[^\s*](?:.*?[^\s*])?)\*|(?<!\w)_(?<emU>[^\s_](?:.*?[^\s_])?)_(?!\w)/g;
|
|
76
|
+
function inline(line) {
|
|
77
|
+
let drawn = '';
|
|
78
|
+
let at = 0;
|
|
79
|
+
for (const match of line.matchAll(INLINE)) {
|
|
80
|
+
const { code, strong, strongU, em, emU } = match.groups;
|
|
81
|
+
let span;
|
|
82
|
+
if (code !== undefined)
|
|
83
|
+
span = styled(command, code, match[0]);
|
|
84
|
+
else if ((strong ?? strongU) !== undefined)
|
|
85
|
+
span = styled(heading, (strong ?? strongU), match[0]);
|
|
86
|
+
else
|
|
87
|
+
span = styled(value, (em ?? emU), match[0]);
|
|
88
|
+
drawn += line.slice(at, match.index) + span;
|
|
89
|
+
at = match.index + match[0].length;
|
|
90
|
+
}
|
|
91
|
+
return drawn + line.slice(at);
|
|
92
|
+
}
|
|
93
|
+
function draw(block) {
|
|
94
|
+
if (block.kind === 'heading')
|
|
95
|
+
return styled(heading, block.source.slice(HEADING.exec(block.source)[0].length).trim(), block.source);
|
|
96
|
+
const lines = block.source.split('\n');
|
|
97
|
+
if (block.kind !== 'code')
|
|
98
|
+
return lines.map(inline).join('\n');
|
|
99
|
+
const fence = FENCE.exec(block.source)[1];
|
|
100
|
+
return lines.map((line, i) => (i === 0 || (i === lines.length - 1 && closes(line, fence)) ? muted(line) : command(line))).join('\n');
|
|
101
|
+
}
|
|
102
|
+
export function markdown() {
|
|
103
|
+
return {
|
|
104
|
+
name: 'markdown',
|
|
105
|
+
static: ({ text, done }) => text.slice(0, markdownBlocks(text, done).at(-1)?.end ?? 0),
|
|
106
|
+
frame: (_t, { text }) => markdownBlocks(text, true)
|
|
107
|
+
.map(draw)
|
|
108
|
+
.join('\n\n'),
|
|
109
|
+
};
|
|
110
|
+
}
|
package/dist/projection.d.ts
CHANGED
|
@@ -21,6 +21,22 @@ export interface Projection<S> {
|
|
|
21
21
|
close(state: S): void;
|
|
22
22
|
}
|
|
23
23
|
export declare const DEFAULT_INTERVAL = 80;
|
|
24
|
+
/**
|
|
25
|
+
* The frame-writing seam (controlroom R3, R16). `paint` takes the whole frame, one string per
|
|
26
|
+
* line, and writes only what changed since the last paint, wrapped in synchronized output;
|
|
27
|
+
* a frame identical to the last writes nothing. `release` forgets the painted frame without
|
|
28
|
+
* erasing it: what is on screen becomes scrollback, and the next paint starts at the cursor.
|
|
29
|
+
*
|
|
30
|
+
* Between paints the cursor rests at the end of the frame's last row, which is where the
|
|
31
|
+
* hoisted projection has always left it. A frame taller than the terminal cannot be reached
|
|
32
|
+
* above its top row; that is the terminal's limit, and a caller lays out within its height.
|
|
33
|
+
*/
|
|
34
|
+
export interface FrameWriter {
|
|
35
|
+
paint(lines: readonly string[]): void;
|
|
36
|
+
release(): void;
|
|
37
|
+
}
|
|
38
|
+
/** The family's one frame writer over `out` — see `FrameWriter`. */
|
|
39
|
+
export declare function frameWriter(out: Writer): FrameWriter;
|
|
24
40
|
export declare function ttyProjection<S>(component: Component<S>, out: Writer, clock: Clock): Projection<S>;
|
|
25
41
|
/**
|
|
26
42
|
* A pipe, CI, or a screen reader: the static projection, once per change, and nothing else.
|
package/dist/projection.js
CHANGED
|
@@ -4,10 +4,58 @@ import { lineCount } from 'linegauge';
|
|
|
4
4
|
export const DEFAULT_INTERVAL = 80;
|
|
5
5
|
const DEFAULT_COLUMNS = 80;
|
|
6
6
|
const CSI = '\u001B[';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const BEGIN_SYNC = `${CSI}?2026h`;
|
|
8
|
+
const END_SYNC = `${CSI}?2026l`;
|
|
9
|
+
const SAVE = '\u001B7';
|
|
10
|
+
const RESTORE = '\u001B8';
|
|
11
|
+
function columnsOf(out) {
|
|
12
|
+
const { columns } = out;
|
|
13
|
+
return columns !== undefined && columns > 0 ? columns : DEFAULT_COLUMNS;
|
|
14
|
+
}
|
|
15
|
+
function diff(was, now, sameWidth) {
|
|
16
|
+
const { lines: before, rows: beforeRows } = was;
|
|
17
|
+
const { lines: after, rows: afterRows } = now;
|
|
18
|
+
let at = beforeRows.reduce((sum, n) => sum + n, 0) - 1;
|
|
19
|
+
let out = '';
|
|
20
|
+
const move = (row) => {
|
|
21
|
+
out += `${CSI}1G${row < at ? `${CSI}${at - row}A` : ''}${row > at ? `${CSI}${row - at}B` : ''}`;
|
|
22
|
+
at = row;
|
|
23
|
+
};
|
|
24
|
+
const last = Math.min(before.length, after.length) - 1;
|
|
25
|
+
let line = 0;
|
|
26
|
+
let row = 0;
|
|
27
|
+
for (; sameWidth && line < last; line += 1) {
|
|
28
|
+
if (before[line] !== after[line]) {
|
|
29
|
+
if (beforeRows[line] !== 1 || afterRows[line] !== 1)
|
|
30
|
+
break;
|
|
31
|
+
move(row);
|
|
32
|
+
out += `${CSI}2K${after[line]}`;
|
|
33
|
+
}
|
|
34
|
+
row += beforeRows[line];
|
|
35
|
+
}
|
|
36
|
+
if (sameWidth && line === last && before.length === after.length && before[line] === after[line])
|
|
37
|
+
return out === '' ? '' : `${SAVE}${out}${RESTORE}`;
|
|
38
|
+
move(row);
|
|
39
|
+
return `${out}${CSI}0J${after.slice(line).join('\n')}`;
|
|
40
|
+
}
|
|
41
|
+
export function frameWriter(out) {
|
|
42
|
+
let shown;
|
|
43
|
+
let width = 0;
|
|
44
|
+
return {
|
|
45
|
+
paint(lines) {
|
|
46
|
+
const frame = lines.length === 0 ? [''] : [...lines];
|
|
47
|
+
const columns = columnsOf(out);
|
|
48
|
+
const now = { lines: frame, rows: frame.map((line) => lineCount(line, columns)) };
|
|
49
|
+
const bytes = shown === undefined ? frame.join('\n') : diff(shown, now, columns === width);
|
|
50
|
+
shown = now;
|
|
51
|
+
width = columns;
|
|
52
|
+
if (bytes !== '')
|
|
53
|
+
out.write(`${BEGIN_SYNC}${bytes}${END_SYNC}`);
|
|
54
|
+
},
|
|
55
|
+
release() {
|
|
56
|
+
shown = undefined;
|
|
57
|
+
},
|
|
58
|
+
};
|
|
11
59
|
}
|
|
12
60
|
class TtyProjection {
|
|
13
61
|
#component;
|
|
@@ -15,8 +63,8 @@ class TtyProjection {
|
|
|
15
63
|
#clock;
|
|
16
64
|
#interval;
|
|
17
65
|
#started;
|
|
66
|
+
#frame;
|
|
18
67
|
#current;
|
|
19
|
-
#lines = 0;
|
|
20
68
|
#cancel = () => undefined;
|
|
21
69
|
#dropCursorNet;
|
|
22
70
|
constructor(component, out, clock) {
|
|
@@ -25,6 +73,7 @@ class TtyProjection {
|
|
|
25
73
|
this.#clock = clock;
|
|
26
74
|
this.#interval = component.interval ?? DEFAULT_INTERVAL;
|
|
27
75
|
this.#started = clock.now();
|
|
76
|
+
this.#frame = frameWriter(out);
|
|
28
77
|
}
|
|
29
78
|
open(state) {
|
|
30
79
|
this.#current = state;
|
|
@@ -40,16 +89,15 @@ class TtyProjection {
|
|
|
40
89
|
}
|
|
41
90
|
close(state) {
|
|
42
91
|
this.#cancel();
|
|
43
|
-
this.#
|
|
92
|
+
this.#frame.paint(this.#component.static(state).split('\n'));
|
|
93
|
+
this.#frame.release();
|
|
94
|
+
this.#out.write(`\n${SHOW_CURSOR}`);
|
|
44
95
|
this.#dropCursorNet();
|
|
45
|
-
this.#lines = 0;
|
|
46
96
|
}
|
|
47
97
|
#paint() {
|
|
48
98
|
const { frame } = this.#component;
|
|
49
99
|
const text = frame === undefined ? this.#component.static(this.#current) : frame(this.#clock.now() - this.#started, this.#current);
|
|
50
|
-
this.#
|
|
51
|
-
const columns = this.#out.columns;
|
|
52
|
-
this.#lines = lineCount(text, columns !== undefined && columns > 0 ? columns : DEFAULT_COLUMNS);
|
|
100
|
+
this.#frame.paint(text.split('\n'));
|
|
53
101
|
}
|
|
54
102
|
#repaint() {
|
|
55
103
|
this.#paint();
|
package/dist/schema.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://github.com/ofri-peretz/burgee/blob/main/packages/flagstaff/src/schema.json","title":"flagstaff plugin","description":"A plugin is one plain object. Everything in it is data that can be read without running it; the only functions allowed are a component's `static` (required) and `frame` (optional). A spinner or component without a static projection is refused at register().","type":"object","required":["name"],"additionalProperties":true,"properties":{"name":{"type":"string","minLength":1,"description":"The plugin's name; also the prefix a host may use when two plugins contribute the same key."},"contract":{"type":"integer","minimum":1,"description":"The plugin contract this object follows. A host refuses a newer contract than it knows."},"tokens":{"type":"object","description":"A roundel theme: semantic token name to a hex colour, contrast-checked when flown.","additionalProperties":{"type":"string","pattern":"^#[0-9a-fA-F]{6}$"},"propertyNames":{"enum":["error","warn","ok","hint","muted","command","flag","value","heading","ground"],"description":"roundel's ten semantic tokens, and nothing else — `roundel`'s own validate() refuses any other name."}},"glyphs":{"type":"object","description":"Symbols by meaning: `ok`, `fail`, `warn`, `info`, `running`. A plugin that ships glyphs changes every built-in that draws one.","additionalProperties":{"type":"string","minLength":1}},"spinners":{"type":"object","description":"Spinner styles by name, in cli-spinners' shape plus the static projection.","additionalProperties":{"$ref":"#/$defs/spinner"}},"borders":{"type":"object","description":"Border styles a box can be drawn with, by name.","additionalProperties":{"$ref":"#/$defs/border"}},"components":{"type":"object","description":"Components by name: `static(state)` returns the text a pipe, an agent or a screen reader gets; `frame(t, state)` is the optional animated form.","additionalProperties":{"$ref":"#/$defs/component"}},"capabilities":{"$ref":"#/$defs/capabilities"},"widths":{"$ref":"#/$defs/widths"},"resolvers":{"type":"object","description":"bellpull resolvers by name: extra directories searched for an executable, before PATH (negative rank) or after it (positive). Two resolvers with one name shadow; two names both apply, in rank order.","additionalProperties":{"$ref":"#/$defs/resolver"}},"widgets":{"type":"object","description":"caique prompt widgets by kind. The six built-in kinds — text, confirm, select, multiselect, password, path — cannot be replaced: a plugin adds kinds of its own.","additionalProperties":{"$ref":"#/$defs/widget"}},"handlers":{"type":"array","description":"closeout exit handlers. The phase decides the order they run in, not their position in this list.","items":{"$ref":"#/$defs/handler"}},"sources":{"type":"object","description":"seniority configuration sources by name, ranked against the built-in layers: a flag is 0 and a declared default is 40, and a plugin source sits strictly between.","additionalProperties":{"$ref":"#/$defs/source"}},"commands":{"type":"array","description":"burgee commands this plugin contributes. Each is read by exactly the code a program's own command is, and a burgee plugin must declare `contract`.","items":{"$ref":"#/$defs/command"}},"hooks":{"type":"object","description":"burgee lifecycle hooks. parse rewrites argv before a command is resolved; preRun opens around a command, and exactly one of postRun or onError closes; shutdown fires once as the program leaves, by any path.","additionalProperties":false,"properties":{"parse":{"$ref":"#/$defs/hook"},"preRun":{"$ref":"#/$defs/hook"},"postRun":{"$ref":"#/$defs/hook"},"onError":{"$ref":"#/$defs/hook"},"shutdown":{"$ref":"#/$defs/hook"}}},"enforce":{"type":"string","pattern":"^(pre|post)$","description":"burgee: order this plugin's hooks before (`pre`) or after (`post`) the others."}},"$defs":{"spinner":{"type":"object","required":["frames","interval","static"],"properties":{"frames":{"type":"array","items":{"type":"string"},"minItems":1},"interval":{"type":"integer","minimum":1,"description":"Milliseconds between frames on a terminal."},"static":{"type":"string","description":"What a pipe prints instead of the animation."}}},"component":{"type":"object","required":["static"],"properties":{"static":{"description":"(state) => string. Required: the projection every non-terminal mode prints."},"frame":{"description":"(t, state) => string. Optional: the frame at t milliseconds since hoisting."},"sample":{"type":"object","required":["running","done"],"description":"Two states to *show* this component with: `flagstaff check` and the docs gallery render `running` then `done`. Omitted, they assume `{ phase: 'running' }` and `{ phase: 'done' }` and say so in the output. The loop never reads it — a running program's state comes from the program.","properties":{"running":{"description":"The state to open with."},"done":{"description":"The state to close with."}}},"interval":{"type":"integer","minimum":1,"description":"Milliseconds between repaints when `frame` is given; 80 when omitted."}}},"border":{"type":"object","required":["topLeft","top","topRight","left","right","bottomLeft","bottom","bottomRight"],"description":"cli-boxes' shape exactly, so that corpus imports unchanged.","properties":{"topLeft":{"type":"string"},"top":{"type":"string"},"topRight":{"type":"string"},"left":{"type":"string"},"right":{"type":"string"},"bottomLeft":{"type":"string"},"bottom":{"type":"string"},"bottomRight":{"type":"string"}}},"capability":{"type":"object","required":["name","osc","when","encode","fallback"],"additionalProperties":false,"description":"One paratext capability: what it says to the terminal, when the terminal is believed to understand it, and what prints when it does not. No functions, so it travels through JSON. `encode` and `fallback` are templates: `{field}` is the field's value, `{field|base64}` is it base64-encoded, and `[ … ]` is emitted only when every field inside it has a value.","properties":{"name":{"type":"string","minLength":1,"description":"How callers name it. Registering an existing name replaces it — how a caller corrects a guess we got wrong."},"osc":{"description":"The OSC code this speaks, or 'BEL' for the bell and for protocols that are not OSC at all, such as Kitty's.","oneOf":[{"type":"integer","minimum":0},{"const":"BEL"}]},"when":{"type":"object","description":"When the terminal is believed to understand it. Every clause must hold; `termProgram` and `envAny` are ORs within themselves. Guesses — no terminal answers 'do you do OSC 1337' — and therefore data a caller can replace.","additionalProperties":false,"properties":{"tty":{"type":"boolean","description":"Refuse a pipe. Almost always true: a file that receives OSC gets control bytes in it."},"termProgram":{"type":"array","items":{"type":"string"},"description":"Any one of these TERM_PROGRAM values."},"envAny":{"type":"array","items":{"type":"string"},"description":"Any one of these environment variables merely being set, as VTE announces itself."},"term":{"type":"string","description":"An exact TERM — Kitty is xterm-kitty."}}},"encode":{"type":"string","minLength":1,"description":"The bytes, as a template, for a terminal that does understand."},"fallback":{"type":"string","description":"What to print when it does not — PRINCIPLES rule 6. '' is a legitimate answer, a window title having nothing to say in a log; absence is not, which is why this is required and may be ''."}},"examples":[{"name":"kitty-image","osc":"BEL","when":{"tty":true,"term":"xterm-kitty"},"encode":"\u001b_Ga=T,f=100;{base64}\u001b\\","fallback":"{caption}"}]},"capabilities":{"type":"object","description":"paratext capabilities by name — the OSC section of a plugin, read the way flagstaff reads `spinners`.","additionalProperties":{"$ref":"#/$defs/capability"}},"capabilityDocument":{"description":"What paratext's `check()` accepts. Two shapes, and only one of them survives 1.0.","oneOf":[{"description":"The family shape: a plugin carrying its capabilities under `capabilities`.","type":"object","required":["name","capabilities"],"properties":{"name":{"type":"string","minLength":1},"contract":{"type":"integer","minimum":1},"capabilities":{"$ref":"#/$defs/capabilities"}}},{"deprecated":true,"description":"Deprecated: one capability as the whole document, the shape paratext's schema had before this one absorbed it. Accepted for one minor release, removed at 1.0 — `check()` validates it and says so.","$ref":"#/$defs/capability"}]},"widthRange":{"type":"array","description":"One inclusive code-point range, as [low, high]. A single code point is written [n, n].","items":{"type":"integer","minimum":0,"maximum":1114111},"minItems":2,"maxItems":2},"widthOverride":{"type":"object","description":"A linegauge width override: the column count a named set of code-point ranges occupies, for a terminal that disagrees with the Unicode tables. Data only — no function, so it can be written in a config file, diffed, and printed by `linegauge check` without running anyone code.","required":["ranges","columns","why"],"additionalProperties":false,"properties":{"ranges":{"type":"array","description":"The code points this override applies to.","items":{"$ref":"#/$defs/widthRange"},"minItems":1},"columns":{"type":"integer","description":"Columns each cluster in those ranges occupies: 0 for a zero-width mark, 1 narrow, 2 wide.","minimum":0,"maximum":2},"why":{"type":"string","description":"The terminal or the reason. Required, because a width table with no provenance is one nobody can audit when it turns out to be wrong — which is the normal outcome for ambiguous width.","minLength":1}}},"widths":{"type":"object","description":"linegauge width overrides by name — the measurement section of a plugin, read the way flagstaff reads `spinners`.","additionalProperties":{"$ref":"#/$defs/widthOverride"}},"resolver":{"type":"object","required":["rank","paths"],"description":"One bellpull resolver: where to look for an executable, and when.","properties":{"rank":{"type":"number","description":"Search order against PATH: negative searches before it, positive after."},"paths":{"type":"array","minItems":1,"description":"Directories to search. `{VAR}` is substituted from the environment; each must be absolute, or start with a `{VAR}` that holds an absolute path.","items":{"type":"string","minLength":1,"pattern":"^(/|\\{|[A-Za-z]:[\\\\/]|\\\\\\\\)"}},"extensions":{"type":"array","items":{"type":"string"},"description":"Extensions to try on Windows, in place of PATHEXT."},"when":{"type":"object","description":"When the resolver applies. Leave it out and it always does.","properties":{"platform":{"type":"array","items":{"type":"string"},"description":"process.platform values it applies on."},"envAny":{"type":"array","items":{"type":"string"},"description":"It applies when any of these environment variables is set."}}}}},"widget":{"type":"object","required":["static"],"description":"One caique widget: how a prompt kind of the plugin's own is drawn.","properties":{"static":{"description":"(spec) => string. Required: what a pipe, an agent or a screen reader gets instead of the interactive prompt."},"frame":{"description":"(t, spec) => string. Optional: the animated form; leave it out and the widget is line-mode only."},"sample":{"type":"object","required":["running","done"],"description":"Two named states of plain data that `caique check` renders the widget with."}}},"handler":{"type":"object","required":["name","run"],"description":"One closeout exit handler.","properties":{"name":{"type":"string","minLength":1,"description":"How the handler is named in a report, including the one the deadline prints when it does not return."},"phase":{"type":"string","pattern":"^(flush|release)$","description":"When it runs. Defaults to `release`; `restore` is closeout's own last phase and a plugin may not use it."},"run":{"description":"(info) => void | Promise<void>. Required: the cleanup itself."}}},"source":{"type":"object","required":["rank"],"description":"One seniority source. Exactly one of `values` (static) or `read(runtime)` (fetched) gives its answer.","properties":{"rank":{"type":"integer","minimum":1,"maximum":39,"description":"Precedence, strictly between the flag (0) and the declared default (40): a source may not beat what the user typed, nor sink below the default."},"values":{"type":"object","description":"Option name to value."},"read":{"description":"(runtime) => { values, location? } | undefined."},"location":{"type":"string","description":"The file, URL or variable set a person would go and look at."}}},"option":{"type":"object","required":["type"],"description":"One burgee option, keyed by its camelCase name; the flag is its kebab-case form.","properties":{"type":{"type":"string","pattern":"^(string|boolean|number)$"},"description":{"type":"string"},"short":{"type":"string","minLength":1},"required":{"type":"boolean"},"env":{"type":"string"},"choices":{"type":"array","items":{"type":"string"}},"dependsOn":{"type":"array","items":{"type":"string"},"description":"Options that must be set with this one; each must be another option of the same command."},"exclusive":{"type":"array","items":{"type":"string"},"description":"Options that may not be set with this one; each must be another option of the same command."},"deprecated":{"description":"What replaces this option, e.g. '--force'. `true` alone, or an empty string, is refused: a deprecation names its replacement."}}},"command":{"type":"object","required":["path"],"description":"One burgee command node, declared exactly as a program's own command is.","properties":{"path":{"type":"array","minItems":1,"items":{"type":"string","minLength":1},"description":"The words a user types. May not repeat a path the program or an earlier plugin already declares."},"description":{"type":"string"},"options":{"type":"object","additionalProperties":{"$ref":"#/$defs/option"}},"effects":{"type":"string","pattern":"^(read_only|idempotent|non_idempotent|withheld)$","description":"What running it does to the world. Required on any command that runs; `withheld` serves it to people and keeps it out of the MCP tool list."},"deprecated":{"description":"What replaces this command. `true` alone, or an empty string, is refused."},"run":{"description":"(ctx) => unknown. What the command does; its return value is the `--json` envelope's data."},"load":{"description":"() => Promise<module>. A lazy form of `run`, imported on dispatch."}}},"hook":{"type":"object","required":["handler"],"description":"One burgee hook.","properties":{"filter":{"type":"object","description":"`{ command: RegExp }`: fire only for commands whose path matches."},"handler":{"description":"(ctx) => void | Promise<void>. Required. On parse it may return the string[] argv to use instead."}}}}}
|
|
1
|
+
{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://github.com/ofri-peretz/burgee/blob/main/packages/flagstaff/src/schema.json","title":"flagstaff plugin","description":"A plugin is one plain object. Everything in it is data that can be read without running it; the only functions allowed are a component's `static` (required) and `frame` (optional). A spinner or component without a static projection is refused at register().","type":"object","required":["name"],"additionalProperties":true,"properties":{"name":{"type":"string","minLength":1,"description":"The plugin's name; also the prefix a host may use when two plugins contribute the same key."},"contract":{"type":"integer","minimum":1,"description":"The plugin contract this object follows. A host refuses a newer contract than it knows."},"tokens":{"type":"object","description":"A roundel theme: semantic token name to a hex colour, contrast-checked when flown.","additionalProperties":{"type":"string","pattern":"^#[0-9a-fA-F]{6}$"},"propertyNames":{"enum":["error","warn","ok","hint","muted","command","flag","value","heading","ground"],"description":"roundel's ten semantic tokens, and nothing else — `roundel`'s own validate() refuses any other name."}},"glyphs":{"type":"object","description":"Symbols by meaning: `ok`, `fail`, `warn`, `info`, `running`. A plugin that ships glyphs changes every built-in that draws one.","additionalProperties":{"type":"string","minLength":1}},"spinners":{"type":"object","description":"Spinner styles by name, in cli-spinners' shape plus the static projection.","additionalProperties":{"$ref":"#/$defs/spinner"}},"borders":{"type":"object","description":"Border styles a box can be drawn with, by name.","additionalProperties":{"$ref":"#/$defs/border"}},"components":{"type":"object","description":"Components by name: `static(state)` returns the text a pipe, an agent or a screen reader gets; `frame(t, state)` is the optional animated form.","additionalProperties":{"$ref":"#/$defs/component"}},"capabilities":{"$ref":"#/$defs/capabilities"},"widths":{"$ref":"#/$defs/widths"},"resolvers":{"type":"object","description":"bellpull resolvers by name: extra directories searched for an executable, before PATH (negative rank) or after it (positive). Two resolvers with one name shadow; two names both apply, in rank order.","additionalProperties":{"$ref":"#/$defs/resolver"}},"widgets":{"type":"object","description":"caique prompt widgets by kind. The six built-in kinds — text, confirm, select, multiselect, password, path — cannot be replaced: a plugin adds kinds of its own.","additionalProperties":{"$ref":"#/$defs/widget"}},"handlers":{"type":"array","description":"closeout exit handlers. The phase decides the order they run in, not their position in this list.","items":{"$ref":"#/$defs/handler"}},"sources":{"type":"object","description":"seniority configuration sources by name, ranked against the built-in layers: a flag is 0 and a declared default is 40, and a plugin source sits strictly between.","additionalProperties":{"$ref":"#/$defs/source"}},"commands":{"type":"array","description":"burgee commands this plugin contributes. Each is read by exactly the code a program's own command is, and a burgee plugin must declare `contract`.","items":{"$ref":"#/$defs/command"}},"hooks":{"type":"object","description":"burgee lifecycle hooks. parse rewrites argv before a command is resolved; preRun opens around a command, and exactly one of postRun or onError closes; shutdown fires once as the program leaves, by any path.","additionalProperties":false,"properties":{"parse":{"$ref":"#/$defs/hook"},"preRun":{"$ref":"#/$defs/hook"},"postRun":{"$ref":"#/$defs/hook"},"onError":{"$ref":"#/$defs/hook"},"shutdown":{"$ref":"#/$defs/hook"}}},"enforce":{"type":"string","pattern":"^(pre|post)$","description":"burgee: order this plugin's hooks before (`pre`) or after (`post`) the others."},"keymaps":{"$ref":"#/$defs/keymaps"},"panes":{"$ref":"#/$defs/panes"}},"$defs":{"spinner":{"type":"object","required":["frames","interval","static"],"properties":{"frames":{"type":"array","items":{"type":"string"},"minItems":1},"interval":{"type":"integer","minimum":1,"description":"Milliseconds between frames on a terminal."},"static":{"type":"string","description":"What a pipe prints instead of the animation."}}},"component":{"type":"object","required":["static"],"properties":{"static":{"description":"(state) => string. Required: the projection every non-terminal mode prints."},"frame":{"description":"(t, state) => string. Optional: the frame at t milliseconds since hoisting."},"sample":{"type":"object","required":["running","done"],"description":"Two states to *show* this component with: `flagstaff check` and the docs gallery render `running` then `done`. Omitted, they assume `{ phase: 'running' }` and `{ phase: 'done' }` and say so in the output. The loop never reads it — a running program's state comes from the program.","properties":{"running":{"description":"The state to open with."},"done":{"description":"The state to close with."}}},"interval":{"type":"integer","minimum":1,"description":"Milliseconds between repaints when `frame` is given; 80 when omitted."}}},"border":{"type":"object","required":["topLeft","top","topRight","left","right","bottomLeft","bottom","bottomRight"],"description":"cli-boxes' shape exactly, so that corpus imports unchanged.","properties":{"topLeft":{"type":"string"},"top":{"type":"string"},"topRight":{"type":"string"},"left":{"type":"string"},"right":{"type":"string"},"bottomLeft":{"type":"string"},"bottom":{"type":"string"},"bottomRight":{"type":"string"}}},"capability":{"type":"object","required":["name","osc","when","encode","fallback"],"additionalProperties":false,"description":"One paratext capability: what it says to the terminal, when the terminal is believed to understand it, and what prints when it does not. No functions, so it travels through JSON. `encode` and `fallback` are templates: `{field}` is the field's value, `{field|base64}` is it base64-encoded, and `[ … ]` is emitted only when every field inside it has a value.","properties":{"name":{"type":"string","minLength":1,"description":"How callers name it. Registering an existing name replaces it — how a caller corrects a guess we got wrong."},"osc":{"description":"The OSC code this speaks, or 'BEL' for the bell and for protocols that are not OSC at all, such as Kitty's.","oneOf":[{"type":"integer","minimum":0},{"const":"BEL"}]},"when":{"type":"object","description":"When the terminal is believed to understand it. Every clause must hold; `termProgram` and `envAny` are ORs within themselves. Guesses — no terminal answers 'do you do OSC 1337' — and therefore data a caller can replace.","additionalProperties":false,"properties":{"tty":{"type":"boolean","description":"Refuse a pipe. Almost always true: a file that receives OSC gets control bytes in it."},"termProgram":{"type":"array","items":{"type":"string"},"description":"Any one of these TERM_PROGRAM values."},"envAny":{"type":"array","items":{"type":"string"},"description":"Any one of these environment variables merely being set, as VTE announces itself."},"term":{"type":"string","description":"An exact TERM — Kitty is xterm-kitty."}}},"encode":{"type":"string","minLength":1,"description":"The bytes, as a template, for a terminal that does understand."},"fallback":{"type":"string","description":"What to print when it does not — PRINCIPLES rule 6. '' is a legitimate answer, a window title having nothing to say in a log; absence is not, which is why this is required and may be ''."}},"examples":[{"name":"kitty-image","osc":"BEL","when":{"tty":true,"term":"xterm-kitty"},"encode":"\u001b_Ga=T,f=100;{base64}\u001b\\","fallback":"{caption}"}]},"capabilities":{"type":"object","description":"paratext capabilities by name — the OSC section of a plugin, read the way flagstaff reads `spinners`.","additionalProperties":{"$ref":"#/$defs/capability"}},"capabilityDocument":{"description":"What paratext's `check()` accepts. Two shapes, and only one of them survives 1.0.","oneOf":[{"description":"The family shape: a plugin carrying its capabilities under `capabilities`.","type":"object","required":["name","capabilities"],"properties":{"name":{"type":"string","minLength":1},"contract":{"type":"integer","minimum":1},"capabilities":{"$ref":"#/$defs/capabilities"}}},{"deprecated":true,"description":"Deprecated: one capability as the whole document, the shape paratext's schema had before this one absorbed it. Accepted for one minor release, removed at 1.0 — `check()` validates it and says so.","$ref":"#/$defs/capability"}]},"widthRange":{"type":"array","description":"One inclusive code-point range, as [low, high]. A single code point is written [n, n].","items":{"type":"integer","minimum":0,"maximum":1114111},"minItems":2,"maxItems":2},"widthOverride":{"type":"object","description":"A linegauge width override: the column count a named set of code-point ranges occupies, for a terminal that disagrees with the Unicode tables. Data only — no function, so it can be written in a config file, diffed, and printed by `linegauge check` without running anyone code.","required":["ranges","columns","why"],"additionalProperties":false,"properties":{"ranges":{"type":"array","description":"The code points this override applies to.","items":{"$ref":"#/$defs/widthRange"},"minItems":1},"columns":{"type":"integer","description":"Columns each cluster in those ranges occupies: 0 for a zero-width mark, 1 narrow, 2 wide.","minimum":0,"maximum":2},"why":{"type":"string","description":"The terminal or the reason. Required, because a width table with no provenance is one nobody can audit when it turns out to be wrong — which is the normal outcome for ambiguous width.","minLength":1}}},"widths":{"type":"object","description":"linegauge width overrides by name — the measurement section of a plugin, read the way flagstaff reads `spinners`.","additionalProperties":{"$ref":"#/$defs/widthOverride"}},"resolver":{"type":"object","required":["rank","paths"],"description":"One bellpull resolver: where to look for an executable, and when.","properties":{"rank":{"type":"number","description":"Search order against PATH: negative searches before it, positive after."},"paths":{"type":"array","minItems":1,"description":"Directories to search. `{VAR}` is substituted from the environment; each must be absolute, or start with a `{VAR}` that holds an absolute path.","items":{"type":"string","minLength":1,"pattern":"^(/|\\{|[A-Za-z]:[\\\\/]|\\\\\\\\)"}},"extensions":{"type":"array","items":{"type":"string"},"description":"Extensions to try on Windows, in place of PATHEXT."},"when":{"type":"object","description":"When the resolver applies. Leave it out and it always does.","properties":{"platform":{"type":"array","items":{"type":"string"},"description":"process.platform values it applies on."},"envAny":{"type":"array","items":{"type":"string"},"description":"It applies when any of these environment variables is set."}}}}},"widget":{"type":"object","required":["static"],"description":"One caique widget: how a prompt kind of the plugin's own is drawn.","properties":{"static":{"description":"(spec) => string. Required: what a pipe, an agent or a screen reader gets instead of the interactive prompt."},"frame":{"description":"(t, spec) => string. Optional: the animated form; leave it out and the widget is line-mode only."},"sample":{"type":"object","required":["running","done"],"description":"Two named states of plain data that `caique check` renders the widget with."}}},"handler":{"type":"object","required":["name","run"],"description":"One closeout exit handler.","properties":{"name":{"type":"string","minLength":1,"description":"How the handler is named in a report, including the one the deadline prints when it does not return."},"phase":{"type":"string","pattern":"^(flush|release)$","description":"When it runs. Defaults to `release`; `restore` is closeout's own last phase and a plugin may not use it."},"run":{"description":"(info) => void | Promise<void>. Required: the cleanup itself."}}},"source":{"type":"object","required":["rank"],"description":"One seniority source. Exactly one of `values` (static) or `read(runtime)` (fetched) gives its answer.","properties":{"rank":{"type":"integer","minimum":1,"maximum":39,"description":"Precedence, strictly between the flag (0) and the declared default (40): a source may not beat what the user typed, nor sink below the default."},"values":{"type":"object","description":"Option name to value."},"read":{"description":"(runtime) => { values, location? } | undefined."},"location":{"type":"string","description":"The file, URL or variable set a person would go and look at."}}},"option":{"type":"object","required":["type"],"description":"One burgee option, keyed by its camelCase name; the flag is its kebab-case form.","properties":{"type":{"type":"string","pattern":"^(string|boolean|number)$"},"description":{"type":"string"},"short":{"type":"string","minLength":1},"required":{"type":"boolean"},"env":{"type":"string"},"choices":{"type":"array","items":{"type":"string"}},"dependsOn":{"type":"array","items":{"type":"string"},"description":"Options that must be set with this one; each must be another option of the same command."},"exclusive":{"type":"array","items":{"type":"string"},"description":"Options that may not be set with this one; each must be another option of the same command."},"deprecated":{"description":"What replaces this option, e.g. '--force'. `true` alone, or an empty string, is refused: a deprecation names its replacement."}}},"command":{"type":"object","required":["path"],"description":"One burgee command node, declared exactly as a program's own command is.","properties":{"path":{"type":"array","minItems":1,"items":{"type":"string","minLength":1},"description":"The words a user types. May not repeat a path the program or an earlier plugin already declares."},"description":{"type":"string"},"options":{"type":"object","additionalProperties":{"$ref":"#/$defs/option"}},"effects":{"type":"string","pattern":"^(read_only|idempotent|non_idempotent|withheld)$","description":"What running it does to the world. Required on any command that runs; `withheld` serves it to people and keeps it out of the MCP tool list."},"deprecated":{"description":"What replaces this command. `true` alone, or an empty string, is refused."},"run":{"description":"(ctx) => unknown. What the command does; its return value is the `--json` envelope's data."},"load":{"description":"() => Promise<module>. A lazy form of `run`, imported on dispatch."}}},"hook":{"type":"object","required":["handler"],"description":"One burgee hook.","properties":{"filter":{"type":"object","description":"`{ command: RegExp }`: fire only for commands whose path matches."},"handler":{"description":"(ctx) => void | Promise<void>. Required. On parse it may return the string[] argv to use instead."}}},"keymaps":{"type":"object","description":"controlroom keymaps by name: key spec to action name, and the label each action shows in the hint line. `default` replaces the built-in keymap.","additionalProperties":{"$ref":"#/$defs/keymap"}},"keymap":{"type":"object","required":["keys"],"additionalProperties":false,"properties":{"keys":{"type":"object","description":"Key spec, as caique/keys spells it ('left', 'enter', 'ctrl+c', 'shift+tab', 's'), to an action name ('tab.next', 'toggle:status', or the program's own).","additionalProperties":{"type":"string","minLength":1}},"labels":{"type":"object","description":"Action name to the label the hint line shows. An action with no label is bound but not advertised.","additionalProperties":{"type":"string","minLength":1}}}},"panes":{"type":"object","description":"controlroom panes by name: the flagstaff component that draws each one, and its label. A tab bar is a pane over flagstaff's `tab-bar`.","additionalProperties":{"$ref":"#/$defs/pane"}},"pane":{"type":"object","required":["component"],"additionalProperties":false,"properties":{"component":{"type":"string","minLength":1,"description":"The name of a component flagstaff has registered, e.g. 'log-tail' or 'tab-bar'."},"label":{"type":"string","description":"The text a static projection prints above the pane."}}}}}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Component } from './plugin.js';
|
|
2
|
+
export interface TabBarState {
|
|
3
|
+
/** The labels, in order. */
|
|
4
|
+
tabs: readonly string[];
|
|
5
|
+
/** Index of the active tab. Out of range, no tab is active and the static is empty. */
|
|
6
|
+
active: number;
|
|
7
|
+
}
|
|
8
|
+
export interface TabBarOptions {
|
|
9
|
+
/** Drawn between tabs, muted. Default ` · `. */
|
|
10
|
+
separator?: string;
|
|
11
|
+
}
|
|
12
|
+
/** A tab bar: the active label off a terminal, every tab with the active one marked on one. */
|
|
13
|
+
export declare function tabBar({ separator }?: TabBarOptions): Component<TabBarState>;
|
package/dist/tab-bar.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { heading, muted } from 'roundel/tokens';
|
|
2
|
+
import { register } from './plugin.js';
|
|
3
|
+
const SEPARATOR = ' · ';
|
|
4
|
+
function marked(label) {
|
|
5
|
+
const painted = heading(label);
|
|
6
|
+
return painted === label ? `[${label}]` : painted;
|
|
7
|
+
}
|
|
8
|
+
export function tabBar({ separator = SEPARATOR } = {}) {
|
|
9
|
+
return {
|
|
10
|
+
name: 'tab-bar',
|
|
11
|
+
static: ({ tabs, active }) => tabs[active] ?? '',
|
|
12
|
+
frame: (_t, { tabs, active }) => tabs.map((tab, i) => (i === active ? marked(tab) : muted(tab))).join(muted(separator)),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const builtin = tabBar();
|
|
16
|
+
register({
|
|
17
|
+
name: 'flagstaff',
|
|
18
|
+
components: {
|
|
19
|
+
'tab-bar': {
|
|
20
|
+
static: builtin.static,
|
|
21
|
+
frame: builtin.frame,
|
|
22
|
+
sample: {
|
|
23
|
+
running: { tabs: ['Status', 'Tail logs', 'Visualizer'], active: 0 },
|
|
24
|
+
done: { tabs: ['Status', 'Tail logs', 'Visualizer'], active: 1 },
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
});
|
package/dist/tasks.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { error, hint, muted, ok, warn } from 'roundel/tokens';
|
|
2
2
|
import { glyph, lookupSpinner } from './plugin.js';
|
|
3
3
|
const PAINT = { ok, fail: error, warn, info: hint };
|
|
4
|
-
const PENDING = ' ';
|
|
5
4
|
const settled = (status) => status !== 'pending' && status !== 'running';
|
|
6
5
|
export function tasks({ spinner = 'dots' } = {}) {
|
|
7
6
|
const style = lookupSpinner(spinner);
|
|
@@ -9,7 +8,7 @@ export function tasks({ spinner = 'dots' } = {}) {
|
|
|
9
8
|
if (settled(status))
|
|
10
9
|
return PAINT[status](glyph(status));
|
|
11
10
|
if (status === 'pending')
|
|
12
|
-
return muted(
|
|
11
|
+
return muted(glyph('pending'));
|
|
13
12
|
const at = Math.floor(t / style.interval) % style.frames.length;
|
|
14
13
|
return style.frames[at] ?? '';
|
|
15
14
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flagstaff",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "The staff the flag flies from. A terminal frame loop with a static projection for agents and screen readers, and a plugin host for spinners, progress, boxes and tables. Drop-in paths for ora, log-update, boxen and cli-table3. No dependency outside the burgee family.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"sideEffects": ["./dist/cli.js"],
|
|
7
|
+
"sideEffects": ["./dist/cli.js", "./dist/log-tail.js", "./dist/tab-bar.js"],
|
|
8
8
|
"engines": {
|
|
9
9
|
"node": "^20.19.0 || >=22.13.0"
|
|
10
10
|
},
|
|
@@ -65,6 +65,26 @@
|
|
|
65
65
|
"import": "./dist/tasks.js",
|
|
66
66
|
"default": "./dist/tasks.js"
|
|
67
67
|
},
|
|
68
|
+
"./log-tail": {
|
|
69
|
+
"types": "./dist/log-tail.d.ts",
|
|
70
|
+
"import": "./dist/log-tail.js",
|
|
71
|
+
"default": "./dist/log-tail.js"
|
|
72
|
+
},
|
|
73
|
+
"./tab-bar": {
|
|
74
|
+
"types": "./dist/tab-bar.d.ts",
|
|
75
|
+
"import": "./dist/tab-bar.js",
|
|
76
|
+
"default": "./dist/tab-bar.js"
|
|
77
|
+
},
|
|
78
|
+
"./markdown": {
|
|
79
|
+
"types": "./dist/markdown.d.ts",
|
|
80
|
+
"import": "./dist/markdown.js",
|
|
81
|
+
"default": "./dist/markdown.js"
|
|
82
|
+
},
|
|
83
|
+
"./diff": {
|
|
84
|
+
"types": "./dist/diff.d.ts",
|
|
85
|
+
"import": "./dist/diff.js",
|
|
86
|
+
"default": "./dist/diff.js"
|
|
87
|
+
},
|
|
68
88
|
"./box": {
|
|
69
89
|
"types": "./dist/box.d.ts",
|
|
70
90
|
"import": "./dist/box.js",
|
|
@@ -121,10 +141,10 @@
|
|
|
121
141
|
"json"
|
|
122
142
|
],
|
|
123
143
|
"dependencies": {
|
|
124
|
-
"closeout": "^0.
|
|
125
|
-
"linegauge": "^1.0.
|
|
126
|
-
"paratext": "^0.
|
|
127
|
-
"roundel": "^0.6.
|
|
144
|
+
"closeout": "^0.7.0",
|
|
145
|
+
"linegauge": "^1.0.4",
|
|
146
|
+
"paratext": "^0.9.0",
|
|
147
|
+
"roundel": "^0.6.3"
|
|
128
148
|
},
|
|
129
149
|
"devDependencies": {
|
|
130
150
|
"fast-check": "^4.10.2",
|