Skip to content

Commit

Permalink
fixed #135 - terminal instance is used for all bars
Browse files Browse the repository at this point in the history
  • Loading branch information
AndiDittrich committed Feb 19, 2023
1 parent 6c75740 commit 84cf30a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###

Expand Down
18 changes: 16 additions & 2 deletions lib/multi-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions lib/terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 84cf30a

Please sign in to comment.