UNPKG

3.17 kBJavaScriptView Raw
1export class Config {
2 /**
3 *
4 * @param {object} config
5 *
6 * @param {ReadStream} [config.input = process.stdin] the output stream to read from
7 * @param {WriteStream} [config.output = process.stdout] the output stream to write on
8 * @param {number} [config.fps = 12] the max update rate in fps (redraw will only triggered on value change)
9 * @param {IO|any} [config.terminal = null] external terminal provided ?
10 * @param {boolean} [config.autoClear = false] clear on finish ?
11 * @param {boolean} [config.autoStop = false] stop on finish ?
12 * @param {boolean} [config.hideCursor = false] hide the cursor ?
13 * @param {boolean} [config.lineWrap = false] allow or disable setLineWrap ?
14 * @param {string} [config.sentence = DEFAULT_FORMAT] the bar sentence
15 * @param {function} [config.formatTime = null] external time-sentence provided ?
16 * @param {function} [config.formatValue = null] external value-sentence provided ?
17 * @param {function} [config.formatBar = null] external bar-sentence provided ?
18 * @param {boolean} [config.syncUpdate = true] allow synchronous updates ?
19 * @param {boolean} [config.noTTYOutput = false] noTTY mode
20 * @param {number} [config.notTTYSchedule = 2000] schedule - 2s
21 * @param {boolean} [config.forceRedraw = false] force bar redraw even if progress did not change
22 *
23 * @param {object} [config.eta] eta config
24 * @param {boolean} [config.eta.on = false] switch to turn on eta
25 * @param {number} [config.eta.capacity = 10] the number of results to average ETA over
26 * @param {boolean} [config.eta.autoUpdate = false] automatic eta updates based on fps
27 * @returns {Config}
28 */
29 constructor(config) {
30 // merge layout
31 // the max update rate in fps (redraw will only triggered on value change)
32 this.throttle = 1000 / ( config.fps ?? 10 )
33
34 // the output stream to write on
35 this.output = config.output ?? process.stdout
36 this.input = config.input ?? process.stdin
37
38 this.eta = config.eta
39 ? {
40 capacity: config.eta?.capacity ?? 10, // the number of results to average ETA over
41 autoUpdate: config.eta?.autoUpdate ?? false, // automatic eta updates based on fps
42 }
43 : null
44
45 this.terminal = config.terminal ?? null // external terminal provided ?
46 this.autoClear = config.autoClear ?? false // clear on finish ?
47 this.autoStop = config.autoStop ?? false // stop on finish ?
48 this.hideCursor = config.hideCursor ?? true // hide the cursor ?
49 this.lineWrap = config.lineWrap ?? false // disable setLineWrap ?
50
51 this.syncUpdate = config.syncUpdate ?? true // allow synchronous updates ?
52 this.noTTYOutput = config.noTTYOutput ?? false // noTTY mode
53 this.notTTYSchedule = config.notTTYSchedule ?? 2000 // schedule - 2s
54 this.forceRedraw = config.forceRedraw ?? false // force bar redraw even if progress did not change
55 return this
56 }
57
58 static build(config) { return new Config(config) }
59}
\No newline at end of file