feat: ✨ Created a mini nodeJS server with NewMan for testing without PostMan GUI.
This will mimic a run in a CD/CI environment or docker container.
This commit is contained in:
73
node_modules/cli-progress/lib/eta.js
generated
vendored
Normal file
73
node_modules/cli-progress/lib/eta.js
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
|
||||
// ETA calculation
|
||||
class ETA{
|
||||
|
||||
constructor(length, initTime, initValue){
|
||||
// size of eta buffer
|
||||
this.etaBufferLength = length || 100;
|
||||
|
||||
// eta buffer with initial values
|
||||
this.valueBuffer = [initValue];
|
||||
this.timeBuffer = [initTime];
|
||||
|
||||
// eta time value
|
||||
this.eta = '0';
|
||||
}
|
||||
|
||||
// add new values to calculation buffer
|
||||
update(time, value, total){
|
||||
this.valueBuffer.push(value);
|
||||
this.timeBuffer.push(time);
|
||||
|
||||
// trigger recalculation
|
||||
this.calculate(total-value);
|
||||
}
|
||||
|
||||
// fetch estimated time
|
||||
getTime(){
|
||||
return this.eta;
|
||||
}
|
||||
|
||||
// eta calculation - request number of remaining events
|
||||
calculate(remaining){
|
||||
// get number of samples in eta buffer
|
||||
const currentBufferSize = this.valueBuffer.length;
|
||||
const buffer = Math.min(this.etaBufferLength, currentBufferSize);
|
||||
|
||||
const v_diff = this.valueBuffer[currentBufferSize - 1] - this.valueBuffer[currentBufferSize - buffer];
|
||||
const t_diff = this.timeBuffer[currentBufferSize - 1] - this.timeBuffer[currentBufferSize - buffer];
|
||||
|
||||
// get progress per ms
|
||||
const vt_rate = v_diff/t_diff;
|
||||
|
||||
// strip past elements
|
||||
this.valueBuffer = this.valueBuffer.slice(-this.etaBufferLength);
|
||||
this.timeBuffer = this.timeBuffer.slice(-this.etaBufferLength);
|
||||
|
||||
// eq: vt_rate *x = total
|
||||
const eta = Math.ceil(remaining/vt_rate/1000);
|
||||
|
||||
// check values
|
||||
if (isNaN(eta)){
|
||||
this.eta = 'NULL';
|
||||
|
||||
// +/- Infinity --- NaN already handled
|
||||
}else if (!isFinite(eta)){
|
||||
this.eta = 'INF';
|
||||
|
||||
// > 10M s ? - set upper display limit ~115days (1e7/60/60/24)
|
||||
}else if (eta > 1e7){
|
||||
this.eta = 'INF';
|
||||
|
||||
// negative ?
|
||||
}else if (eta < 0){
|
||||
this.eta = 0;
|
||||
|
||||
}else{
|
||||
// assign
|
||||
this.eta = eta;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ETA;
|
11
node_modules/cli-progress/lib/format-bar.js
generated
vendored
Normal file
11
node_modules/cli-progress/lib/format-bar.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
// format bar
|
||||
module.exports = function formatBar(progress, options){
|
||||
// calculate barsize
|
||||
const completeSize = Math.round(progress*options.barsize);
|
||||
const incompleteSize = options.barsize-completeSize;
|
||||
|
||||
// generate bar string by stripping the pre-rendered strings
|
||||
return options.barCompleteString.substr(0, completeSize) +
|
||||
options.barGlue +
|
||||
options.barIncompleteString.substr(0, incompleteSize);
|
||||
}
|
34
node_modules/cli-progress/lib/format-time.js
generated
vendored
Normal file
34
node_modules/cli-progress/lib/format-time.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
// default time format
|
||||
|
||||
// format a number of seconds into hours and minutes as appropriate
|
||||
module.exports = function formatTime(t, options, roundToMultipleOf){
|
||||
function round(input) {
|
||||
if (roundToMultipleOf) {
|
||||
return roundToMultipleOf * Math.round(input / roundToMultipleOf);
|
||||
} else {
|
||||
return input
|
||||
}
|
||||
}
|
||||
|
||||
// leading zero padding
|
||||
function autopadding(v){
|
||||
return (options.autopaddingChar + v).slice(-2);
|
||||
}
|
||||
|
||||
// > 1h ?
|
||||
if (t > 3600) {
|
||||
return autopadding(Math.floor(t / 3600)) + 'h' + autopadding(round((t % 3600) / 60)) + 'm';
|
||||
|
||||
// > 60s ?
|
||||
} else if (t > 60) {
|
||||
return autopadding(Math.floor(t / 60)) + 'm' + autopadding(round((t % 60))) + 's';
|
||||
|
||||
// > 10s ?
|
||||
} else if (t > 10) {
|
||||
return autopadding(round(t)) + 's';
|
||||
|
||||
// default: don't apply round to multiple
|
||||
}else{
|
||||
return autopadding(t) + 's';
|
||||
}
|
||||
}
|
22
node_modules/cli-progress/lib/format-value.js
generated
vendored
Normal file
22
node_modules/cli-progress/lib/format-value.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
// default value format (apply autopadding)
|
||||
|
||||
// format valueset
|
||||
module.exports = function formatValue(v, options, type){
|
||||
// no autopadding ? passthrough
|
||||
if (options.autopadding !== true){
|
||||
return v;
|
||||
}
|
||||
|
||||
// padding
|
||||
function autopadding(value, length){
|
||||
return (options.autopaddingChar + value).slice(-length);
|
||||
}
|
||||
|
||||
switch (type){
|
||||
case 'percentage':
|
||||
return autopadding(v, 3);
|
||||
|
||||
default:
|
||||
return v;
|
||||
}
|
||||
}
|
80
node_modules/cli-progress/lib/formatter.js
generated
vendored
Normal file
80
node_modules/cli-progress/lib/formatter.js
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
const _stringWidth = require('string-width');
|
||||
const _defaultFormatValue = require('./format-value');
|
||||
const _defaultFormatBar = require('./format-bar');
|
||||
const _defaultFormatTime = require('./format-time');
|
||||
|
||||
// generic formatter
|
||||
module.exports = function defaultFormatter(options, params, payload){
|
||||
|
||||
// copy format string
|
||||
let s = options.format;
|
||||
|
||||
// custom time format set ?
|
||||
const formatTime = options.formatTime || _defaultFormatTime;
|
||||
|
||||
// custom value format set ?
|
||||
const formatValue = options.formatValue || _defaultFormatValue;
|
||||
|
||||
// custom bar format set ?
|
||||
const formatBar = options.formatBar || _defaultFormatBar;
|
||||
|
||||
// calculate progress in percent
|
||||
const percentage = Math.floor(params.progress*100) + '';
|
||||
|
||||
// bar stopped and stopTime set ?
|
||||
const stopTime = params.stopTime || Date.now();
|
||||
|
||||
// calculate elapsed time
|
||||
const elapsedTime = Math.round((stopTime - params.startTime)/1000);
|
||||
|
||||
// merges data from payload and calculated
|
||||
const context = Object.assign({}, payload, {
|
||||
bar: formatBar(params.progress, options),
|
||||
|
||||
percentage: formatValue(percentage, options, 'percentage'),
|
||||
total: formatValue(params.total, options, 'total'),
|
||||
value: formatValue(params.value, options, 'value'),
|
||||
|
||||
eta: formatValue(params.eta, options, 'eta'),
|
||||
eta_formatted: formatTime(params.eta, options, 5),
|
||||
|
||||
duration: formatValue(elapsedTime, options, 'duration'),
|
||||
duration_formatted: formatTime(elapsedTime, options, 1)
|
||||
});
|
||||
|
||||
// assign placeholder tokens
|
||||
s = s.replace(/\{(\w+)\}/g, function(match, key){
|
||||
// key exists within payload/context
|
||||
if (typeof context[key] !== 'undefined') {
|
||||
return context[key];
|
||||
}
|
||||
|
||||
// no changes to unknown values
|
||||
return match;
|
||||
});
|
||||
|
||||
// calculate available whitespace (2 characters margin of error)
|
||||
const fullMargin = Math.max(0, params.maxWidth - _stringWidth(s) -2);
|
||||
const halfMargin = Math.floor(fullMargin / 2);
|
||||
|
||||
// distribute available whitespace according to position
|
||||
switch (options.align) {
|
||||
|
||||
// fill start-of-line with whitespaces
|
||||
case 'right':
|
||||
s = (fullMargin > 0) ? ' '.repeat(fullMargin) + s : s;
|
||||
break;
|
||||
|
||||
// distribute whitespaces to left+right
|
||||
case 'center':
|
||||
s = (halfMargin > 0) ? ' '.repeat(halfMargin) + s : s;
|
||||
break;
|
||||
|
||||
// default: left align, no additional whitespaces
|
||||
case 'left':
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
212
node_modules/cli-progress/lib/generic-bar.js
generated
vendored
Normal file
212
node_modules/cli-progress/lib/generic-bar.js
generated
vendored
Normal file
@@ -0,0 +1,212 @@
|
||||
const _ETA = require('./eta');
|
||||
const _Terminal = require('./terminal');
|
||||
const _formatter = require('./formatter');
|
||||
const _EventEmitter = require('events');
|
||||
|
||||
// Progress-Bar constructor
|
||||
module.exports = class GenericBar extends _EventEmitter{
|
||||
|
||||
constructor(options){
|
||||
super();
|
||||
|
||||
// store options
|
||||
this.options = options;
|
||||
|
||||
// store terminal instance
|
||||
this.terminal = (this.options.terminal) ? this.options.terminal : new _Terminal(this.options.stream);
|
||||
|
||||
// the current bar value
|
||||
this.value = 0;
|
||||
|
||||
// the end value of the bar
|
||||
this.total = 100;
|
||||
|
||||
// last drawn string - only render on change!
|
||||
this.lastDrawnString = null;
|
||||
|
||||
// start time (used for eta calculation)
|
||||
this.startTime = null;
|
||||
|
||||
// stop time (used for duration calculation)
|
||||
this.stopTime = null;
|
||||
|
||||
// last update time
|
||||
this.lastRedraw = Date.now();
|
||||
|
||||
// default eta calculator (will be re-create on start)
|
||||
this.eta = new _ETA(this.options.etaBufferLength, 0, 0);
|
||||
|
||||
// payload data
|
||||
this.payload = {};
|
||||
|
||||
// progress bar active ?
|
||||
this.isActive = false;
|
||||
|
||||
// use default formatter or custom one ?
|
||||
this.formatter = (typeof this.options.format === 'function') ? this.options.format : _formatter;
|
||||
}
|
||||
|
||||
// internal render function
|
||||
render(){
|
||||
// calculate the normalized current progress
|
||||
let progress = (this.value/this.total);
|
||||
|
||||
// handle NaN Errors caused by total=0. Set to complete in this case
|
||||
if (isNaN(progress)){
|
||||
progress = (this.options && this.options.emptyOnZero) ? 0.0 : 1.0;
|
||||
}
|
||||
|
||||
// limiter
|
||||
progress = Math.min(Math.max(progress, 0.0), 1.0);
|
||||
|
||||
// formatter params
|
||||
const params = {
|
||||
progress: progress,
|
||||
eta: this.eta.getTime(),
|
||||
startTime: this.startTime,
|
||||
stopTime: this.stopTime,
|
||||
total: this.total,
|
||||
value: this.value,
|
||||
maxWidth: this.terminal.getWidth()
|
||||
};
|
||||
|
||||
// automatic eta update ? (long running processes)
|
||||
if (this.options.etaAsynchronousUpdate){
|
||||
this.updateETA();
|
||||
}
|
||||
|
||||
// format string
|
||||
const s = this.formatter(this.options, params, this.payload);
|
||||
|
||||
const forceRedraw = this.options.forceRedraw
|
||||
// force redraw in notty-mode!
|
||||
|| (this.options.noTTYOutput && !this.terminal.isTTY());
|
||||
|
||||
// string changed ? only trigger redraw on change!
|
||||
if (forceRedraw || this.lastDrawnString != s){
|
||||
// trigger event
|
||||
this.emit('redraw-pre');
|
||||
|
||||
// set cursor to start of line
|
||||
this.terminal.cursorTo(0, null);
|
||||
|
||||
// write output
|
||||
this.terminal.write(s);
|
||||
|
||||
// clear to the right from cursor
|
||||
this.terminal.clearRight();
|
||||
|
||||
// store string
|
||||
this.lastDrawnString = s;
|
||||
|
||||
// set last redraw time
|
||||
this.lastRedraw = Date.now();
|
||||
|
||||
// trigger event
|
||||
this.emit('redraw-post');
|
||||
}
|
||||
}
|
||||
|
||||
// start the progress bar
|
||||
start(total, startValue, payload){
|
||||
// set initial values
|
||||
this.value = startValue || 0;
|
||||
this.total = (typeof total !== 'undefined' && total >= 0) ? total : 100;
|
||||
|
||||
// store payload (optional)
|
||||
this.payload = payload || {};
|
||||
|
||||
// store start time for duration+eta calculation
|
||||
this.startTime = Date.now();
|
||||
|
||||
// reset string line buffer (redraw detection)
|
||||
this.lastDrawnString = '';
|
||||
|
||||
// initialize eta buffer
|
||||
this.eta = new _ETA(this.options.etaBufferLength, this.startTime, this.value);
|
||||
|
||||
// set flag
|
||||
this.isActive = true;
|
||||
|
||||
// start event
|
||||
this.emit('start', total, startValue);
|
||||
}
|
||||
|
||||
// stop the bar
|
||||
stop(){
|
||||
// set flag
|
||||
this.isActive = false;
|
||||
|
||||
// store stop timestamp to get total duration
|
||||
this.stopTime = new Date();
|
||||
|
||||
// stop event
|
||||
this.emit('stop', this.total, this.value);
|
||||
}
|
||||
|
||||
// update the bar value
|
||||
// update(value, payload)
|
||||
// update(payload)
|
||||
update(arg0, arg1 = {}){
|
||||
// value set ?
|
||||
// update(value, [payload]);
|
||||
if (typeof arg0 === 'number') {
|
||||
// update value
|
||||
this.value = arg0;
|
||||
|
||||
// add new value; recalculate eta
|
||||
this.eta.update(Date.now(), arg0, this.total);
|
||||
}
|
||||
|
||||
// extract payload
|
||||
// update(value, payload)
|
||||
// update(payload)
|
||||
const payloadData = ((typeof arg0 === 'object') ? arg0 : arg1) || {};
|
||||
|
||||
// update event (before stop() is called)
|
||||
this.emit('update', this.total, this.value);
|
||||
|
||||
// merge payload
|
||||
for (const key in payloadData){
|
||||
this.payload[key] = payloadData[key];
|
||||
}
|
||||
|
||||
// limit reached ? autostop set ?
|
||||
if (this.value >= this.getTotal() && this.options.stopOnComplete) {
|
||||
this.stop();
|
||||
}
|
||||
}
|
||||
|
||||
// update the bar value
|
||||
// increment(delta, payload)
|
||||
// increment(payload)
|
||||
increment(arg0 = 1, arg1 = {}){
|
||||
// increment([payload]) => step=1
|
||||
// handle the use case when `step` is omitted but payload is passed
|
||||
if (typeof arg0 === 'object') {
|
||||
this.update(this.value + 1, arg0);
|
||||
|
||||
// increment([step=1], [payload={}])
|
||||
}else{
|
||||
this.update(this.value + arg0, arg1);
|
||||
}
|
||||
}
|
||||
|
||||
// get the total (limit) value
|
||||
getTotal(){
|
||||
return this.total;
|
||||
}
|
||||
|
||||
// set the total (limit) value
|
||||
setTotal(total){
|
||||
if (typeof total !== 'undefined' && total >= 0){
|
||||
this.total = total;
|
||||
}
|
||||
}
|
||||
|
||||
// force eta calculation update (long running processes)
|
||||
updateETA(){
|
||||
// add new value; recalculate eta
|
||||
this.eta.update(Date.now(), this.value, this.total);
|
||||
}
|
||||
}
|
201
node_modules/cli-progress/lib/multi-bar.js
generated
vendored
Normal file
201
node_modules/cli-progress/lib/multi-bar.js
generated
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
const _Terminal = require('./terminal');
|
||||
const _BarElement = require('./generic-bar');
|
||||
const _options = require('./options');
|
||||
const _EventEmitter = require('events');
|
||||
|
||||
// Progress-Bar constructor
|
||||
module.exports = class MultiBar extends _EventEmitter{
|
||||
|
||||
constructor(options, preset){
|
||||
super();
|
||||
|
||||
// list of bars
|
||||
this.bars = [];
|
||||
|
||||
// parse+store options
|
||||
this.options = _options.parse(options, preset);
|
||||
|
||||
// disable synchronous updates
|
||||
this.options.synchronousUpdate = false;
|
||||
|
||||
// store terminal instance
|
||||
this.terminal = (this.options.terminal) ? this.options.terminal : new _Terminal(this.options.stream);
|
||||
|
||||
// the update timer
|
||||
this.timer = null;
|
||||
|
||||
// progress bar active ?
|
||||
this.isActive = false;
|
||||
|
||||
// update interval
|
||||
this.schedulingRate = (this.terminal.isTTY() ? this.options.throttleTime : this.options.notTTYSchedule);
|
||||
}
|
||||
|
||||
// add a new bar to the stack
|
||||
create(total, startValue, payload){
|
||||
// progress updates are only visible in TTY mode!
|
||||
if (this.options.noTTYOutput === false && this.terminal.isTTY() === false){
|
||||
return;
|
||||
}
|
||||
|
||||
// create new bar element
|
||||
const bar = new _BarElement(this.options);
|
||||
|
||||
// store bar
|
||||
this.bars.push(bar);
|
||||
|
||||
// multiprogress already active ?
|
||||
if (!this.isActive){
|
||||
// hide the cursor ?
|
||||
if (this.options.hideCursor === true){
|
||||
this.terminal.cursor(false);
|
||||
}
|
||||
|
||||
// disable line wrapping ?
|
||||
if (this.options.linewrap === false){
|
||||
this.terminal.lineWrapping(false);
|
||||
}
|
||||
|
||||
// initialize update timer
|
||||
this.timer = setTimeout(this.update.bind(this), this.schedulingRate);
|
||||
}
|
||||
|
||||
// set flag
|
||||
this.isActive = true;
|
||||
|
||||
// start progress bar
|
||||
bar.start(total, startValue, payload);
|
||||
|
||||
// trigger event
|
||||
this.emit('start');
|
||||
|
||||
// return new instance
|
||||
return bar;
|
||||
}
|
||||
|
||||
// remove a bar from the stack
|
||||
remove(bar){
|
||||
// find element
|
||||
const index = this.bars.indexOf(bar);
|
||||
|
||||
// element found ?
|
||||
if (index < 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
// remove element
|
||||
this.bars.splice(index, 1);
|
||||
|
||||
// force update
|
||||
this.update();
|
||||
|
||||
// clear bottom
|
||||
this.terminal.newline();
|
||||
this.terminal.clearBottom();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// internal update routine
|
||||
update(){
|
||||
// stop timer
|
||||
if (this.timer){
|
||||
clearTimeout(this.timer);
|
||||
this.timer = null;
|
||||
}
|
||||
|
||||
// trigger event
|
||||
this.emit('update-pre');
|
||||
|
||||
// reset cursor
|
||||
this.terminal.cursorRelativeReset();
|
||||
|
||||
// trigger event
|
||||
this.emit('redraw-pre');
|
||||
|
||||
// update each bar
|
||||
for (let i=0; i< this.bars.length; i++){
|
||||
// add new line ?
|
||||
if (i > 0){
|
||||
this.terminal.newline();
|
||||
}
|
||||
|
||||
// render
|
||||
this.bars[i].render();
|
||||
}
|
||||
|
||||
// trigger event
|
||||
this.emit('redraw-post');
|
||||
|
||||
// add new line in notty mode!
|
||||
if (this.options.noTTYOutput && this.terminal.isTTY() === false){
|
||||
this.terminal.newline();
|
||||
this.terminal.newline();
|
||||
}
|
||||
|
||||
// next update
|
||||
this.timer = setTimeout(this.update.bind(this), this.schedulingRate);
|
||||
|
||||
// trigger event
|
||||
this.emit('update-post');
|
||||
|
||||
// stop if stopOnComplete and all bars stopped
|
||||
if (this.options.stopOnComplete && !this.bars.find(bar => bar.isActive)) {
|
||||
this.stop();
|
||||
}
|
||||
}
|
||||
|
||||
stop(){
|
||||
|
||||
// stop timer
|
||||
clearTimeout(this.timer);
|
||||
this.timer = null;
|
||||
|
||||
// set flag
|
||||
this.isActive = false;
|
||||
|
||||
// cursor hidden ?
|
||||
if (this.options.hideCursor === true){
|
||||
this.terminal.cursor(true);
|
||||
}
|
||||
|
||||
// re-enable line wrpaping ?
|
||||
if (this.options.linewrap === false){
|
||||
this.terminal.lineWrapping(true);
|
||||
}
|
||||
|
||||
// reset cursor
|
||||
this.terminal.cursorRelativeReset();
|
||||
|
||||
// trigger event
|
||||
this.emit('stop-pre-clear');
|
||||
|
||||
// clear line on complete ?
|
||||
if (this.options.clearOnComplete){
|
||||
// clear all bars
|
||||
this.terminal.clearBottom();
|
||||
|
||||
// or show final progress ?
|
||||
}else{
|
||||
// update each bar
|
||||
for (let i=0; i< this.bars.length; i++){
|
||||
// add new line ?
|
||||
if (i > 0){
|
||||
this.terminal.newline();
|
||||
}
|
||||
|
||||
// trigger final rendering
|
||||
this.bars[i].render();
|
||||
|
||||
// stop
|
||||
this.bars[i].stop();
|
||||
}
|
||||
|
||||
// new line on complete
|
||||
this.terminal.newline();
|
||||
}
|
||||
|
||||
// trigger event
|
||||
this.emit('stop');
|
||||
}
|
||||
}
|
95
node_modules/cli-progress/lib/options.js
generated
vendored
Normal file
95
node_modules/cli-progress/lib/options.js
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
// utility to merge defaults
|
||||
function mergeOption(v, defaultValue){
|
||||
if (typeof v === 'undefined' || v === null){
|
||||
return defaultValue;
|
||||
}else{
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
// set global options
|
||||
parse: function parse(rawOptions, preset){
|
||||
|
||||
// options storage
|
||||
const options = {};
|
||||
|
||||
// merge preset
|
||||
const opt = Object.assign({}, preset, rawOptions);
|
||||
|
||||
// the max update rate in fps (redraw will only triggered on value change)
|
||||
options.throttleTime = 1000 / (mergeOption(opt.fps, 10));
|
||||
|
||||
// the output stream to write on
|
||||
options.stream = mergeOption(opt.stream, process.stderr);
|
||||
|
||||
// external terminal provided ?
|
||||
options.terminal = mergeOption(opt.terminal, null);
|
||||
|
||||
// clear on finish ?
|
||||
options.clearOnComplete = mergeOption(opt.clearOnComplete, false);
|
||||
|
||||
// stop on finish ?
|
||||
options.stopOnComplete = mergeOption(opt.stopOnComplete, false);
|
||||
|
||||
// size of the progressbar in chars
|
||||
options.barsize = mergeOption(opt.barsize, 40);
|
||||
|
||||
// position of the progress bar - 'left' (default), 'right' or 'center'
|
||||
options.align = mergeOption(opt.align, 'left');
|
||||
|
||||
// hide the cursor ?
|
||||
options.hideCursor = mergeOption(opt.hideCursor, false);
|
||||
|
||||
// disable linewrapping ?
|
||||
options.linewrap = mergeOption(opt.linewrap, false);
|
||||
|
||||
// pre-render bar strings (performance)
|
||||
options.barCompleteString = (new Array(options.barsize + 1 ).join(opt.barCompleteChar || '='));
|
||||
options.barIncompleteString = (new Array(options.barsize + 1 ).join(opt.barIncompleteChar || '-'));
|
||||
|
||||
// glue sequence (control chars) between bar elements ?
|
||||
options.barGlue = mergeOption(opt.barGlue, '');
|
||||
|
||||
// the bar format
|
||||
options.format = mergeOption(opt.format, 'progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}');
|
||||
|
||||
// external time-format provided ?
|
||||
options.formatTime = mergeOption(opt.formatTime, null);
|
||||
|
||||
// external value-format provided ?
|
||||
options.formatValue = mergeOption(opt.formatValue, null);
|
||||
|
||||
// external bar-format provided ?
|
||||
options.formatBar = mergeOption(opt.formatBar, null);
|
||||
|
||||
// the number of results to average ETA over
|
||||
options.etaBufferLength = mergeOption(opt.etaBuffer, 10);
|
||||
|
||||
// automatic eta updates based on fps
|
||||
options.etaAsynchronousUpdate = mergeOption(opt.etaAsynchronousUpdate, false);
|
||||
|
||||
// allow synchronous updates ?
|
||||
options.synchronousUpdate = mergeOption(opt.synchronousUpdate, true);
|
||||
|
||||
// notty mode
|
||||
options.noTTYOutput = mergeOption(opt.noTTYOutput, false);
|
||||
|
||||
// schedule - 2s
|
||||
options.notTTYSchedule = mergeOption(opt.notTTYSchedule, 2000);
|
||||
|
||||
// emptyOnZero - false
|
||||
options.emptyOnZero = mergeOption(opt.emptyOnZero, false);
|
||||
|
||||
// force bar redraw even if progress did not change
|
||||
options.forceRedraw = mergeOption(opt.forceRedraw, false);
|
||||
|
||||
// automated padding to fixed width ?
|
||||
options.autopadding = mergeOption(opt.autopadding, false);
|
||||
|
||||
// autopadding character - empty in case autopadding is disabled
|
||||
options.autopaddingChar = options.autopadding ? mergeOption(opt.autopaddingChar, ' ') : '';
|
||||
|
||||
return options;
|
||||
}
|
||||
};
|
124
node_modules/cli-progress/lib/single-bar.js
generated
vendored
Normal file
124
node_modules/cli-progress/lib/single-bar.js
generated
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
const _GenericBar = require('./generic-bar');
|
||||
const _options = require('./options');
|
||||
|
||||
// Progress-Bar constructor
|
||||
module.exports = class SingleBar extends _GenericBar{
|
||||
|
||||
constructor(options, preset){
|
||||
super(_options.parse(options, preset));
|
||||
|
||||
// the update timer
|
||||
this.timer = null;
|
||||
|
||||
// disable synchronous updates in notty mode
|
||||
if (this.options.noTTYOutput && this.terminal.isTTY() === false){
|
||||
this.options.synchronousUpdate = false;
|
||||
}
|
||||
|
||||
// update interval
|
||||
this.schedulingRate = (this.terminal.isTTY() ? this.options.throttleTime : this.options.notTTYSchedule);
|
||||
}
|
||||
|
||||
// internal render function
|
||||
render(){
|
||||
// stop timer
|
||||
if (this.timer){
|
||||
clearTimeout(this.timer);
|
||||
this.timer = null;
|
||||
}
|
||||
|
||||
// run internal rendering
|
||||
super.render();
|
||||
|
||||
// add new line in notty mode!
|
||||
if (this.options.noTTYOutput && this.terminal.isTTY() === false){
|
||||
this.terminal.newline();
|
||||
}
|
||||
|
||||
// next update
|
||||
this.timer = setTimeout(this.render.bind(this), this.schedulingRate);
|
||||
}
|
||||
|
||||
update(current, payload){
|
||||
// timer inactive ?
|
||||
if (!this.timer) {
|
||||
return;
|
||||
}
|
||||
|
||||
super.update(current, payload);
|
||||
|
||||
// trigger synchronous update ?
|
||||
// check for throttle time
|
||||
if (this.options.synchronousUpdate && (this.lastRedraw + this.options.throttleTime*2) < Date.now()){
|
||||
// force update
|
||||
this.render();
|
||||
}
|
||||
}
|
||||
|
||||
// start the progress bar
|
||||
start(total, startValue, payload){
|
||||
// progress updates are only visible in TTY mode!
|
||||
if (this.options.noTTYOutput === false && this.terminal.isTTY() === false){
|
||||
return;
|
||||
}
|
||||
|
||||
// save current cursor settings
|
||||
this.terminal.cursorSave();
|
||||
|
||||
// hide the cursor ?
|
||||
if (this.options.hideCursor === true){
|
||||
this.terminal.cursor(false);
|
||||
}
|
||||
|
||||
// disable line wrapping ?
|
||||
if (this.options.linewrap === false){
|
||||
this.terminal.lineWrapping(false);
|
||||
}
|
||||
|
||||
// initialize bar
|
||||
super.start(total, startValue, payload);
|
||||
|
||||
// redraw on start!
|
||||
this.render();
|
||||
}
|
||||
|
||||
// stop the bar
|
||||
stop(){
|
||||
// timer inactive ?
|
||||
if (!this.timer) {
|
||||
return;
|
||||
}
|
||||
|
||||
// trigger final rendering
|
||||
this.render();
|
||||
|
||||
// restore state
|
||||
super.stop();
|
||||
|
||||
// stop timer
|
||||
clearTimeout(this.timer);
|
||||
this.timer = null;
|
||||
|
||||
// cursor hidden ?
|
||||
if (this.options.hideCursor === true){
|
||||
this.terminal.cursor(true);
|
||||
}
|
||||
|
||||
// re-enable line wrapping ?
|
||||
if (this.options.linewrap === false){
|
||||
this.terminal.lineWrapping(true);
|
||||
}
|
||||
|
||||
// restore cursor on complete (position + settings)
|
||||
this.terminal.cursorRestore();
|
||||
|
||||
// clear line on complete ?
|
||||
if (this.options.clearOnComplete){
|
||||
this.terminal.cursorTo(0, null);
|
||||
this.terminal.clearLine();
|
||||
}else{
|
||||
// new line on complete
|
||||
this.terminal.newline();
|
||||
}
|
||||
}
|
||||
}
|
159
node_modules/cli-progress/lib/terminal.js
generated
vendored
Normal file
159
node_modules/cli-progress/lib/terminal.js
generated
vendored
Normal file
@@ -0,0 +1,159 @@
|
||||
const _readline = require('readline');
|
||||
|
||||
// low-level terminal interactions
|
||||
class Terminal{
|
||||
|
||||
constructor(outputStream){
|
||||
this.stream = outputStream;
|
||||
|
||||
// default: line wrapping enabled
|
||||
this.linewrap = true;
|
||||
|
||||
// current, relative y position
|
||||
this.dy = 0;
|
||||
}
|
||||
|
||||
// save cursor position + settings
|
||||
cursorSave(){
|
||||
if (!this.stream.isTTY){
|
||||
return;
|
||||
}
|
||||
|
||||
// save position
|
||||
this.stream.write('\x1B7');
|
||||
}
|
||||
|
||||
// restore last cursor position + settings
|
||||
cursorRestore(){
|
||||
if (!this.stream.isTTY){
|
||||
return;
|
||||
}
|
||||
|
||||
// restore cursor
|
||||
this.stream.write('\x1B8');
|
||||
}
|
||||
|
||||
// show/hide cursor
|
||||
cursor(enabled){
|
||||
if (!this.stream.isTTY){
|
||||
return;
|
||||
}
|
||||
|
||||
if (enabled){
|
||||
this.stream.write('\x1B[?25h');
|
||||
}else{
|
||||
this.stream.write('\x1B[?25l');
|
||||
}
|
||||
}
|
||||
|
||||
// change cursor positionn
|
||||
cursorTo(x=null, y=null){
|
||||
if (!this.stream.isTTY){
|
||||
return;
|
||||
}
|
||||
|
||||
// move cursor absolute
|
||||
_readline.cursorTo(this.stream, x, y);
|
||||
}
|
||||
|
||||
// change relative cursor position
|
||||
cursorRelative(dx=null, dy=null){
|
||||
if (!this.stream.isTTY){
|
||||
return;
|
||||
}
|
||||
|
||||
// store current position
|
||||
this.dy = this.dy + dy;
|
||||
|
||||
// move cursor relative
|
||||
_readline.moveCursor(this.stream, dx, dy);
|
||||
}
|
||||
|
||||
// relative reset
|
||||
cursorRelativeReset(){
|
||||
if (!this.stream.isTTY){
|
||||
return;
|
||||
}
|
||||
|
||||
// move cursor to initial line
|
||||
_readline.moveCursor(this.stream, 0, -this.dy);
|
||||
|
||||
// first char
|
||||
_readline.cursorTo(this.stream, 0, null);
|
||||
|
||||
// reset counter
|
||||
this.dy = 0;
|
||||
}
|
||||
|
||||
// clear to the right from cursor
|
||||
clearRight(){
|
||||
if (!this.stream.isTTY){
|
||||
return;
|
||||
}
|
||||
|
||||
_readline.clearLine(this.stream, 1);
|
||||
}
|
||||
|
||||
// clear the full line
|
||||
clearLine(){
|
||||
if (!this.stream.isTTY){
|
||||
return;
|
||||
}
|
||||
|
||||
_readline.clearLine(this.stream, 0);
|
||||
}
|
||||
|
||||
// clear everyting beyond the current line
|
||||
clearBottom(){
|
||||
if (!this.stream.isTTY){
|
||||
return;
|
||||
}
|
||||
|
||||
_readline.clearScreenDown(this.stream);
|
||||
}
|
||||
|
||||
// add new line; increment counter
|
||||
newline(){
|
||||
this.stream.write('\n');
|
||||
this.dy++;
|
||||
}
|
||||
|
||||
// write content to output stream
|
||||
// @TODO use string-width to strip length
|
||||
write(s){
|
||||
// line wrapping enabled ? trim output
|
||||
if (this.linewrap === true){
|
||||
this.stream.write(s.substr(0, this.getWidth()));
|
||||
}else{
|
||||
this.stream.write(s);
|
||||
}
|
||||
}
|
||||
|
||||
// control line wrapping
|
||||
lineWrapping(enabled){
|
||||
if (!this.stream.isTTY){
|
||||
return;
|
||||
}
|
||||
|
||||
// store state
|
||||
this.linewrap = enabled;
|
||||
if (enabled){
|
||||
this.stream.write('\x1B[?7h');
|
||||
}else{
|
||||
this.stream.write('\x1B[?7l');
|
||||
}
|
||||
}
|
||||
|
||||
// tty environment ?
|
||||
isTTY(){
|
||||
return (this.stream.isTTY === true);
|
||||
}
|
||||
|
||||
// get terminal width
|
||||
getWidth(){
|
||||
// set max width to 80 in tty-mode and 200 in notty-mode
|
||||
return this.stream.columns || (this.stream.isTTY ? 80 : 200);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Terminal;
|
Reference in New Issue
Block a user