no bigspinner by default: use '-ww' for a spinner, '-www' bigger, '-wwww' max

This commit is contained in:
Trent Mick 2015-09-23 00:19:42 -07:00
parent 289d9389a4
commit 818a6b0afe
3 changed files with 37 additions and 23 deletions

View File

@ -12,25 +12,40 @@
* *
* Usage: * Usage:
* var distractions = require('./distractions'); * var distractions = require('./distractions');
* var distraction = distractions.createDistraction(); * var distraction = distractions.createDistraction([num]);
* setTimeout(function () { * setTimeout(function () {
* distraction.destroy(); * distraction.destroy();
* }, 5000); * }, 5000);
*/ */
var assert = require('assert-plus');
var bigspinner = require('bigspinner'); var bigspinner = require('bigspinner');
function createDistraction() { function createDistraction(num) {
assert.optionalNumber(num, 'num');
var height, width;
if (num <= 2) {
height = Math.min(5, process.stdout.rows - 2);
width = Math.min(5*2, process.stdout.columns - 2);
} else if (num === 3) {
height = Math.min(10, process.stdout.rows - 2);
width = Math.min(10*2, process.stdout.columns - 2);
} else {
var BORDER = 10; var BORDER = 10;
height = Math.max(2, process.stdout.rows - 2 - BORDER);
width = Math.max(2, process.stdout.columns - 1 - BORDER);
}
return bigspinner.createSpinner({ return bigspinner.createSpinner({
delay: 50, delay: 50,
positions: 40, positions: 40,
stream: process.stderr, stream: process.stderr,
height: Math.max(2, process.stdout.rows - 2 - BORDER), height: height,
width: Math.max(2, process.stdout.columns - 1 - BORDER), width: width,
hideCursor: true, hideCursor: true,
fontChar: '\u2588' // '\x1b[7m \x1b[m' //fontChar: '\u2588' // '\x1b[7m \x1b[m'
fontChar: '#'
}); });
} }

View File

@ -125,9 +125,11 @@ function do_create_instance(subcmd, opts, args, callback) {
return next(); return next();
} }
// 1 'wait': no distraction.
// >1 'wait': distraction, pass in the N.
var distraction; var distraction;
if (!opts.quiet && process.stderr.isTTY) { if (process.stderr.isTTY && opts.wait.length > 1) {
distraction = distractions.createDistraction(); distraction = distractions.createDistraction(opts.wait.length);
} }
// Dry-run: fake wait for a few seconds. // Dry-run: fake wait for a few seconds.
@ -205,13 +207,9 @@ do_create_instance.options = [
}, },
{ {
names: ['wait', 'w'], names: ['wait', 'w'],
type: 'bool', type: 'arrayOfBool',
help: 'Wait for the creation to complete.' help: 'Wait for the creation to complete. Use multiple times for a ' +
}, 'spinner.'
{
names: ['quiet', 'q'],
type: 'bool',
help: 'No progress spinner while waiting.'
}, },
{ {
names: ['json', 'j'], names: ['json', 'j'],

View File

@ -72,8 +72,14 @@ function do_wait_instance(subcmd, opts, args, cb) {
idsToWaitFor.length, states.join(', ')); idsToWaitFor.length, states.join(', '));
} }
if (false && /* TODO: need BigSpinner.log first */ /*
!opts.quiet && process.stderr.isTTY) * TODO: need BigSpinner.log first.
* TODO: Also when adding a spinner, we need an equiv option to
* `triton create -wwww` to trigger the spinner (and size). By
* default: no spinner.
*/
if (false &&
process.stderr.isTTY)
{ {
distraction = distractions.createDistraction(); distraction = distractions.createDistraction();
} }
@ -122,11 +128,6 @@ do_wait_instance.options = [
type: 'bool', type: 'bool',
help: 'Show this help.' help: 'Show this help.'
}, },
{
names: ['quiet', 'q'],
type: 'bool',
help: 'No progress spinner while waiting.'
},
{ {
names: ['states', 's'], names: ['states', 's'],
type: 'arrayOfString', type: 'arrayOfString',