Permalink
Browse files

Added optional decimal parameter to progress

  • Loading branch information...
1 parent d103af2 commit 8db80126f36e44a1fa98af724c58afcd4ac7f32c @mex mex committed Jul 26, 2013
Showing with 8 additions and 2 deletions.
  1. +8 −2 cli.js
View
10 cli.js
@@ -1086,8 +1086,9 @@ cli.exec = function (cmd, callback, errback) {
* @api public
*/
var last_progress_call, progress_len = 74;
-cli.progress = function (progress) {
+cli.progress = function (progress, decimals) {
if (progress < 0 || progress > 1 || isNaN(progress)) return;
+ if (!decimals) decimals = 0;
var now = (new Date()).getTime();
if (last_progress_call && (now - last_progress_call) < 100 && progress !== 1) {
return; //Throttle progress calls
@@ -1103,7 +1104,12 @@ cli.progress = function (progress) {
for (var i = 1; i <= progress_len; i++) {
str += i <= barLength ? '#' : ' ';
}
- cli.native.util.print('[' + str + '] ' + Math.floor(progress * 100) + '%' + (progress === 1 ? '\n' : '\u000D'));
+ var pwr = Math.pow(10, decimals);
+ var percentage = Math.floor(progress * 100 * pwr) / pwr + '%';
+ for (i = 0; i < decimals; i++) {
+ percentage += ' ';
+ }
+ cli.native.util.print('[' + str + '] ' + percentage + (progress === 1 ? '\n' : '\u000D'));
};
/**

0 comments on commit 8db8012

Please sign in to comment.