flagstaff 1.3.0 → 1.4.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 +11 -0
- package/dist/schema.json +1 -1
- package/dist/table.d.ts +21 -0
- package/dist/table.js +32 -37
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -184,6 +184,17 @@ table([['ora', '99'], ['log-update', '99']], { head: ['host', 'tests'] });
|
|
|
184
184
|
No layout engine, and there will not be one: these measure with `width()`, wrap with
|
|
185
185
|
`wrap()`, and join strings.
|
|
186
186
|
|
|
187
|
+
A table column can be bounded. `columns` is positional, like `align`: `max` caps a column
|
|
188
|
+
whatever its content, and `min` keeps it open while another column can give way. Both count
|
|
189
|
+
the content's display width, not the padding. When the mins add up past `width`, the mins win
|
|
190
|
+
and the table is wider than asked. A cell wider than its column wraps; `overflow: 'truncate'`
|
|
191
|
+
cuts it to one row ending in `…` instead, by display width, with a link kept around what is
|
|
192
|
+
left. The static projection has no columns to cap, so it prints every cell whole.
|
|
193
|
+
|
|
194
|
+
```js
|
|
195
|
+
table(rows, { head: ['id', 'status'], columns: [{ max: 12, overflow: 'truncate' }, { min: 10 }] });
|
|
196
|
+
```
|
|
197
|
+
|
|
187
198
|
### A log tail and a tab bar
|
|
188
199
|
|
|
189
200
|
Two output-only components for screens built on flagstaff — controlroom's panes, or a plain
|
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: `1` today. A host refuses a newer contract than it knows, and burgee also refuses a plugin that declares none — `definePlugin` stamps it, a plain object writes `contract: 1`."},"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. Only `platform` and `envAny` are conditions: any other key is refused, because a condition nobody reads would make the resolver apply everywhere.","additionalProperties":false,"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. `spec` is the prompt — `{ kind, message }` plus any field the kind reads; `caique check` passes `{ kind, message: 'preview', ...sample.done }`."},"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, e.g. `{ running: { value: 0 }, done: { value: 4 } }`; each is spread into the `spec` that `static` receives."}}},"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. Lower wins, and the built-in layers are flag 0, environment 10, config file 20, package.json 30, default 40 — so 11 to 19 ranks above the config file and below the environment."},"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","required":["command"],"description":"`{ command: RegExp }`, e.g. `{ command: /^deploy/ }`: fire only for commands whose path, its words joined by spaces, matches. Leave it out and the hook fires for every command."},"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."}}}}}
|
|
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: `1` today. A host refuses a newer contract than it knows, and burgee also refuses a plugin that declares none — `definePlugin` stamps it, a plain object writes `contract: 1`."},"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."},"locales":{"type":"object","description":"burgee locale packs (localised-human-surfaces R4): a BCP 47 language tag, as Intl.Locale writes it, mapped to catalog ids and their translations. A message is a string, or for a message whose English carries a count placeholder, one string per plural form Intl.PluralRules selects for the locale. burgee/locale-pack-schema.json lists every id with its English; `burgee check` renders a pack or refuses it.","propertyNames":{"pattern":"^[a-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$"},"additionalProperties":{"type":"object","additionalProperties":{"anyOf":[{"type":"string"},{"type":"object","propertyNames":{"enum":["zero","one","two","few","many","other"]},"required":["other"],"additionalProperties":{"type":"string"}}]}}},"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. Only `platform` and `envAny` are conditions: any other key is refused, because a condition nobody reads would make the resolver apply everywhere.","additionalProperties":false,"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. `spec` is the prompt — `{ kind, message }` plus any field the kind reads; `caique check` passes `{ kind, message: 'preview', ...sample.done }`."},"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, e.g. `{ running: { value: 0 }, done: { value: 4 } }`; each is spread into the `spec` that `static` receives."}}},"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. Lower wins, and the built-in layers are flag 0, environment 10, config file 20, package.json 30, default 40 — so 11 to 19 ranks above the config file and below the environment."},"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","required":["command"],"description":"`{ command: RegExp }`, e.g. `{ command: /^deploy/ }`: fire only for commands whose path, its words joined by spaces, matches. Leave it out and the hook fires for every command."},"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."}}}}}
|
package/dist/table.d.ts
CHANGED
|
@@ -9,6 +9,11 @@ export interface TableOptions {
|
|
|
9
9
|
width?: number;
|
|
10
10
|
/** Alignment per column; `left` for any column not named. */
|
|
11
11
|
align?: ('left' | 'right')[];
|
|
12
|
+
/**
|
|
13
|
+
* Bounds per column, positional like `align`; a hole or a missing entry is unbounded. Both
|
|
14
|
+
* are content widths, as `width()` measures them, padding not counted.
|
|
15
|
+
*/
|
|
16
|
+
columns?: (ColumnOptions | undefined)[];
|
|
12
17
|
/**
|
|
13
18
|
* The terminal a linked cell is rendered for. Omitted, the real process is read through
|
|
14
19
|
* this package's seam. Supply one and the whole path is pure — which is how `link.test.ts`
|
|
@@ -16,6 +21,22 @@ export interface TableOptions {
|
|
|
16
21
|
*/
|
|
17
22
|
terminal?: Terminal;
|
|
18
23
|
}
|
|
24
|
+
/** One column's bounds (`table-column-widths` R1). */
|
|
25
|
+
export interface ColumnOptions {
|
|
26
|
+
/**
|
|
27
|
+
* How far the fit may narrow the column while another can still give way. A whole number
|
|
28
|
+
* from 0. It bounds the shrink and is not a width: a column narrower than it stays so.
|
|
29
|
+
*/
|
|
30
|
+
min?: number;
|
|
31
|
+
/** A cap no content pushes the column past. A whole number from 1, and at least `min`. */
|
|
32
|
+
max?: number;
|
|
33
|
+
/**
|
|
34
|
+
* What a cell wider than its column does (R3): `'wrap'` onto more physical rows, the
|
|
35
|
+
* default and the only behaviour before this option, or `'truncate'` to one row ending in
|
|
36
|
+
* `…`. A person's view only: the static projection carries the full cell either way (R4).
|
|
37
|
+
*/
|
|
38
|
+
overflow?: 'wrap' | 'truncate';
|
|
39
|
+
}
|
|
19
40
|
/** Draw `rows` as a table, as a string. */
|
|
20
41
|
export declare function table(rows: Row[], options?: TableOptions): string;
|
|
21
42
|
export interface TableState {
|
package/dist/table.js
CHANGED
|
@@ -1,57 +1,53 @@
|
|
|
1
1
|
import { width } from 'linegauge';
|
|
2
|
+
import { truncate } from 'linegauge/truncate';
|
|
2
3
|
import { wrap } from 'linegauge/wrap';
|
|
3
4
|
import { heading, muted } from 'roundel/tokens';
|
|
4
5
|
import { cellHref, cellText, laid, painted, painter, STATIC } from './link.js';
|
|
5
6
|
const DEFAULT_WIDTH = 80;
|
|
6
7
|
const CHROME_PER_COLUMN = 3;
|
|
7
|
-
const CHROME_FIXED = 1;
|
|
8
8
|
const MIN_COLUMN = 3;
|
|
9
9
|
const V = '│';
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return Array.from({ length: columns }, (_, index) => Math.max(0, ...rows.map((row) => width(laid(cellText(row[index]), cellHref(row[index]), paint)))));
|
|
18
|
-
}
|
|
19
|
-
function fitWidths(natural, available) {
|
|
20
|
-
const widths = [...natural];
|
|
21
|
-
let total = widths.reduce((sum, w) => sum + w, 0);
|
|
22
|
-
while (total > available) {
|
|
23
|
-
const widest = Math.max(...widths);
|
|
24
|
-
widths[widths.indexOf(widest)] = widest - 1;
|
|
25
|
-
total -= 1;
|
|
10
|
+
const lay = (cell, paint) => laid(cellText(cell), cellHref(cell), paint);
|
|
11
|
+
function fitWidths(widths, available, { columns: bounds = [] }) {
|
|
12
|
+
for (let total = widths.reduce((sum, w) => sum + w, 0); total > available; total--) {
|
|
13
|
+
const pick = widths.reduce((best, w, i) => (w > (bounds[i]?.min ?? MIN_COLUMN) && (best < 0 || w > widths[best]) ? i : best), -1);
|
|
14
|
+
if (pick < 0)
|
|
15
|
+
break;
|
|
16
|
+
widths.splice(pick, 1, widths[pick] - 1);
|
|
26
17
|
}
|
|
27
18
|
return widths;
|
|
28
19
|
}
|
|
29
|
-
function layoutRow(row, widths,
|
|
30
|
-
const cells = widths.map((w,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
.
|
|
20
|
+
function layoutRow(row, widths, options, paint) {
|
|
21
|
+
const cells = widths.map((w, i) => {
|
|
22
|
+
const text = lay(row[i], paint);
|
|
23
|
+
return options.columns?.[i]?.overflow === 'truncate' ? [truncate(text.replace(/\r?\n/g, ' '), w)] : wrap(text, w, { hard: true, trim: false }).split('\n');
|
|
24
|
+
});
|
|
25
|
+
const pad = (plain, room, i) => {
|
|
26
|
+
const gap = ' '.repeat(Math.max(0, room - width(plain)));
|
|
27
|
+
const line = painted(plain, cellHref(row[i]), paint);
|
|
28
|
+
return options.align?.[i] === 'right' ? gap + line : line + gap;
|
|
29
|
+
};
|
|
30
|
+
return Array.from({ length: Math.max(1, ...cells.map((lines) => lines.length)) }, (_, line) => `${V} ${widths.map((w, i) => pad(cells[i]?.[line] ?? '', w, i)).join(` ${V} `)} ${V}`);
|
|
38
31
|
}
|
|
39
|
-
const rule = (widths, left, mid, right) => left
|
|
32
|
+
const rule = (widths, [left, mid, right]) => `${left}${widths.map((w) => '─'.repeat(w + 2)).join(mid)}${right}`;
|
|
40
33
|
export function table(rows, options = {}) {
|
|
41
34
|
const columns = Math.max(options.head?.length ?? 0, ...rows.map((row) => row.length), 1);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
options.columns?.forEach((column, i) => {
|
|
36
|
+
const { min = 0, max = min || 1 } = column ?? {};
|
|
37
|
+
if ((min % 1) + (max % 1) !== 0 || min < 0 || max < Math.max(min, 1))
|
|
38
|
+
throw new TypeError(`flagstaff/table: columns[${i}] needs whole widths, 0 <= min <= max, max >= 1`);
|
|
39
|
+
});
|
|
40
|
+
const available = Math.max(columns * MIN_COLUMN, (options.width ?? DEFAULT_WIDTH) - columns * CHROME_PER_COLUMN - 1);
|
|
45
41
|
const paint = painter(options.terminal);
|
|
46
42
|
const all = options.head === undefined ? rows : [options.head, ...rows];
|
|
47
|
-
const widths = fitWidths(
|
|
48
|
-
const out = [rule(widths,
|
|
43
|
+
const widths = fitWidths(Array.from({ length: columns }, (_, i) => Math.min(options.columns?.[i]?.max ?? Infinity, Math.max(0, ...all.map((row) => width(lay(row[i], paint)))))), available, options);
|
|
44
|
+
const out = [rule(widths, '┌┬┐')];
|
|
49
45
|
if (options.head !== undefined) {
|
|
50
|
-
out.push(...layoutRow(options.head.map((cell) => heading(cell)), widths,
|
|
46
|
+
out.push(...layoutRow(options.head.map((cell) => heading(cell)), widths, options, paint), rule(widths, '├┼┤'));
|
|
51
47
|
}
|
|
52
48
|
for (const row of rows)
|
|
53
|
-
out.push(...layoutRow(row, widths,
|
|
54
|
-
out.push(rule(widths,
|
|
49
|
+
out.push(...layoutRow(row, widths, options, paint));
|
|
50
|
+
out.push(rule(widths, '└┴┘'));
|
|
55
51
|
return out.join('\n');
|
|
56
52
|
}
|
|
57
53
|
export function tableComponent(options = {}) {
|
|
@@ -60,9 +56,8 @@ export function tableComponent(options = {}) {
|
|
|
60
56
|
name: 'table',
|
|
61
57
|
static: (state) => {
|
|
62
58
|
const head = state.head ?? options.head;
|
|
63
|
-
const show = (cell) => laid(cellText(cell), cellHref(cell), plain);
|
|
64
59
|
return state.rows
|
|
65
|
-
.map((row) =>
|
|
60
|
+
.map((row) => row.map((cell, i) => (head === undefined ? '' : `${head[i] ?? i}: `) + lay(cell, plain)).join(head === undefined ? '\t' : ', '))
|
|
66
61
|
.join('\n');
|
|
67
62
|
},
|
|
68
63
|
frame: (_t, state) => muted(table(state.rows, state.head === undefined ? options : { ...options, head: state.head })),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flagstaff",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Spinners, progress, boxes and tables on one terminal frame loop, with a static projection for pipes, screen readers and agents, and a plugin host. No dependency outside the burgee family. Drop-in paths for ora, log-update, boxen and cli-table3.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -141,10 +141,10 @@
|
|
|
141
141
|
"json"
|
|
142
142
|
],
|
|
143
143
|
"dependencies": {
|
|
144
|
-
"closeout": "^1.1.
|
|
145
|
-
"linegauge": "^1.1.
|
|
146
|
-
"paratext": "^1.0.
|
|
147
|
-
"roundel": "^1.1.
|
|
144
|
+
"closeout": "^1.1.2",
|
|
145
|
+
"linegauge": "^1.1.1",
|
|
146
|
+
"paratext": "^1.0.6",
|
|
147
|
+
"roundel": "^1.1.1"
|
|
148
148
|
},
|
|
149
149
|
"devDependencies": {
|
|
150
150
|
"fast-check": "^4.10.2",
|