diff --git a/.gitignore b/.gitignore index 6ff2f90..d905c43 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules *.sock npm-debug.log yarn.lock +.idea \ No newline at end of file diff --git a/Readme.md b/Readme.md index 6d4271a..f0b24e6 100644 --- a/Readme.md +++ b/Readme.md @@ -40,6 +40,7 @@ These are keys in the options object you can pass to the progress bar along with - `renderThrottle` minimum time between updates in milliseconds defaulting to 16 - `clear` option to clear the bar on completion defaulting to false - `callback` optional function to call when the progress bar completes +- `isRtlOn` a boolean value that indicates if the bar's direction should progress from right to the left direction (default: `false`). ### Tokens diff --git a/lib/node-progress.js b/lib/node-progress.js index 8eb0740..5e0d2b8 100644 --- a/lib/node-progress.js +++ b/lib/node-progress.js @@ -59,7 +59,7 @@ function ProgressBar(fmt, options) { this.curr = options.curr || 0; this.total = options.total; this.width = options.width || this.total; - this.clear = options.clear + this.clear = options.clear; this.chars = { complete : options.complete || '=', incomplete : options.incomplete || '-', @@ -70,6 +70,7 @@ function ProgressBar(fmt, options) { this.callback = options.callback || function () {}; this.tokens = {}; this.lastDraw = ''; + this.isRtlOn = options.isRtlOn || false; } /** @@ -165,7 +166,9 @@ ProgressBar.prototype.render = function (tokens, force) { complete = complete.slice(0, -1) + this.chars.head; /* fill in the actual progress bar */ - str = str.replace(':bar', complete + incomplete); + var barDataLtr = complete + incomplete; + var barData = this.isRtlOn ? barDataLtr : [...barDataLtr].reverse().join(''); + str = str.replace(':bar', barData); /* replace the extra tokens */ if (this.tokens) for (var key in this.tokens) str = str.replace(':' + key, this.tokens[key]);