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