| 111 | |
| 112 | // internal update routine |
| 113 | update(){ |
| 114 | // stop timer |
| 115 | if (this.timer){ |
| 116 | clearTimeout(this.timer); |
| 117 | this.timer = null; |
| 118 | } |
| 119 | |
| 120 | // trigger event |
| 121 | this.emit('update-pre'); |
| 122 | |
| 123 | // reset cursor |
| 124 | this.terminal.cursorRelativeReset(); |
| 125 | |
| 126 | // trigger event |
| 127 | this.emit('redraw-pre'); |
| 128 | |
| 129 | // content within logging buffer ? |
| 130 | if (this.loggingBuffer.length > 0){ |
| 131 | this.terminal.clearLine(); |
| 132 | |
| 133 | // flush logging buffer and write content to terminal |
| 134 | while (this.loggingBuffer.length > 0){ |
| 135 | this.terminal.write(this.loggingBuffer.shift(), true); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | // update each bar |
| 140 | for (let i=0; i< this.bars.length; i++){ |
| 141 | // add new line ? |
| 142 | if (i > 0){ |
| 143 | this.terminal.newline(); |
| 144 | } |
| 145 | |
| 146 | // render |
| 147 | this.bars[i].render(); |
| 148 | } |
| 149 | |
| 150 | // trigger event |
| 151 | this.emit('redraw-post'); |
| 152 | |
| 153 | // add new line in notty mode! |
| 154 | if (this.options.noTTYOutput && this.terminal.isTTY() === false){ |
| 155 | this.terminal.newline(); |
| 156 | this.terminal.newline(); |
| 157 | } |
| 158 | |
| 159 | // next update |
| 160 | this.timer = setTimeout(this.update.bind(this), this.schedulingRate); |
| 161 | |
| 162 | // trigger event |
| 163 | this.emit('update-post'); |
| 164 | |
| 165 | // stop if stopOnComplete and all bars stopped |
| 166 | if (this.options.stopOnComplete && !this.bars.find(bar => bar.isActive)) { |
| 167 | this.stop(); |
| 168 | } |
| 169 | } |
| 170 | |