1 | /// <reference types="node"/>
|
2 |
|
3 | export as namespace ProgressBar;
|
4 |
|
5 | export = ProgressBar;
|
6 |
|
7 | /**
|
8 | * Flexible ascii progress bar.
|
9 | */
|
10 | declare class ProgressBar {
|
11 | /**
|
12 | * Initialize a `ProgressBar` with the given `fmt` string and `options` or
|
13 | * `total`.
|
14 | *
|
15 | * Options:
|
16 | * - `total` total number of ticks to complete
|
17 | * - `width` the displayed width of the progress bar defaulting to total
|
18 | * - `stream` the output stream defaulting to stderr
|
19 | * - `complete` completion character defaulting to "="
|
20 | * - `incomplete` incomplete character defaulting to "-"
|
21 | * - `renderThrottle` minimum time between updates in milliseconds defaulting to 16
|
22 | * - `callback` optional function to call when the progress bar completes
|
23 | * - `clear` will clear the progress bar upon termination
|
24 | *
|
25 | * Tokens:
|
26 | * - `:bar` the progress bar itself
|
27 | * - `:current` current tick number
|
28 | * - `:total` total ticks
|
29 | * - `:elapsed` time elapsed in seconds
|
30 | * - `:percent` completion percentage
|
31 | * - `:eta` eta in seconds
|
32 | */
|
33 | constructor(format: string, total: number);
|
34 | constructor(format: string, options: ProgressBar.ProgressBarOptions);
|
35 |
|
36 | /**
|
37 | * "tick" the progress bar with optional `len` and optional `tokens`.
|
38 | */
|
39 | tick(tokens?: any): void;
|
40 | tick(count?: number, tokens?: any): void;
|
41 |
|
42 | /**
|
43 | * Method to render the progress bar with optional `tokens` to place in the
|
44 | * progress bar's `fmt` field.
|
45 | */
|
46 | render(tokens?: any, force?: boolean): void;
|
47 |
|
48 | /**
|
49 | * "update" the progress bar to represent an exact percentage.
|
50 | * The ratio (between 0 and 1) specified will be multiplied by `total` and
|
51 | * floored, representing the closest available "tick." For example, if a
|
52 | * progress bar has a length of 3 and `update(0.5)` is called, the progress
|
53 | * will be set to 1.
|
54 | *
|
55 | * A ratio of 0.5 will attempt to set the progress to halfway.
|
56 | *
|
57 | * @param ratio The ratio (between 0 and 1 inclusive) to set the
|
58 | * overall completion to.
|
59 | */
|
60 | update(ratio: number, tokens?: any): void;
|
61 |
|
62 | /**
|
63 | * "interrupt" the progress bar and write a message above it.
|
64 | */
|
65 | interrupt(message: string): void;
|
66 |
|
67 | /**
|
68 | * Terminates a progress bar.
|
69 | */
|
70 | terminate(): void;
|
71 |
|
72 | /**
|
73 | * Completed status of progress (Boolean)
|
74 | */
|
75 | complete: boolean;
|
76 |
|
77 | /**
|
78 | * Current tick number.
|
79 | */
|
80 | curr: number;
|
81 |
|
82 | /**
|
83 | * Total number of ticks to complete.
|
84 | */
|
85 | total: number;
|
86 | }
|
87 |
|
88 | declare namespace ProgressBar {
|
89 | /**
|
90 | * These are keys in the options object you can pass to the progress bar along with total as seen in the example above.
|
91 | */
|
92 | interface ProgressBarOptions {
|
93 | /**
|
94 | * Total number of ticks to complete.
|
95 | */
|
96 | total: number;
|
97 |
|
98 | /**
|
99 | * current completed index
|
100 | */
|
101 | curr?: number | undefined;
|
102 |
|
103 | /**
|
104 | * head character defaulting to complete character
|
105 | */
|
106 | head?: string | undefined;
|
107 |
|
108 | /**
|
109 | * The displayed width of the progress bar defaulting to total.
|
110 | */
|
111 | width?: number | undefined;
|
112 |
|
113 | /**
|
114 | * minimum time between updates in milliseconds defaulting to 16
|
115 | */
|
116 | renderThrottle?: number | undefined;
|
117 |
|
118 | /**
|
119 | * The output stream defaulting to stderr.
|
120 | */
|
121 | stream?: NodeJS.WritableStream | undefined;
|
122 |
|
123 | /**
|
124 | * Completion character defaulting to "=".
|
125 | */
|
126 | complete?: string | undefined;
|
127 |
|
128 | /**
|
129 | * Incomplete character defaulting to "-".
|
130 | */
|
131 | incomplete?: string | undefined;
|
132 |
|
133 | /**
|
134 | * Option to clear the bar on completion defaulting to false.
|
135 | */
|
136 | clear?: boolean | undefined;
|
137 |
|
138 | /**
|
139 | * Optional function to call when the progress bar completes.
|
140 | */
|
141 | callback?: Function | undefined;
|
142 | }
|
143 | }
|