diff --git a/.gitignore b/.gitignore index a8ac8ca..71f9497 100755 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,6 @@ node_modules* .tmp* intern_* dev.js -yarn-error.log \ No newline at end of file +yarn-error.log +.yarn +.pnp.* \ No newline at end of file diff --git a/README.md b/README.md index 7cc6768..2495ab7 100755 --- a/README.md +++ b/README.md @@ -205,7 +205,7 @@ const = new cliProgress.MultiBar(options:object [, preset:object]); Adds a new progress bar to the container and starts the bar. Returns regular `SingleBar` object which can be individually controlled. -Additional `barOptions` can be passed directly to the [generic-bar](lib/generic-bar.js) to override the global options for a single bar instance. This can be useful to change the appearance of a single bar object. But be patient: this should only be used to override formats - DON'T try to set other global options like the terminal, synchronous flags, etc.. +Additional `barOptions` can be passed directly to the [generic-bar](lib/generic-bar.js) to override the global options for a single bar instance. This can be useful to change the appearance of a single bar object. But be patient: this should only be used to override format\barChars - DON'T try to set other global options like the terminal, synchronous flags, etc.. ```js const = .create(totalValue:int, startValue:int [, payload:object = {} [, barOptions:object = {}]]); diff --git a/lib/generic-bar.js b/lib/generic-bar.js index 4fb6886..f11ace3 100755 --- a/lib/generic-bar.js +++ b/lib/generic-bar.js @@ -45,6 +45,14 @@ module.exports = class GenericBar extends _EventEmitter{ // progress bar active ? this.isActive = false; + // if barCompleteChar/barIncompleteChar was provided, re-cache it + if (options.barCompleteString[1] !== options.barCompleteChar) { + options.barCompleteString = options.barCompleteChar.repeat(options.barsize); + } + if (options.barIncompleteString[1] !== options.barIncompleteChar) { + options.barIncompleteString = options.barIncompleteChar.repeat(options.barsize); + } + // use default formatter or custom one ? this.formatter = (typeof this.options.format === 'function') ? this.options.format : _formatter; } diff --git a/lib/options.js b/lib/options.js index ce0a229..02adc8b 100644 --- a/lib/options.js +++ b/lib/options.js @@ -44,9 +44,12 @@ module.exports = { // disable linewrapping ? options.linewrap = mergeOption(opt.linewrap, false); + options.barCompleteChar = mergeOption(opt.barCompleteChar, '='); + options.barIncompleteChar = mergeOption(opt.barIncompleteChar, '-'); + // 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 || '-')); + options.barCompleteString = options.barCompleteChar.repeat(options.barsize); + options.barIncompleteString = options.barIncompleteChar.repeat(options.barsize); // glue sequence (control chars) between bar elements ? options.barGlue = mergeOption(opt.barGlue, ''); @@ -98,4 +101,4 @@ module.exports = { return options; } -}; \ No newline at end of file +};