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