From 1f0c40e87b15ef0f78a8a60ff6c70840be8b092b Mon Sep 17 00:00:00 2001 From: Andi Dittrich Date: Sun, 9 Jan 2022 11:39:30 +0100 Subject: [PATCH] removed colors dependency #116 --- CHANGES.md | 6 ++++++ README.md | 6 ++++-- examples/README.md | 8 ++++++++ examples/example-align.js | 8 ++++---- examples/example-formatter.js | 2 +- examples/example-presets.js | 6 +++--- examples/example-visual.js | 12 ++++++------ package.json | 3 +-- presets/shades-grey.js | 3 +-- yarn.lock | 10 +++++----- 10 files changed, 39 insertions(+), 25 deletions(-) create mode 100644 examples/README.md diff --git a/CHANGES.md b/CHANGES.md index 00812d3..02679a0 100755 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,11 @@ ## Branch 3.x ## +### 3.10.0 ### + +* Changed: foreground color of `preset.shades-grey` is set directly by ANSI codes +* Changed: example snippets are using `ansi-colors` library +* Bugfix: removed `colors` dependency due to some issues with the maintainer... see [Zalgo bomb](https://github.com/Marak/colors.js/issues/285#issuecomment-1008212640) + ### 3.9.1 ### * Bugfix: duration calculation doesn't work for bar restart scenarios - thanks to [autlaw on GitHub](https://github.com/npkgz/cli-progress/pull/101) diff --git a/README.md b/README.md index 169b8ca..ce247d2 100755 --- a/README.md +++ b/README.md @@ -65,7 +65,9 @@ Single Bar Mode ```js const cliProgress = require('cli-progress'); -const colors = require('colors'); + +// note: you have to install this dependency manually since it's not required by cli-progress +const colors = require('ansi-colors'); // create new progress bar const b1 = new cliProgress.SingleBar({ @@ -394,7 +396,7 @@ bar.stop(); **File** `myPreset.js` ```js -const colors = require('colors'); +const colors = require('ansi-colors'); module.exports = { format: colors.red(' {bar}') + ' {percentage}% | ETA: {eta}s | {value}/{total} | Speed: {speed} kbit', diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..74eb3d2 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,8 @@ +cli-progress examples +================================= + +Note: some of the examples are using the `ansi-colors` library for styling - since this lib is not required for `cli-progress` itself you have to install it manually! + +```bash +yarn install ansi-colors +``` \ No newline at end of file diff --git a/examples/example-align.js b/examples/example-align.js index 1409647..ce04bfe 100755 --- a/examples/example-align.js +++ b/examples/example-align.js @@ -1,13 +1,13 @@ -var _progress = require('../cli-progress'); -var _colors = require('colors'); +const _progress = require('../cli-progress'); +const _colors = require('ansi-colors'); // helper function to display preset function showPreset(name, pos){ console.log(_colors.magenta('Preset: ' + name)); // create a new progress bar with preset - var bar = new _progress.Bar({ - align: pos + const bar = new _progress.Bar({ + align: pos }, _progress.Presets[name] || _progress.Presets.legacy); bar.start(200, 0); diff --git a/examples/example-formatter.js b/examples/example-formatter.js index 8676510..da33759 100755 --- a/examples/example-formatter.js +++ b/examples/example-formatter.js @@ -1,5 +1,5 @@ const _progress = require('../cli-progress'); -const _colors = require('colors'); +const _colors = require('ansi-colors'); function myFormatter(options, params, payload){ diff --git a/examples/example-presets.js b/examples/example-presets.js index c50bc46..611d36d 100755 --- a/examples/example-presets.js +++ b/examples/example-presets.js @@ -1,12 +1,12 @@ -var _progress = require('../cli-progress'); -var _colors = require('colors'); +const _progress = require('../cli-progress'); +const _colors = require('ansi-colors'); // helper function to display preset function showPreset(name){ console.log(_colors.magenta('Preset: ' + name)); // create a new progress bar with preset - var bar = new _progress.Bar({}, _progress.Presets[name] || _progress.Presets.legacy); + const bar = new _progress.Bar({}, _progress.Presets[name] || _progress.Presets.legacy); bar.start(200, 0); // random value 1..200 diff --git a/examples/example-visual.js b/examples/example-visual.js index c93e827..6f9891a 100755 --- a/examples/example-visual.js +++ b/examples/example-visual.js @@ -1,10 +1,10 @@ const _progress = require('../cli-progress'); -const _colors = require('colors'); +const _colors = require('ansi-colors'); function Example5(){ console.log(''); // create new progress bar - var b1 = new _progress.Bar({ + const b1 = new _progress.Bar({ format: 'CLI Progress |' + _colors.cyan('{bar}') + '| {percentage}% || {value}/{total} Chunks || Speed: {speed}', barCompleteChar: '\u2588', barIncompleteChar: '\u2591', @@ -17,18 +17,18 @@ function Example5(){ }); // the bar value - will be linear incremented - var value = 0; + let value = 0; - var speedData = []; + const speedData = []; // 20ms update rate - var timer = setInterval(function(){ + const timer = setInterval(function(){ // increment value value++; // example speed data speedData.push(Math.random()*2+5); - var currentSpeedData = speedData.splice(-10); + const currentSpeedData = speedData.splice(-10); // update the bar value b1.update(value, { diff --git a/package.json b/package.json index a88a326..a9222c4 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cli-progress", - "version": "3.9.1", + "version": "3.10.0", "description": "easy to use progress-bar for command-line/terminal applications", "keywords": [ "cli", @@ -35,7 +35,6 @@ "author": "Andi Dittrich (https://andidittrich.com)", "license": "MIT", "dependencies": { - "colors": "^1.1.2", "string-width": "^4.2.0" }, "devDependencies": { diff --git a/presets/shades-grey.js b/presets/shades-grey.js index f3ebb6f..cd618ab 100755 --- a/presets/shades-grey.js +++ b/presets/shades-grey.js @@ -1,8 +1,7 @@ -const _colors = require('colors'); // cli-progress legacy style as of 1.x module.exports = { - format: _colors.grey(' {bar}') + ' {percentage}% | ETA: {eta}s | {value}/{total}', + format: ' \u001b[90m{bar}\u001b[0m {percentage}% | ETA: {eta}s | {value}/{total}', barCompleteChar: '\u2588', barIncompleteChar: '\u2591' }; \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index e77dac5..70d3977 100644 --- a/yarn.lock +++ b/yarn.lock @@ -48,6 +48,11 @@ ansi-colors@3.2.3: resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-3.2.3.tgz#57d35b8686e851e2cc04c403f1c00203976a1813" integrity sha512-LEHHyuhlPY3TmuUYMh2oz89lTShfvgbmzaBcxve9t/9Wuy7Dwf4yoAKcND7KFT1HAQfqZ12qtc+DUrBMeKF9nw== +ansi-colors@^4.1.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348" + integrity sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA== + ansi-escapes@^4.2.1: version "4.3.2" resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-4.3.2.tgz#6b2291d1db7d98b6521d5f1efa42d0f3a9feb65e" @@ -234,11 +239,6 @@ color-name@~1.1.4: resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== -colors@^1.1.2: - version "1.4.0" - resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78" - integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA== - concat-map@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"