UNPKG

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