/
AsciiBar.d.ts
192 lines (192 loc) · 5.93 KB
/
AsciiBar.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/// <reference types="node" />
export default class AsciiBar {
/**
* Format of the displayed progressbar
*/
formatString: string;
/**
* Number of steps to finish progress
*/
total: number;
/**
* Startdate to calculate elapsed time (in milliseconds)
*/
startDate: number;
/**
* Which timespan to use for timing calculation - If you are unsure allways use false here!
*/
lastUpdateForTiming: boolean;
/**
* Width of the progress bar (only the #bar part)
*/
width: number;
/**
* Symbol for the done progress in the #bar part
*/
doneSymbol: string;
/**
* Symbol for the undone progress in the #bar part
*/
undoneSymbol: string;
/**
* Wether to print to configured stream or not
*/
print: boolean;
/**
* A spinner object describing how the spinner looks like
* Change this for another spinner
*/
spinner: Spinner;
/**
* The message displayed at the #message placeholder
*/
message: string;
/**
* wether to call progressbar's stop() function automatically if the progress reaches 100%
*/
autoStop: boolean;
/**
* wether to hide the terminal's cursor while displaying the progress bar
*/
hideCursor: boolean;
private elapsed;
private lastUpdate;
private timeToFinish;
private overallTime;
private stream;
private spinnerTimeout;
private enableSpinner;
private currentSpinnerSymbol;
private current;
constructor(options?: string | ProgressbarOptions);
/**
* Creates the progressbar string with all configured settings
* @returns a string representating the progressbar
*/
renderLine(): string;
/**
* Render the progressbar and print it to output stream
*/
printLine(): void;
/**
* update the progress. This will trigger re-rendering the progressbar
* @param current the new absolute progress value
* @param message [optional] update the message displayed at the #message placeholder
*/
update(current: number, message?: string): this;
/**
* Updates the spinner if enabled
*/
private updateSpinner;
/**
* Formats a time span (given in milliseconds) to a easy human readable string
* @param millis timespan in milliseconds
*/
private formatTime;
/**
* Stop the progressbar
* This will stop the spinner and change it's symbol to a checkmark (if not disabled)
* Message will be changed to a string describing the elapsed time (if not disabled)
* This function will be triggered automatically if the progressbar reaches 100% (if not disabled)
* @param withInfo wether to auto-update the progressbar's spinner and message after stopping
*/
stop(withInfo?: boolean): void;
}
interface ProgressbarOptions {
/**
* Format of the displayed progressbar
* Use serveral of this placeholders:
* #bar #count #percent #overall #elapsed #ttf #message #spinner
* And combine with serveral of this formatters:
* ##default ##green ##blue ##red ##yellow ##bright ##dim
* @default '#percent #bar'
* @example '##bright##blue#spinner##default #percent #bar Elapsed: #elapsed Time to finish: #ttf #message'
*/
formatString?: string;
/**
* Number of steps to finish progress
* @default 100
*/
total?: number;
/**
* Startdate to calculate elapsed time (in milliseconds)
* Use this if the progress started before initialising the progressbar
* @default 'new Date().getTime()'
*/
startDate?: number;
/**
* Stream to print the progressbar
* @default process.stdout
*/
stream?: NodeJS.ReadWriteStream;
/**
* Width of the progress bar (only the #bar part)
* @default 20
*/
width?: number;
/**
* Symbol for the done progress in the #bar part
* @default '>'
*/
doneSymbol?: string;
/**
* Symbol for the undone progress in the #bar part
* @default '-'
*/
undoneSymbol?: string;
/**
* Wether to print to configured stream or not
* If set to false get the currently rendered statusbar with bar.renderLine()
* @default true
*/
print?: boolean;
/**
* Start value of progress
* @default 0
*/
start?: number;
/**
* Wether to enable the spinner update function or not.
* If enabled the statusbar will re-render automatically every few seconds to update the spinner symbol
* Make sure to include #spinner in formatString to use spinner symbol
* @default false
*/
enableSpinner?: boolean;
/**
* Which timespan to use for timing calculation - If you are unsure allways use false here!
* set to FALSE: Assume that each of the remaining steps will take as long as THE AVERAGE OF ALL the previous steps
* set to TRUE: Assume that eah of the remaining steps will take as long as THE LAST STEP took. WARNING: This implies, that every call of the ProgressBar.update() function increment the state with the same stepwidth.
* @default false using overall elapsed time for timing calculation
*/
lastUpdateForTiming?: boolean;
/**
* wether to call progressbar's stop() function automatically if the progress reaches 100%
* @default true
*/
autoStop?: boolean;
/**
* wether to hide the terminal's cursor while displaying the progress bar
* cursor will be re-enabled by the bar.stop() function
* @default false
*/
hideCursor?: boolean;
}
export declare let defaultSpinner: Spinner;
export declare let simpleSpinner: Spinner;
interface Spinner {
/**
* Number of milliseconds to update to the next spinner frame
*/
interval: number;
/**
* Array of the spinner "frames"
* A frame means one char
*/
frames: string[];
/**
* Used in runtime to store currently displayed frame
* @default 0
*/
currentFrame?: number;
}
export {};