cli-progress
Advanced tools
Comparing version 3.4.0 to 3.5.0
## Branch 3.x ## | ||
### 3.5.0 ### | ||
* Added: support for events via [EventEmitter](https://nodejs.org/api/events.html) - feature [requested on GitHub](https://github.com/AndiDittrich/Node.CLI-Progress/pull/58) | ||
### 3.4.0 ### | ||
@@ -4,0 +8,0 @@ |
const _ETA = require('./eta'); | ||
const _Terminal = require('./terminal'); | ||
const _formatter = require('./formatter'); | ||
const _EventEmitter = require('events'); | ||
// Progress-Bar constructor | ||
module.exports = class GenericBar{ | ||
module.exports = class GenericBar extends _EventEmitter{ | ||
constructor(options){ | ||
super(); | ||
@@ -76,2 +78,5 @@ // store options | ||
if (forceRedraw || this.lastDrawnString != s){ | ||
// trigger event | ||
this.emit('redraw-pre'); | ||
// set cursor to start of line | ||
@@ -91,2 +96,5 @@ this.terminal.cursorTo(0, null); | ||
this.lastRedraw = Date.now(); | ||
// trigger event | ||
this.emit('redraw-post'); | ||
} | ||
@@ -110,2 +118,5 @@ } | ||
this.isActive = true; | ||
// start event | ||
this.emit('start', total, startValue); | ||
} | ||
@@ -117,2 +128,5 @@ | ||
this.isActive = false; | ||
// stop event | ||
this.emit('stop', this.total, this.value); | ||
} | ||
@@ -130,2 +144,5 @@ | ||
// update event (before stop() is called) | ||
this.emit('update', this.total, this.value); | ||
// merge payload | ||
@@ -132,0 +149,0 @@ const payloadData = payload || {}; |
const _Terminal = require('./terminal'); | ||
const _BarElement = require('./generic-bar'); | ||
const _options = require('./options'); | ||
const _EventEmitter = require('events'); | ||
// Progress-Bar constructor | ||
module.exports = class MultiBar{ | ||
module.exports = class MultiBar extends _EventEmitter{ | ||
constructor(options, preset){ | ||
super(); | ||
// list of bars | ||
@@ -66,2 +69,5 @@ this.bars = []; | ||
// trigger event | ||
this.emit('start'); | ||
// return new instance | ||
@@ -101,2 +107,5 @@ return bar; | ||
} | ||
// trigger event | ||
this.emit('update-pre'); | ||
@@ -106,2 +115,5 @@ // reset cursor | ||
// trigger event | ||
this.emit('redraw-pre'); | ||
// update each bar | ||
@@ -118,2 +130,5 @@ for (let i=0; i< this.bars.length; i++){ | ||
// trigger event | ||
this.emit('redraw-post'); | ||
// add new line in notty mode! | ||
@@ -128,2 +143,5 @@ if (this.options.noTTYOutput && this.terminal.isTTY() === false){ | ||
// trigger event | ||
this.emit('update-post'); | ||
// stop if stopOnComplete and all bars stopped | ||
@@ -157,2 +175,5 @@ if (this.options.stopOnComplete && !this.bars.find(bar => bar.isActive)) { | ||
// trigger event | ||
this.emit('stop-pre-clear'); | ||
// clear line on complete ? | ||
@@ -182,3 +203,6 @@ if (this.options.clearOnComplete){ | ||
} | ||
// trigger event | ||
this.emit('stop'); | ||
} | ||
} |
The MIT License (X11 License) | ||
Copyright (c) 2015-2019 Andi Dittrich | ||
Copyright (c) 2015-2020 Andi Dittrich | ||
@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person |
{ | ||
"name": "cli-progress", | ||
"version": "3.4.0", | ||
"version": "3.5.0", | ||
"description": "easy to use progress-bar for command-line/terminal applications", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
[![Build Status](https://travis-ci.org/AndiDittrich/Node.CLI-Progress.svg?branch=master)](https://travis-ci.org/AndiDittrich/Node.CLI-Progress) | ||
[Single Bar](#single-bar-mode) | [Multi Bar](#multi-bar-mode) | [Options](#options-1) | [Examples](examples/) | [Presets](presets/) | [Events](docs/events.md) | ||
CLI-Progress | ||
@@ -227,2 +229,9 @@ ============ | ||
Events | ||
----------------------------------- | ||
The classes extends [EventEmitter](https://nodejs.org/api/events.html) which allows you to hook into different events. | ||
See [event docs](docs/events.md) for detailed informations + examples. | ||
Bar Formatting | ||
@@ -229,0 +238,0 @@ ----------------------------------- |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46704
727
405