flagstaff 1.7.4 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -18
- package/dist/ora.d.ts +14 -3
- package/dist/ora.js +259 -140
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
<a href="https://burgee.interlace.tools/docs/compatibility"><img src="https://img.shields.io/badge/boxen%20suite-213%2F213-0a6b47?style=flat-square" alt="flagstaff/boxen passes 213 of 213 cases of the boxen test suite" /></a>
|
|
30
30
|
<a href="https://burgee.interlace.tools/docs/compatibility"><img src="https://img.shields.io/badge/cli--table3%20suite-29%2F29-0a6b47?style=flat-square" alt="flagstaff/cli-table3 passes 29 of 29 cases of the cli-table3 test suite" /></a>
|
|
31
31
|
<a href="https://burgee.interlace.tools/docs/compatibility"><img src="https://img.shields.io/badge/log--update%20suite-99%2F99-0a6b47?style=flat-square" alt="flagstaff/log-update passes 99 of 99 cases of the log-update test suite" /></a>
|
|
32
|
-
<a href="https://burgee.interlace.tools/docs/compatibility"><img src="https://img.shields.io/badge/ora%20suite-
|
|
32
|
+
<a href="https://burgee.interlace.tools/docs/compatibility"><img src="https://img.shields.io/badge/ora%20suite-223%2F223-0a6b47?style=flat-square" alt="flagstaff/ora passes 223 of 223 cases of the ora test suite" /></a>
|
|
33
33
|
</p>
|
|
34
34
|
|
|
35
35
|
<p align="center">
|
|
@@ -40,8 +40,7 @@
|
|
|
40
40
|
**flagstaff** is a terminal frame loop: it hoists a component, holds it, changes it and
|
|
41
41
|
lowers it. Every mode but the terminal gets a **static projection** — one line per state on a
|
|
42
42
|
pipe, one event per transition under `--json`, plain text for a screen reader — so no state is
|
|
43
|
-
lost to the log an agent reads back. Plugins are data
|
|
44
|
-
outside the burgee family.
|
|
43
|
+
lost to the log an agent reads back. Plugins are data, and there is no layout engine.
|
|
45
44
|
|
|
46
45
|
Drop-in for **ora**, **log-update**, **boxen** and **cli-table3**: `npx burgee migrate` moves
|
|
47
46
|
the imports, each path graded by the incumbent's own suite — see [Migrating](#migrating).
|
|
@@ -343,7 +342,7 @@ the change ([Migrate](https://burgee.interlace.tools/docs/migrate)).
|
|
|
343
342
|
|
|
344
343
|
### The ora path
|
|
345
344
|
|
|
346
|
-
`flagstaff/ora` is ora
|
|
345
|
+
`flagstaff/ora` is ora 10's whole API, graded **223 / 223 by ora's own test suite** through
|
|
347
346
|
[`compat-oracle`](https://github.com/ofri-peretz/burgee/blob/main/packages/compat-oracle/README.md). One import changes:
|
|
348
347
|
|
|
349
348
|
```diff
|
|
@@ -354,22 +353,21 @@ the change ([Migrate](https://burgee.interlace.tools/docs/migrate)).
|
|
|
354
353
|
Everything else stays: `ora({ text, spinner, color, indent, prefixText, suffixText })`,
|
|
355
354
|
`.start() .stop() .succeed() .fail() .warn() .info() .stopAndPersist()`, `oraPromise()`,
|
|
356
355
|
the `spinners` corpus, the stream hooks that keep a `console.log` above the frame, the
|
|
357
|
-
synchronized-output sequences, the
|
|
356
|
+
synchronized-output sequences, the pause while another writer's line is unfinished, the frame
|
|
357
|
+
kept above the last row of the screen, the stdin discarder.
|
|
358
358
|
|
|
359
|
-
What changes is the bill. ora
|
|
359
|
+
What changes is the bill. ora 10.0.0 ships 128,182 B of JavaScript across **seventeen
|
|
360
360
|
packages** — ora, chalk, cli-spinners, string-width, log-symbols, cli-cursor,
|
|
361
361
|
restore-cursor, onetime, mimic-function, signal-exit, is-interactive, is-unicode-supported,
|
|
362
362
|
stdin-discarder, yoctocolors, strip-ansi, ansi-regex, get-east-asian-width. `flagstaff/ora`
|
|
363
|
-
is
|
|
363
|
+
is 53,486 B across **two** — itself and roundel — **42% of ora's**, and 20,250 B of that is
|
|
364
364
|
the spinner corpus ora's API re-exports. Nothing in it reaches the frame loop, so a program
|
|
365
365
|
that migrates its spinner today can adopt `hoist()` a file at a time, or never ([measured](https://burgee.interlace.tools/docs/benchmarks)).
|
|
366
366
|
|
|
367
367
|
Both sides are counted the same way, so the number reproduces: shipped code and data —
|
|
368
368
|
`.js`/`.mjs`/`.cjs` plus the `.json` a module imports, `package.json` never counted. Ours is
|
|
369
369
|
the import graph walked from `dist/` by `weight.test.ts`; ora's is every package that graph
|
|
370
|
-
touches in ora's own resolved tree, counted whole.
|
|
371
|
-
27 files its graph actually reaches — gives 101,809 B, and `flagstaff/ora` is still 55% of
|
|
372
|
-
that ([measured](https://burgee.interlace.tools/docs/benchmarks)).
|
|
370
|
+
touches in ora's own resolved tree, counted whole ([measured](https://burgee.interlace.tools/docs/benchmarks)).
|
|
373
371
|
|
|
374
372
|
The cursor comes back the way ora's does. A spinner that hid the cursor restores it on a
|
|
375
373
|
clean exit **and** on `SIGINT`, `SIGTERM` and `SIGHUP` — node does not run `'exit'`
|
|
@@ -405,7 +403,7 @@ screen, not the bytes.
|
|
|
405
403
|
`logUpdateStderr`, with the row-level diffing intact: a five-row frame whose last row is a
|
|
406
404
|
counter costs one row of output per tick, not five.
|
|
407
405
|
|
|
408
|
-
log-update ships
|
|
406
|
+
log-update ships 114.3 KB across **sixteen** packages. This subpath reaches two, both from
|
|
409
407
|
this repository: `linegauge/wrap` for the wrapper, and `closeout` for the cursor.
|
|
410
408
|
It carries no port of `slice-ansi` — the wrapper already makes every row self-contained,
|
|
411
409
|
so clipping a frame to the terminal's height is an array slice. `signal-exit`, 22.0 KB of
|
|
@@ -487,10 +485,10 @@ path instead. The current grades are generated under *Benchmarks* below and publ
|
|
|
487
485
|
Every subpath is a lock, not a convention, and the numbers below are asserted by
|
|
488
486
|
`weight.test.ts` against `dist/`, not estimated: `flagstaff/loop` reaches 4.4 KB on disk and
|
|
489
487
|
never the plugin registry; `flagstaff/plugin` 8.4 KB, of which 2.4 KB is the schema;
|
|
490
|
-
`flagstaff/spinner` 9.4 KB; `flagstaff/ora`
|
|
491
|
-
ora's own
|
|
492
|
-
log-update's own
|
|
493
|
-
roundel counted, against boxen 9's own
|
|
488
|
+
`flagstaff/spinner` 9.4 KB; `flagstaff/ora` 44.1 KB — 53.5 KB with roundel counted, against
|
|
489
|
+
ora 10's own 128.2 KB; `flagstaff/log-update` 29.6 KB, against
|
|
490
|
+
log-update's own 114.3 KB across sixteen, reaching only `linegauge/wrap` and `closeout`; `flagstaff/boxen` 17.6 KB — 67.8 KB with linegauge and
|
|
491
|
+
roundel counted, against boxen 9's own 115.8 KB across fourteen; `flagstaff/cli-table3` 32.9 KB —
|
|
494
492
|
42.3 KB with roundel, against cli-table3's own 106.0 KB across seven. The three façades share `wrap.js` and
|
|
495
493
|
`width.js`, and the first two share `closeout`; none reaches another's port, and none
|
|
496
494
|
reaches the core. `sideEffects: false` lets a
|
|
@@ -508,7 +506,7 @@ Graded by the incumbent's own test suite:
|
|
|
508
506
|
| `boxen` | 213 / 213 |
|
|
509
507
|
| `cli-table3` | 29 / 29 |
|
|
510
508
|
| `log-update` | 99 / 99 |
|
|
511
|
-
| `ora` |
|
|
509
|
+
| `ora` | 223 / 223 |
|
|
512
510
|
|
|
513
511
|
## For agents
|
|
514
512
|
|
|
@@ -552,13 +550,14 @@ Plugins register under the `tokens`, `glyphs`, `spinners`, `borders`, `component
|
|
|
552
550
|
|
|
553
551
|
## The family
|
|
554
552
|
|
|
555
|
-
|
|
553
|
+
Eleven packages, one repository, one release pipeline. Each installs and works on its own, and each
|
|
556
554
|
owns one job. Six of them — `bellpull`, `closeout`, `linegauge`, `paratext`, `roundel`, `seniority`
|
|
557
555
|
— depend on nothing; the others depend only on packages in this table, and every dependency points
|
|
558
556
|
one way, down the [layers](https://burgee.interlace.tools/docs/concepts/family).
|
|
559
557
|
|
|
560
558
|
No package declares a dependency from outside the family; `react` and `react-reconciler` are
|
|
561
|
-
optional peers of `controlroom`, which npm does not install
|
|
559
|
+
optional peers of `controlroom`, which npm does not install; `vitest` is an optional peer of
|
|
560
|
+
`oxmutate`, which npm does not install.
|
|
562
561
|
[`package-shape-lock`](https://github.com/ofri-peretz/burgee/blob/main/scripts/package-shape-lock.test.ts)
|
|
563
562
|
holds that for every manifest, and
|
|
564
563
|
[`independence-install-lock`](https://github.com/ofri-peretz/burgee/blob/main/scripts/independence-install-lock.test.ts)
|
|
@@ -581,6 +580,7 @@ keeps both true.
|
|
|
581
580
|
| [closeout](https://closeout.interlace.tools/docs) | Exit handlers, terminal restore and a bounded shutdown | signal-exit, exit-hook, restore-cursor, cli-cursor and onetime |
|
|
582
581
|
| [bellpull](https://bellpull.interlace.tools/docs) | Subprocesses, and which executable actually ran | cross-spawn and which |
|
|
583
582
|
| [controlroom](https://controlroom.interlace.tools/docs) | Keyboard-driven terminal screens, inline or full-screen | ink |
|
|
583
|
+
| [oxmutate](https://oxmutate.interlace.tools/docs) | Mutation testing on the oxc engine, inside your own Vitest | Stryker |
|
|
584
584
|
|
|
585
585
|
Every migration guide, and the family-wide [compatibility](https://burgee.interlace.tools/docs/compatibility)
|
|
586
586
|
and [benchmarks](https://burgee.interlace.tools/docs/benchmarks) pages, are on
|
package/dist/ora.d.ts
CHANGED
|
@@ -71,6 +71,12 @@ export declare class Ora {
|
|
|
71
71
|
set isSilent(value: boolean);
|
|
72
72
|
frame(): string;
|
|
73
73
|
clear(): this;
|
|
74
|
+
/**
|
|
75
|
+
* A stream without the readline cursor methods — a CI log stream that reports a TTY — gets
|
|
76
|
+
* the frame written where the cursor is. Unfinished external output is left alone until its
|
|
77
|
+
* newline, with no timeout: resized rows cannot be counted reliably, and a replay would
|
|
78
|
+
* duplicate rows already in scrollback.
|
|
79
|
+
*/
|
|
74
80
|
render(): this;
|
|
75
81
|
start(text?: string): this;
|
|
76
82
|
stop(): this;
|
|
@@ -78,8 +84,13 @@ export declare class Ora {
|
|
|
78
84
|
fail(text?: string): this;
|
|
79
85
|
warn(text?: string): this;
|
|
80
86
|
info(text?: string): this;
|
|
81
|
-
stopAndPersist(options?: PersistOptions): this;
|
|
87
|
+
stopAndPersist(options?: PersistOptions | null): this;
|
|
82
88
|
}
|
|
83
89
|
export default function ora(options?: Options | string): Ora;
|
|
84
|
-
/**
|
|
85
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Run an action under a spinner, and land on the right symbol whichever way it ends. The
|
|
92
|
+
* action's own outcome wins: a `failText` that throws, or a persist the stream cannot write,
|
|
93
|
+
* never replaces the action's error, and a persist that fails never discards its result. A
|
|
94
|
+
* `successText` that throws is the caller's error and is not drawn as a failure.
|
|
95
|
+
*/
|
|
96
|
+
export declare function oraPromise<T>(action: Promise<T> | ((spinner: Ora) => Promise<T>), options?: PromiseOptions<T> | string | null): Promise<T>;
|
package/dist/ora.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
2
|
import { HIDE_CURSOR, rawMode, SHOW_CURSOR } from 'closeout/cursor';
|
|
3
3
|
import restoreCursor from 'closeout/restore-cursor';
|
|
4
|
-
import {
|
|
4
|
+
import { strip, width } from 'linegauge';
|
|
5
5
|
import { beginSynchronizedOutput, endSynchronizedOutput } from 'paratext/csi';
|
|
6
6
|
import chalk from 'roundel/chalk';
|
|
7
7
|
import { unicode } from 'roundel/terminal';
|
|
@@ -72,10 +72,65 @@ class StdinDiscarder {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
const stdinDiscarder = new StdinDiscarder();
|
|
75
|
-
const RENDER_DEFERRAL_TIMEOUT = 200;
|
|
76
75
|
const FALLBACK_INTERVAL = 100;
|
|
77
76
|
const DEFAULT_COLUMNS = 80;
|
|
78
|
-
const
|
|
77
|
+
const TRUNCATION_MESSAGE = '... (content truncated to fit terminal)';
|
|
78
|
+
const STYLE_RESET = '\u001B[0m';
|
|
79
|
+
const TAB_STOP = 8;
|
|
80
|
+
let graphemes;
|
|
81
|
+
const segmenter = () => (graphemes ??= new Intl.Segmenter());
|
|
82
|
+
const CONTROL_CHARACTER = /([\t\n\r])/u;
|
|
83
|
+
const PRINTABLE_ASCII = /^[ -~]+$/u;
|
|
84
|
+
const tabStopWidth = (column, columns) => {
|
|
85
|
+
const nextStop = Math.floor(column / TAB_STOP) * TAB_STOP + TAB_STOP;
|
|
86
|
+
return Math.max(0, Math.min(nextStop, columns - 1) - column);
|
|
87
|
+
};
|
|
88
|
+
function layOut(text, columns) {
|
|
89
|
+
const rows = [];
|
|
90
|
+
let cells = [];
|
|
91
|
+
let column = 0;
|
|
92
|
+
let expandedText = '';
|
|
93
|
+
const startRow = () => {
|
|
94
|
+
cells = [];
|
|
95
|
+
column = 0;
|
|
96
|
+
rows.push(cells);
|
|
97
|
+
};
|
|
98
|
+
const writeGrapheme = (grapheme, cellWidth) => {
|
|
99
|
+
if (cellWidth === 0)
|
|
100
|
+
return;
|
|
101
|
+
if (column + cellWidth > columns)
|
|
102
|
+
startRow();
|
|
103
|
+
cells[column++] = grapheme;
|
|
104
|
+
for (let index = 1; index < cellWidth; index += 1)
|
|
105
|
+
cells[column++] = '';
|
|
106
|
+
};
|
|
107
|
+
const writeTab = () => {
|
|
108
|
+
const end = column + tabStopWidth(column, columns);
|
|
109
|
+
expandedText += ' '.repeat(end - column);
|
|
110
|
+
for (; column < end; column += 1)
|
|
111
|
+
cells[column] ??= ' ';
|
|
112
|
+
};
|
|
113
|
+
startRow();
|
|
114
|
+
for (const part of strip(text).split(CONTROL_CHARACTER)) {
|
|
115
|
+
if (part === '\t') {
|
|
116
|
+
writeTab();
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
expandedText += part;
|
|
120
|
+
if (part === '\n')
|
|
121
|
+
startRow();
|
|
122
|
+
else if (part === '\r')
|
|
123
|
+
column = 0;
|
|
124
|
+
else if (PRINTABLE_ASCII.test(part))
|
|
125
|
+
for (const character of part)
|
|
126
|
+
writeGrapheme(character, 1);
|
|
127
|
+
else
|
|
128
|
+
for (const { segment } of segmenter().segment(part))
|
|
129
|
+
writeGrapheme(segment, width(segment));
|
|
130
|
+
}
|
|
131
|
+
return { rows, expandedText };
|
|
132
|
+
}
|
|
133
|
+
const rowCount = (text, columns) => layOut(text, columns).rows.length;
|
|
79
134
|
const activeHooksPerStream = new Map();
|
|
80
135
|
const writeHooks = new WeakMap();
|
|
81
136
|
const validColors = new Set(['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'gray']);
|
|
@@ -84,10 +139,26 @@ function paint(color, text) {
|
|
|
84
139
|
return text;
|
|
85
140
|
return chalk[color]?.(text) ?? text;
|
|
86
141
|
}
|
|
142
|
+
function formatAffix(value, separator, placeBefore) {
|
|
143
|
+
const resolved = typeof value === 'function' ? value() : value;
|
|
144
|
+
if (typeof resolved === 'string' && resolved !== '')
|
|
145
|
+
return placeBefore ? separator + resolved : resolved + separator;
|
|
146
|
+
return '';
|
|
147
|
+
}
|
|
148
|
+
function buildOutputLine(symbol, text, prefixText, suffixText) {
|
|
149
|
+
const hasSymbol = symbol !== '';
|
|
150
|
+
const hasText = typeof text === 'string' && text !== '';
|
|
151
|
+
const fullPrefixText = formatAffix(prefixText, hasSymbol || hasText ? ' ' : '', false);
|
|
152
|
+
const fullText = typeof text === 'string' ? (hasSymbol ? ' ' : '') + text : '';
|
|
153
|
+
const bodyEndsWithSeparator = hasSymbol && text === '';
|
|
154
|
+
return fullPrefixText + symbol + fullText + formatAffix(suffixText, bodyEndsWithSeparator ? '' : ' ', true);
|
|
155
|
+
}
|
|
87
156
|
export class Ora {
|
|
88
157
|
#linesToClear = 0;
|
|
89
158
|
#frameIndex = -1;
|
|
90
159
|
#lastFrameTime = 0;
|
|
160
|
+
#renderedFrame;
|
|
161
|
+
#renderedColumns;
|
|
91
162
|
#options;
|
|
92
163
|
#spinner;
|
|
93
164
|
#stream;
|
|
@@ -95,19 +166,19 @@ export class Ora {
|
|
|
95
166
|
#hookedStreams = new Map();
|
|
96
167
|
#isInternalWrite = false;
|
|
97
168
|
#drainHandler;
|
|
98
|
-
#
|
|
169
|
+
#hasUnfinishedLine = false;
|
|
99
170
|
#isDiscardingStdin = false;
|
|
100
171
|
#color;
|
|
101
172
|
constructor(options) {
|
|
102
173
|
const given = typeof options === 'string' ? { text: options } : options;
|
|
103
174
|
this.#options = { color: 'cyan', stream: rt.stderr, discardStdin: true, hideCursor: true, isEnabled: false, isSilent: false, indent: 0, ...given };
|
|
104
175
|
this.color = this.#options.color;
|
|
105
|
-
this.#stream = this.#options.stream;
|
|
176
|
+
this.#stream = this.#options.stream ?? rt.stderr;
|
|
106
177
|
if (typeof given?.isEnabled !== 'boolean')
|
|
107
178
|
this.#options.isEnabled = isInteractive(this.#stream);
|
|
108
179
|
if (typeof given?.isSilent !== 'boolean')
|
|
109
180
|
this.#options.isSilent = false;
|
|
110
|
-
if (this.#options.interval !== undefined && !(Number.
|
|
181
|
+
if (this.#options.interval !== undefined && !(Number.isSafeInteger(this.#options.interval) && this.#options.interval > 0)) {
|
|
111
182
|
throw new Error('The `interval` option must be a positive integer');
|
|
112
183
|
}
|
|
113
184
|
const userInterval = this.#options.interval;
|
|
@@ -131,15 +202,13 @@ export class Ora {
|
|
|
131
202
|
},
|
|
132
203
|
});
|
|
133
204
|
Object.defineProperty(this, '_frameIndex', { get: () => this.#frameIndex });
|
|
205
|
+
Object.defineProperty(this, '_renderedFrame', { get: () => this.#renderedFrame });
|
|
206
|
+
Object.defineProperty(this, '_renderedColumns', { get: () => this.#renderedColumns });
|
|
134
207
|
Object.defineProperty(this, '_lineCount', {
|
|
135
208
|
get: () => {
|
|
136
|
-
const
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
const fullPrefixText = typeof prefixText === 'string' && prefixText !== '' ? `${prefixText} ` : '';
|
|
140
|
-
const fullSuffixText = typeof suffixText === 'string' && suffixText !== '' ? ` ${suffixText}` : '';
|
|
141
|
-
const text = typeof this.#options.text === 'string' ? ` ${this.#options.text}` : '';
|
|
142
|
-
return lineCount(`${' '.repeat(this.#options.indent)}${fullPrefixText}-${text}${fullSuffixText}`, columns);
|
|
209
|
+
const { prefixText, suffixText } = this.#options;
|
|
210
|
+
const line = buildOutputLine('-', this.#options.text, typeof prefixText === 'function' ? '' : prefixText, typeof suffixText === 'function' ? '' : suffixText);
|
|
211
|
+
return rowCount(' '.repeat(this.#options.indent) + line, this.#columns);
|
|
143
212
|
},
|
|
144
213
|
});
|
|
145
214
|
}
|
|
@@ -148,7 +217,7 @@ export class Ora {
|
|
|
148
217
|
}
|
|
149
218
|
set indent(indent) {
|
|
150
219
|
const value = indent === undefined ? 0 : indent;
|
|
151
|
-
if (!(value >= 0 && Number.
|
|
220
|
+
if (!(value >= 0 && Number.isSafeInteger(value)))
|
|
152
221
|
throw new Error('The `indent` option must be an integer from 0 and up');
|
|
153
222
|
this.#options.indent = value;
|
|
154
223
|
}
|
|
@@ -159,27 +228,27 @@ export class Ora {
|
|
|
159
228
|
return this.#spinner;
|
|
160
229
|
}
|
|
161
230
|
set spinner(spinner) {
|
|
162
|
-
|
|
163
|
-
this.#options.interval = undefined;
|
|
164
|
-
if (typeof spinner === 'object') {
|
|
231
|
+
if (typeof spinner === 'object' && spinner !== null) {
|
|
165
232
|
if (!Array.isArray(spinner.frames) || spinner.frames.length === 0 || spinner.frames.some((frame) => typeof frame !== 'string')) {
|
|
166
233
|
throw new Error('The given spinner must have a non-empty `frames` array of strings');
|
|
167
234
|
}
|
|
168
|
-
if (spinner.interval !== undefined && !(Number.
|
|
235
|
+
if (spinner.interval !== undefined && !(Number.isSafeInteger(spinner.interval) && spinner.interval > 0)) {
|
|
169
236
|
throw new Error('`spinner.interval` must be a positive integer if provided');
|
|
170
237
|
}
|
|
171
238
|
this.#spinner = spinner;
|
|
172
|
-
return;
|
|
173
239
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
else
|
|
178
|
-
this.#spinner = spinners['dots'];
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
240
|
+
else if (spinner !== undefined && (spinner === 'default' || !Object.hasOwn(spinners, spinner))) {
|
|
241
|
+
throw new Error(`There is no built-in spinner named '${String(spinner)}'. See https://github.com/sindresorhus/cli-spinners/blob/main/spinners.json for a full list.`);
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
this.#spinner = (unicode(rt) ? spinners[spinner ?? 'dots'] : spinners['line']);
|
|
245
|
+
}
|
|
246
|
+
this.#frameIndex = -1;
|
|
247
|
+
this.#options.interval = undefined;
|
|
248
|
+
if (!this.isSpinning)
|
|
249
|
+
return;
|
|
250
|
+
this.#startRenderTimer();
|
|
251
|
+
this.render();
|
|
183
252
|
}
|
|
184
253
|
get text() {
|
|
185
254
|
return this.#options.text;
|
|
@@ -233,29 +302,18 @@ export class Ora {
|
|
|
233
302
|
this.#lastFrameTime = now;
|
|
234
303
|
}
|
|
235
304
|
const frame = paint(this.#color, this.#spinner.frames[this.#frameIndex] ?? '');
|
|
236
|
-
|
|
237
|
-
return this.#fullPrefixText() + frame + text + this.#fullSuffixText();
|
|
305
|
+
return ' '.repeat(this.#options.indent) + buildOutputLine(frame, this.text, this.#options.prefixText, this.#options.suffixText);
|
|
238
306
|
}
|
|
239
307
|
clear() {
|
|
240
|
-
if (!this.isEnabled
|
|
308
|
+
if (!this.isEnabled)
|
|
241
309
|
return this;
|
|
242
|
-
this.#
|
|
243
|
-
this.#stream.cursorTo?.(0);
|
|
244
|
-
for (let index = 0; index < this.#linesToClear; index += 1) {
|
|
245
|
-
if (index > 0)
|
|
246
|
-
this.#stream.moveCursor?.(0, -1);
|
|
247
|
-
this.#stream.clearLine?.(1);
|
|
248
|
-
}
|
|
249
|
-
if (this.#options.indent)
|
|
250
|
-
this.#stream.cursorTo?.(this.#options.indent);
|
|
251
|
-
return undefined;
|
|
252
|
-
});
|
|
253
|
-
this.#linesToClear = 0;
|
|
310
|
+
this.#clearDisplay();
|
|
254
311
|
return this;
|
|
255
312
|
}
|
|
256
313
|
render() {
|
|
257
|
-
if (!this.isEnabled || this.#drainHandler || this.#
|
|
314
|
+
if (!this.isEnabled || this.#drainHandler || this.#hasUnfinishedLine)
|
|
258
315
|
return this;
|
|
316
|
+
let frameContent = this.frame();
|
|
259
317
|
const useSynchronizedOutput = this.#stream.isTTY === true;
|
|
260
318
|
let shouldDisableSynchronizedOutput = false;
|
|
261
319
|
try {
|
|
@@ -263,14 +321,19 @@ export class Ora {
|
|
|
263
321
|
this.#internalWrite(() => this.#stream.write(beginSynchronizedOutput));
|
|
264
322
|
shouldDisableSynchronizedOutput = true;
|
|
265
323
|
}
|
|
266
|
-
this
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
324
|
+
if (this.#linesToClear > 0)
|
|
325
|
+
this.#clearDisplay();
|
|
326
|
+
else if (this.#canMoveCursor(this.#stream)) {
|
|
327
|
+
const stream = this.#stream;
|
|
328
|
+
this.#internalWrite(() => stream.cursorTo(0));
|
|
329
|
+
}
|
|
330
|
+
const columns = this.#columns;
|
|
331
|
+
let layout = layOut(frameContent, columns);
|
|
332
|
+
const rows = this.#stream.rows;
|
|
333
|
+
const maxRows = rows !== undefined && rows > 1 ? rows - 1 : undefined;
|
|
334
|
+
if (maxRows !== undefined && layout.rows.length > maxRows) {
|
|
335
|
+
frameContent = truncateFrame(frameContent, columns, maxRows);
|
|
336
|
+
layout = layOut(frameContent, columns);
|
|
274
337
|
}
|
|
275
338
|
const canContinue = this.#internalWrite(() => this.#stream.write(frameContent));
|
|
276
339
|
if (canContinue === false && this.#stream.isTTY === true) {
|
|
@@ -280,7 +343,9 @@ export class Ora {
|
|
|
280
343
|
};
|
|
281
344
|
this.#stream.once?.('drain', this.#drainHandler);
|
|
282
345
|
}
|
|
283
|
-
this.#linesToClear =
|
|
346
|
+
this.#linesToClear = layout.rows.length;
|
|
347
|
+
this.#renderedFrame = layout.expandedText;
|
|
348
|
+
this.#renderedColumns = columns;
|
|
284
349
|
}
|
|
285
350
|
finally {
|
|
286
351
|
if (shouldDisableSynchronizedOutput)
|
|
@@ -291,17 +356,15 @@ export class Ora {
|
|
|
291
356
|
start(text) {
|
|
292
357
|
if (text !== undefined)
|
|
293
358
|
this.text = text;
|
|
294
|
-
if (this.isSilent)
|
|
359
|
+
if (this.isSpinning || this.isSilent)
|
|
295
360
|
return this;
|
|
296
361
|
if (!this.isEnabled) {
|
|
297
362
|
const symbol = this.text ? '-' : '';
|
|
298
|
-
const line = ' '.repeat(this.#options.indent) +
|
|
363
|
+
const line = ' '.repeat(this.#options.indent) + buildOutputLine(symbol, this.text, this.#options.prefixText, this.#options.suffixText);
|
|
299
364
|
if (line.trim() !== '')
|
|
300
365
|
this.#internalWrite(() => this.#stream.write(`${line}\n`));
|
|
301
366
|
return this;
|
|
302
367
|
}
|
|
303
|
-
if (this.isSpinning)
|
|
304
|
-
return this;
|
|
305
368
|
if (this.#options.hideCursor)
|
|
306
369
|
this.#hideCursor();
|
|
307
370
|
if (this.#options.discardStdin && rt.stdin.isTTY) {
|
|
@@ -309,30 +372,27 @@ export class Ora {
|
|
|
309
372
|
this.#isDiscardingStdin = true;
|
|
310
373
|
}
|
|
311
374
|
this.#installHook();
|
|
312
|
-
|
|
313
|
-
|
|
375
|
+
try {
|
|
376
|
+
this.render();
|
|
377
|
+
}
|
|
378
|
+
catch (error) {
|
|
379
|
+
this.#release();
|
|
380
|
+
this.#showCursor();
|
|
381
|
+
throw error;
|
|
382
|
+
}
|
|
383
|
+
this.#startRenderTimer();
|
|
314
384
|
return this;
|
|
315
385
|
}
|
|
316
386
|
stop() {
|
|
317
|
-
|
|
318
|
-
this.#
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
this.#clearRenderDeferral();
|
|
322
|
-
this.#uninstallHook();
|
|
323
|
-
if (this.#drainHandler) {
|
|
324
|
-
this.#stream.removeListener?.('drain', this.#drainHandler);
|
|
325
|
-
this.#drainHandler = undefined;
|
|
326
|
-
}
|
|
327
|
-
if (this.isEnabled) {
|
|
328
|
-
this.clear();
|
|
329
|
-
if (this.#options.hideCursor)
|
|
330
|
-
this.#showCursor();
|
|
387
|
+
const wasSpinning = this.isSpinning;
|
|
388
|
+
this.#release();
|
|
389
|
+
try {
|
|
390
|
+
this.#clearDisplay();
|
|
331
391
|
}
|
|
332
|
-
|
|
333
|
-
this.#isDiscardingStdin = false;
|
|
334
|
-
stdinDiscarder.stop();
|
|
392
|
+
catch {
|
|
335
393
|
}
|
|
394
|
+
if (wasSpinning)
|
|
395
|
+
this.#showCursor();
|
|
336
396
|
return this;
|
|
337
397
|
}
|
|
338
398
|
succeed(text) {
|
|
@@ -347,15 +407,17 @@ export class Ora {
|
|
|
347
407
|
info(text) {
|
|
348
408
|
return this.stopAndPersist({ symbol: logSymbols.info, ...(text === undefined ? {} : { text }) });
|
|
349
409
|
}
|
|
350
|
-
stopAndPersist(options
|
|
410
|
+
stopAndPersist(options) {
|
|
411
|
+
const hasUnfinishedLine = this.#hasUnfinishedLine;
|
|
412
|
+
this.stop();
|
|
351
413
|
if (this.isSilent)
|
|
352
414
|
return this;
|
|
353
|
-
const
|
|
354
|
-
const
|
|
355
|
-
const
|
|
356
|
-
const
|
|
357
|
-
const
|
|
358
|
-
this.
|
|
415
|
+
const symbolText = String(options?.symbol ?? ' ');
|
|
416
|
+
const symbol = this.isEnabled && this.#stream.isTTY === true ? symbolText : strip(symbolText);
|
|
417
|
+
const text = options?.text ?? this.text;
|
|
418
|
+
const prefixText = options?.prefixText ?? this.#options.prefixText;
|
|
419
|
+
const suffixText = options?.suffixText ?? this.#options.suffixText;
|
|
420
|
+
const textToWrite = `${hasUnfinishedLine ? '\n' : ''}${' '.repeat(this.#options.indent)}${buildOutputLine(symbol, text, prefixText, suffixText)}\n`;
|
|
359
421
|
this.#internalWrite(() => this.#stream.write(textToWrite));
|
|
360
422
|
return this;
|
|
361
423
|
}
|
|
@@ -369,51 +431,79 @@ export class Ora {
|
|
|
369
431
|
}
|
|
370
432
|
}
|
|
371
433
|
#tryRender() {
|
|
372
|
-
if (this.isSpinning)
|
|
373
|
-
this.render();
|
|
374
|
-
}
|
|
375
|
-
#hideCursor() {
|
|
376
|
-
if (this.#stream.isTTY !== true)
|
|
434
|
+
if (!this.isSpinning)
|
|
377
435
|
return;
|
|
378
|
-
|
|
379
|
-
|
|
436
|
+
try {
|
|
437
|
+
this.render();
|
|
438
|
+
}
|
|
439
|
+
catch {
|
|
440
|
+
this.#release();
|
|
441
|
+
this.#showCursor();
|
|
442
|
+
}
|
|
380
443
|
}
|
|
381
|
-
#
|
|
382
|
-
|
|
444
|
+
#release() {
|
|
445
|
+
clearInterval(this.#id);
|
|
446
|
+
this.#id = undefined;
|
|
447
|
+
this.#frameIndex = -1;
|
|
448
|
+
this.#lastFrameTime = 0;
|
|
449
|
+
this.#uninstallHook();
|
|
450
|
+
if (this.#drainHandler) {
|
|
451
|
+
this.#stream.removeListener?.('drain', this.#drainHandler);
|
|
452
|
+
this.#drainHandler = undefined;
|
|
453
|
+
}
|
|
454
|
+
this.#hasUnfinishedLine = false;
|
|
455
|
+
if (!this.#isDiscardingStdin)
|
|
383
456
|
return;
|
|
384
|
-
this.#
|
|
457
|
+
this.#isDiscardingStdin = false;
|
|
458
|
+
stdinDiscarder.stop();
|
|
385
459
|
}
|
|
386
|
-
#
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
return placeBefore ? separator + resolved : resolved + separator;
|
|
390
|
-
return '';
|
|
460
|
+
#startRenderTimer() {
|
|
461
|
+
clearInterval(this.#id);
|
|
462
|
+
this.#id = setInterval(this.#tryRender.bind(this), this.interval);
|
|
391
463
|
}
|
|
392
|
-
#
|
|
393
|
-
return this.#
|
|
464
|
+
get #columns() {
|
|
465
|
+
return this.#stream.columns || DEFAULT_COLUMNS;
|
|
394
466
|
}
|
|
395
|
-
#
|
|
396
|
-
return
|
|
467
|
+
#canMoveCursor(stream) {
|
|
468
|
+
return stream.isTTY === true && typeof stream.cursorTo === 'function' && typeof stream.moveCursor === 'function' && typeof stream.clearLine === 'function';
|
|
397
469
|
}
|
|
398
|
-
#
|
|
399
|
-
const
|
|
400
|
-
|
|
401
|
-
|
|
470
|
+
#clearDisplay() {
|
|
471
|
+
const stream = this.#stream;
|
|
472
|
+
if (!this.#canMoveCursor(stream) || this.#linesToClear === 0)
|
|
473
|
+
return;
|
|
474
|
+
const columns = this.#columns;
|
|
475
|
+
if (this.#renderedFrame !== undefined && this.#renderedColumns !== columns) {
|
|
476
|
+
this.#linesToClear = Math.min(this.#linesToClear, rowCount(this.#renderedFrame, columns));
|
|
477
|
+
}
|
|
478
|
+
try {
|
|
479
|
+
const count = this.#linesToClear;
|
|
480
|
+
this.#internalWrite(() => {
|
|
481
|
+
stream.cursorTo(0);
|
|
482
|
+
for (let index = 0; index < count; index += 1) {
|
|
483
|
+
if (index > 0)
|
|
484
|
+
stream.moveCursor(0, -1);
|
|
485
|
+
stream.clearLine(1);
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
finally {
|
|
490
|
+
this.#linesToClear = 0;
|
|
491
|
+
this.#renderedFrame = undefined;
|
|
492
|
+
}
|
|
402
493
|
}
|
|
403
|
-
#
|
|
404
|
-
if (this.#
|
|
494
|
+
#hideCursor() {
|
|
495
|
+
if (this.#stream.isTTY !== true)
|
|
405
496
|
return;
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
if (this.isSpinning)
|
|
409
|
-
this.#tryRender();
|
|
410
|
-
}, RENDER_DEFERRAL_TIMEOUT);
|
|
411
|
-
this.#deferRenderTimer.unref?.();
|
|
497
|
+
restoreCursor();
|
|
498
|
+
this.#stream.write(HIDE_CURSOR);
|
|
412
499
|
}
|
|
413
|
-
#
|
|
414
|
-
if (this.#
|
|
415
|
-
|
|
416
|
-
|
|
500
|
+
#showCursor() {
|
|
501
|
+
if (!this.#options.hideCursor || this.#stream.isTTY !== true)
|
|
502
|
+
return;
|
|
503
|
+
try {
|
|
504
|
+
this.#stream.write(SHOW_CURSOR);
|
|
505
|
+
}
|
|
506
|
+
catch {
|
|
417
507
|
}
|
|
418
508
|
}
|
|
419
509
|
#installHook() {
|
|
@@ -452,19 +542,32 @@ export class Ora {
|
|
|
452
542
|
const [enc, cb] = typeof encoding === 'function' ? [undefined, encoding] : [encoding, callback];
|
|
453
543
|
if (this.#isInternalWrite)
|
|
454
544
|
return originalWrite.call(stream, chunk, enc, cb);
|
|
455
|
-
this
|
|
456
|
-
const chunkString = stringifyChunk(chunk, enc);
|
|
457
|
-
|
|
545
|
+
this.#clearDisplay();
|
|
546
|
+
const chunkString = strip(stringifyChunk(chunk, enc));
|
|
547
|
+
if (chunkString !== '')
|
|
548
|
+
this.#hasUnfinishedLine = !chunkString.endsWith('\n');
|
|
458
549
|
const writeResult = originalWrite.call(stream, chunk, enc, cb);
|
|
459
|
-
|
|
460
|
-
this.#clearRenderDeferral();
|
|
461
|
-
else if (chunkString.length > 0)
|
|
462
|
-
this.#scheduleRenderDeferral();
|
|
463
|
-
if (this.isSpinning && !this.#deferRenderTimer)
|
|
464
|
-
this.render();
|
|
550
|
+
this.#tryRender();
|
|
465
551
|
return writeResult;
|
|
466
552
|
}
|
|
467
553
|
}
|
|
554
|
+
function truncateFrame(frameContent, columns, maxRows) {
|
|
555
|
+
let message = TRUNCATION_MESSAGE;
|
|
556
|
+
while (message.length > 1 && rowCount(message, columns) > maxRows)
|
|
557
|
+
message = message.slice(0, -1);
|
|
558
|
+
let rowBudget = maxRows - rowCount(message, columns);
|
|
559
|
+
const keptLines = [];
|
|
560
|
+
for (const line of frameContent.split('\n')) {
|
|
561
|
+
const lineRows = layOut(line, columns).rows;
|
|
562
|
+
if (lineRows.length > rowBudget) {
|
|
563
|
+
keptLines.push(...lineRows.slice(0, rowBudget).map((cells) => cells.join('')));
|
|
564
|
+
break;
|
|
565
|
+
}
|
|
566
|
+
keptLines.push(line);
|
|
567
|
+
rowBudget -= lineRows.length;
|
|
568
|
+
}
|
|
569
|
+
return [...keptLines, STYLE_RESET + message].join('\n');
|
|
570
|
+
}
|
|
468
571
|
function stringifyChunk(chunk, encoding) {
|
|
469
572
|
if (chunk === undefined || chunk === null)
|
|
470
573
|
return '';
|
|
@@ -479,6 +582,7 @@ function stringifyChunk(chunk, encoding) {
|
|
|
479
582
|
export default function ora(options) {
|
|
480
583
|
return new Ora(options);
|
|
481
584
|
}
|
|
585
|
+
const resolveText = (value, argument) => (typeof value === 'function' ? value(argument) : value);
|
|
482
586
|
export async function oraPromise(action, options) {
|
|
483
587
|
const actionIsFunction = typeof action === 'function';
|
|
484
588
|
const actionIsPromise = typeof action?.then === 'function';
|
|
@@ -486,22 +590,37 @@ export async function oraPromise(action, options) {
|
|
|
486
590
|
throw new TypeError('Parameter `action` must be a Function or a Promise');
|
|
487
591
|
const settings = typeof options === 'object' && options !== null ? options : {};
|
|
488
592
|
const { successText, failText, successSymbol, failSymbol } = settings;
|
|
489
|
-
const spinner = ora(options).start();
|
|
593
|
+
const spinner = ora(options ?? undefined).start();
|
|
594
|
+
let result;
|
|
490
595
|
try {
|
|
491
|
-
|
|
492
|
-
const text = successText === undefined ? undefined : typeof successText === 'string' ? successText : successText(result);
|
|
493
|
-
if (successSymbol === undefined)
|
|
494
|
-
spinner.succeed(text);
|
|
495
|
-
else
|
|
496
|
-
spinner.stopAndPersist({ symbol: successSymbol, ...(text === undefined ? {} : { text }) });
|
|
497
|
-
return result;
|
|
596
|
+
result = await (actionIsFunction ? action(spinner) : action);
|
|
498
597
|
}
|
|
499
598
|
catch (error) {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
599
|
+
let text;
|
|
600
|
+
try {
|
|
601
|
+
text = resolveText(failText, error);
|
|
602
|
+
}
|
|
603
|
+
catch {
|
|
604
|
+
}
|
|
605
|
+
try {
|
|
606
|
+
spinner.stopAndPersist({ symbol: failSymbol ?? logSymbols.error, ...(text === undefined ? {} : { text }) });
|
|
607
|
+
}
|
|
608
|
+
catch {
|
|
609
|
+
}
|
|
610
|
+
throw error;
|
|
611
|
+
}
|
|
612
|
+
let text;
|
|
613
|
+
try {
|
|
614
|
+
text = resolveText(successText, result);
|
|
615
|
+
}
|
|
616
|
+
catch (error) {
|
|
617
|
+
spinner.stop();
|
|
505
618
|
throw error;
|
|
506
619
|
}
|
|
620
|
+
try {
|
|
621
|
+
spinner.stopAndPersist({ symbol: successSymbol ?? logSymbols.success, ...(text === undefined ? {} : { text }) });
|
|
622
|
+
}
|
|
623
|
+
catch {
|
|
624
|
+
}
|
|
625
|
+
return result;
|
|
507
626
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flagstaff",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.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",
|
|
@@ -164,7 +164,7 @@
|
|
|
164
164
|
],
|
|
165
165
|
"dependencies": {
|
|
166
166
|
"closeout": "^1.1.8",
|
|
167
|
-
"linegauge": "^1.
|
|
167
|
+
"linegauge": "^1.2.0",
|
|
168
168
|
"paratext": "^1.0.11",
|
|
169
169
|
"roundel": "^1.2.1"
|
|
170
170
|
},
|