Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fix progressbar

  • Loading branch information...
commit 131d0874805388d4e9d09c110d0dcddad54e3fef 1 parent 2dd0e0e
Ivan Shumkov Shumkov authored

Showing 1 changed file with 14 additions and 12 deletions. Show diff stats Hide diff stats

  1. +14 12 cli.js
26 cli.js
@@ -1073,21 +1073,23 @@ cli.exec = function (cmd, callback, errback) {
1073 1073 */
1074 1074 var last_progress_call, progress_len = 74;
1075 1075 cli.progress = function (progress) {
1076   - if (progress < 0 || progress > 1) return;
  1076 + if (progress < 0 || progress > 1 || isNaN(progress)) return;
1077 1077 var now = (new Date()).getTime();
1078 1078 if (last_progress_call && (now - last_progress_call) < 100 && progress !== 1) {
1079 1079 return; //Throttle progress calls
1080 1080 }
1081 1081 last_progress_call = now;
1082   - var percent = function () {
1083   - if (progress === 1) return ' 100%\n';
1084   - var p = Math.floor(progress * 100) + '%';
1085   - if (progress < 0.1) p = ' ' + p;
1086   - return ' ' + p;
1087   - };
1088   - var len = Math.floor(progress_len * progress), str = '';
1089   - while (len--) str += '#';
1090   - cli.native.util.print(pad(str, progress_len) + percent() + '\r');
  1082 +
  1083 +
  1084 + var barLength = Math.floor(progress_len * progress),
  1085 + str = '';
  1086 + if (barLength == 0 && progress > 0) {
  1087 + barLength = 1;
  1088 + }
  1089 + for (var i = 1; i <= progress_len; i++) {
  1090 + str += i <= barLength ? '#' : ' ';
  1091 + }
  1092 + cli.native.util.print('[' + str + '] ' + Math.floor(progress * 100) + '%' + (progress === 1 ? '\n' : '\u000D'));
1091 1093 };
1092 1094
1093 1095 /**
@@ -1099,13 +1101,13 @@ cli.progress = function (progress) {
1099 1101 var spinnerInterval;
1100 1102 cli.spinner = function (prefix, end) {
1101 1103 if (end) {
1102   - cli.native.util.print('\r' + prefix);
  1104 + cli.native.util.print('\u000D' + prefix);
1103 1105 return clearInterval(spinnerInterval);
1104 1106 }
1105 1107 prefix = prefix + ' ' || '';
1106 1108 var spinner = ['-','\\','|','/'], i = 0, l = spinner.length;
1107 1109 spinnerInterval = setInterval(function () {
1108   - cli.native.util.print('\r' + prefix + spinner[i++]);
  1110 + cli.native.util.print('\u000D' + prefix + spinner[i++]);
1109 1111 if (i == l) i = 0;
1110 1112 }, 200);
1111 1113 };

0 comments on commit 131d087

Please sign in to comment.
Something went wrong with that request. Please try again.