Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow individual styling in multiBar.create() #136

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -8,4 +8,6 @@ node_modules*
.tmp*
intern_*
dev.js
yarn-error.log
yarn-error.log
.yarn
.pnp.*
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -205,7 +205,7 @@ const <instance> = 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 <barInstance> = <instance>.create(totalValue:int, startValue:int [, payload:object = {} [, barOptions:object = {}]]);
Expand Down
8 changes: 8 additions & 0 deletions lib/generic-bar.js
Expand Up @@ -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;
}
Expand Down
9 changes: 6 additions & 3 deletions lib/options.js
Expand Up @@ -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, '');
Expand Down Expand Up @@ -98,4 +101,4 @@ module.exports = {

return options;
}
};
};