From 84cf30a37ba99882dd5a94120b1d3ba605ffe9dc Mon Sep 17 00:00:00 2001 From: Andi Dittrich Date: Sun, 19 Feb 2023 12:19:43 +0100 Subject: [PATCH] fixed #135 - terminal instance is used for all bars --- CHANGES.md | 3 ++- lib/multi-bar.js | 18 ++++++++++++++++-- lib/terminal.js | 3 +++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 6a36a28..bda0b88 100755 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,8 +2,9 @@ ### 3.12.0 ### -* Added: option to override bar characters via instance options on `multibar.create()` - thanks to [ Araxeus on GitHub](https://github.com/npkgz/cli-progress/pull/136) +* Added: option to override bar characters via instance options on `multibar.create()` - thanks to [Araxeus on GitHub](https://github.com/npkgz/cli-progress/pull/136) * Added: example howto use multibars with different bar styles +* Bugfix: global terminal instance was not used for multibar elements which forces hard string trimming to terminal width - caused by default `linewrap=true` state of the terminal - thanks to [emmercm on GitHub](https://github.com/npkgz/cli-progress/issues/135) ### 3.11.2 ### diff --git a/lib/multi-bar.js b/lib/multi-bar.js index 957a5fa..d40ccfc 100644 --- a/lib/multi-bar.js +++ b/lib/multi-bar.js @@ -39,8 +39,22 @@ module.exports = class MultiBar extends _EventEmitter{ // add a new bar to the stack create(total, startValue, payload, barOptions={}){ - // create new bar element - const bar = new _BarElement(Object.assign({}, this.options, barOptions)); + // create new bar element and merge global options + overrides + // use the same global terminal instance for all instances + const bar = new _BarElement(Object.assign( + {}, + + // global options + this.options, + + // terminal instance + { + terminal: this.terminal + }, + + // overrides + barOptions, + )); // store bar this.bars.push(bar); diff --git a/lib/terminal.js b/lib/terminal.js index cbf6451..7445563 100644 --- a/lib/terminal.js +++ b/lib/terminal.js @@ -122,8 +122,11 @@ class Terminal{ // @TODO use string-width to strip length write(s, rawWrite=false){ // line wrapping enabled ? trim output + // this is just a fallback mechanism in case user enabled line-wrapping via options or set it to auto if (this.linewrap === true && rawWrite === false){ this.stream.write(s.substr(0, this.getWidth())); + + // standard behaviour with disabled linewrapping }else{ this.stream.write(s); }