| ... | @@ -144,7 +144,7 @@ export interface Node extends Ref, Disposable { | ... | @@ -144,7 +144,7 @@ export interface Node extends Ref, Disposable { |
| 144 | valueFormatter?: (value: number, total: number | null) => string; | 144 | valueFormatter?: (value: number, total: number | null) => string; |
| 145 | } | 145 | } |
| 146 | | 146 | |
| 147 | /** override the default field values of {@link Node} on creation. */ | 147 | /** override the default field values of {@linkcode Node} on creation. */ |
| 148 | export interface StartOptions { | 148 | export interface StartOptions { |
| 149 | /** number of items already completed. */ | 149 | /** number of items already completed. */ |
| 150 | value?: number | undefined | null; | 150 | value?: number | undefined | null; |
| ... | @@ -187,6 +187,11 @@ export interface StartOptions { | ... | @@ -187,6 +187,11 @@ export interface StartOptions { |
| 187 | messages?: log.Message[]; | 187 | messages?: log.Message[]; |
| 188 | } | 188 | } |
| 189 | | 189 | |
| | 190 | /** |
| | 191 | * value` will be at least zero, total will be `null` or greater than zero. a |
| | 192 | * custom value formatter can be passed to {@linkcode start} or mutated on an |
| | 193 | * existing node. |
| | 194 | */ |
| 190 | export type ValueFormatter = (value: number, total: number | null) => string; | 195 | export type ValueFormatter = (value: number, total: number | null) => string; |
| 191 | | 196 | |
| 192 | /** | 197 | /** |
| ... | @@ -285,7 +290,7 @@ export class Root< | ... | @@ -285,7 +290,7 @@ export class Root< |
| 285 | /** | 290 | /** |
| 286 | * end this root, as well as all children nodes. this emits the `end` event | 291 | * end this root, as well as all children nodes. this emits the `end` event |
| 287 | * with the provided value, JSON-serializing it if connected via | 292 | * with the provided value, JSON-serializing it if connected via |
| 288 | * `encodeEventStream` or `encodeByteStream`. | 293 | * {@linkcode encodeEventStream} or {@linkcode encodeByteStream}. |
| 289 | * | 294 | * |
| 290 | * this function is pre-bound so that it can be passed to `then`: | 295 | * this function is pre-bound so that it can be passed to `then`: |
| 291 | * ```ts | 296 | * ```ts |
| ... | @@ -311,7 +316,7 @@ export class Root< | ... | @@ -311,7 +316,7 @@ export class Root< |
| 311 | | 316 | |
| 312 | /** | 317 | /** |
| 313 | * emit an event on the specified channel. behavior is not defined when manually | 318 | * emit an event on the specified channel. behavior is not defined when manually |
| 314 | * emitting one of `progress`'s built in events. | 319 | * emitting one of the built in events. |
| 315 | */ | 320 | */ |
| 316 | override emit<C extends keyof MergeRootEvents<Result, Map>>( | 321 | override emit<C extends keyof MergeRootEvents<Result, Map>>( |
| 317 | channel: C, | 322 | channel: C, |
| ... | @@ -344,6 +349,7 @@ export class Root< | ... | @@ -344,6 +349,7 @@ export class Root< |
| 344 | }; | 349 | }; |
| 345 | } | 350 | } |
| 346 | | 351 | |
| | 352 | /** the built in events provided by {@linkcode Root} */ |
| 347 | export type RootEventMap<Result = void> = { | 353 | export type RootEventMap<Result = void> = { |
| 348 | // this event is the debounced "ready to re-render" event. do not emit. | 354 | // this event is the debounced "ready to re-render" event. do not emit. |
| 349 | "change": [rootNodes: readonly ReadOnlyNode[]]; | 355 | "change": [rootNodes: readonly ReadOnlyNode[]]; |
| ... | @@ -601,6 +607,7 @@ export const nullNode: Node = { | ... | @@ -601,6 +607,7 @@ export const nullNode: Node = { |
| 601 | log: noop, | 607 | log: noop, |
| 602 | debug: noop, | 608 | debug: noop, |
| 603 | writeMessage: noop, | 609 | writeMessage: noop, |
| | 610 | write: noop, |
| 604 | scoped() { | 611 | scoped() { |
| 605 | return this; | 612 | return this; |
| 606 | }, | 613 | }, |
| ... | @@ -628,7 +635,7 @@ function endNode<R, M extends Events.Map>(owner: Root<R, M>, state: Internal) { | ... | @@ -628,7 +635,7 @@ function endNode<R, M extends Events.Map>(owner: Root<R, M>, state: Internal) { |
| 628 | state.parent = null; | 635 | state.parent = null; |
| 629 | } | 636 | } |
| 630 | | 637 | |
| 631 | /** Convert the top level `ReadOnlyNode[]` into ANSI text. */ | 638 | /** Convert the top level {@linkcode ReadOnlyNode|ReadOnlyNode[]} into ANSI text. */ |
| 632 | export function formatAnsi(now: number, list: readonly ReadOnlyNode[]): string { | 639 | export function formatAnsi(now: number, list: readonly ReadOnlyNode[]): string { |
| 633 | let out = ""; | 640 | let out = ""; |
| 634 | for (const top of list) { | 641 | for (const top of list) { |
| ... | @@ -739,8 +746,9 @@ export function formatUnicodeBar(progress: number, width: number): string { | ... | @@ -739,8 +746,9 @@ export function formatUnicodeBar(progress: number, width: number): string { |
| 739 | } | 746 | } |
| 740 | | 747 | |
| 741 | /** | 748 | /** |
| 742 | * configure a `Root` to display its contents to a `log.HeadlessWidgetHost`. | 749 | * configure a {@linkcode Root} to display its contents to a |
| 743 | * this is used by the global progress instance to output to the terminal | 750 | * {@linkcode log.HeadlessWidgetHost}. this is used by the global progress |
| | 751 | * instance to output to the terminal. |
| 744 | * ```ts | 752 | * ```ts |
| 745 | * const globalProgress = new progress.Root(); | 753 | * const globalProgress = new progress.Root(); |
| 746 | * progress.attachToScreen(log); | 754 | * progress.attachToScreen(log); |
| ... | @@ -815,7 +823,7 @@ export type StreamEvent = Array< | ... | @@ -815,7 +823,7 @@ export type StreamEvent = Array< |
| 815 | number | StreamNode | StreamCustomEvent | StreamRootChildren | 823 | number | StreamNode | StreamCustomEvent | StreamRootChildren |
| 816 | >; | 824 | >; |
| 817 | const kNode = Symbol("underlyingNode"); | 825 | const kNode = Symbol("underlyingNode"); |
| 818 | /** see {@linkcode StreamEvent} @internal */ | 826 | /** @internal */ |
| 819 | export interface StreamNode { | 827 | export interface StreamNode { |
| 820 | k: EncodedKey; | 828 | k: EncodedKey; |
| 821 | /** text, overwrite */ | 829 | /** text, overwrite */ |
| ... | @@ -850,12 +858,18 @@ type StreamCustomEvent = [ | ... | @@ -850,12 +858,18 @@ type StreamCustomEvent = [ |
| 850 | ]; | 858 | ]; |
| 851 | type StreamRootChildren = number[]; | 859 | type StreamRootChildren = number[]; |
| 852 | | 860 | |
| | 861 | /** options for both {@linkcode encodeEventStream} and {@linkcode encodeByteStream} */ |
| 853 | export interface EncodeStreamOptions { | 862 | export interface EncodeStreamOptions { |
| 854 | /** | 863 | /** |
| 855 | * set the minimum time between packets. | 864 | * set the minimum time between packets. |
| 856 | * @default 1000 / 30 (30fps) | 865 | * @default 1000 / 30 (30fps) |
| 857 | */ | 866 | */ |
| 858 | throttleMs?: number; | 867 | throttleMs?: number; |
| | 868 | /** |
| | 869 | * `log.ts` is capable of capturing stack traces from all log calls. by |
| | 870 | * seeing this to true, those traces will be serialized. disabled by default |
| | 871 | * for privacy reasons. |
| | 872 | */ |
| 859 | serializeStackTraces?: boolean; | 873 | serializeStackTraces?: boolean; |
| 860 | } | 874 | } |
| 861 | | 875 | |
| ... | @@ -951,8 +965,8 @@ export function encodeEventStream< | ... | @@ -951,8 +965,8 @@ export function encodeEventStream< |
| 951 | } | 965 | } |
| 952 | | 966 | |
| 953 | /** | 967 | /** |
| 954 | * decodes a stream created by `encodeEventStream` into managed calls to | 968 | * decodes a stream created by {@linkcode encodeEventStream} into managed calls |
| 955 | * `target.start`. when cancelling, all the created nodes are destroyed. | 969 | * to `target.start`. when cancelling, all the managed nodes are destroyed. |
| 956 | */ | 970 | */ |
| 957 | export function decodeEventStream< | 971 | export function decodeEventStream< |
| 958 | Result = void, | 972 | Result = void, |
| ... | @@ -1475,8 +1489,8 @@ function writeStreamEvent( | ... | @@ -1475,8 +1489,8 @@ function writeStreamEvent( |
| 1475 | } | 1489 | } |
| 1476 | | 1490 | |
| 1477 | /** | 1491 | /** |
| 1478 | * decodes a stream created by `encodeByteStream` into managed calls to | 1492 | * decodes a stream created by {@linkcode encodeByteStream} into managed calls to |
| 1479 | * `target.start`. when cancelling, all the created nodes are destroyed. | 1493 | * `target.start`. when cancelling, all the managed nodes are destroyed. |
| 1480 | */ | 1494 | */ |
| 1481 | export function decodeByteStream< | 1495 | export function decodeByteStream< |
| 1482 | Result = void, | 1496 | Result = void, |
| ... | @@ -1726,7 +1740,8 @@ export class Ema implements EstimationAlgorithm { | ... | @@ -1726,7 +1740,8 @@ export class Ema implements EstimationAlgorithm { |
| 1726 | type EncodedKey = number & { brand: typeof kNode }; | 1740 | type EncodedKey = number & { brand: typeof kNode }; |
| 1727 | | 1741 | |
| 1728 | const globalKeyPool = new KeyPool<number>(); | 1742 | const globalKeyPool = new KeyPool<number>(); |
| 1729 | export const global: Ref = | 1743 | |
| | 1744 | const global: Ref = |
| 1730 | /** @__PURE__ */ ((root = new Root()) => (attachToScreen(root, log), root))(); | 1745 | /** @__PURE__ */ ((root = new Root()) => (attachToScreen(root, log), root))(); |
| 1731 | | 1746 | |
| 1732 | /** | 1747 | /** |