forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
progress.d.ts
121 lines (100 loc) · 3.52 KB
/
progress.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Type definitions for node-progress v1.1.8
// Project: https://github.com/tj/node-progress
// Definitions by: Sebastian Lenz <https://github.com/sebastian-lenz>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../node/node.d.ts"/>
declare module "progress"
{
/**
* These are keys in the options object you can pass to the progress bar along with total as seen in the example above.
*/
interface ProgressBarOptions
{
/**
* Total number of ticks to complete.
*/
total:number;
/**
* The displayed width of the progress bar defaulting to total.
*/
width?:number;
/**
* The output stream defaulting to stderr.
*/
stream?:NodeJS.WritableStream;
/**
* Completion character defaulting to "=".
*/
complete?:string;
/**
* Incomplete character defaulting to "-".
*/
incomplete?:string;
/**
* Option to clear the bar on completion defaulting to false.
*/
clear?:boolean;
/**
* Optional function to call when the progress bar completes.
*/
callback?:Function;
}
/**
* Flexible ascii progress bar.
*/
class ProgressBar
{
/**
* Initialize a `ProgressBar` with the given `fmt` string and `options` or
* `total`.
*
* Options:
* - `total` total number of ticks to complete
* - `width` the displayed width of the progress bar defaulting to total
* - `stream` the output stream defaulting to stderr
* - `complete` completion character defaulting to "="
* - `incomplete` incomplete character defaulting to "-"
* - `renderThrottle` minimum time between updates in milliseconds defaulting to 16
* - `callback` optional function to call when the progress bar completes
* - `clear` will clear the progress bar upon termination
*
* Tokens:
* - `:bar` the progress bar itself
* - `:current` current tick number
* - `:total` total ticks
* - `:elapsed` time elapsed in seconds
* - `:percent` completion percentage
* - `:eta` eta in seconds
*/
constructor(format:string, total:number);
constructor(format:string, options:ProgressBarOptions);
/**
* "tick" the progress bar with optional `len` and optional `tokens`.
*/
tick(tokens?:any):void;
tick(count?:number, tokens?:any):void;
/**
* Method to render the progress bar with optional `tokens` to place in the
* progress bar's `fmt` field.
*/
render(tokens?:any):void;
/**
* "update" the progress bar to represent an exact percentage.
* The ratio (between 0 and 1) specified will be multiplied by `total` and
* floored, representing the closest available "tick." For example, if a
* progress bar has a length of 3 and `update(0.5)` is called, the progress
* will be set to 1.
*
* A ratio of 0.5 will attempt to set the progress to halfway.
*
* @param ratio The ratio (between 0 and 1 inclusive) to set the
* overall completion to.
*/
update(ratio:number, tokens?:any):void;
/**
* Terminates a progress bar.
*/
terminate():void;
}
export = ProgressBar;
}