From 818a6b0afe6c2b2eac9c4304b811ba8a6ede5111 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Wed, 23 Sep 2015 00:19:42 -0700 Subject: [PATCH] no bigspinner by default: use '-ww' for a spinner, '-www' bigger, '-wwww' max --- lib/distractions.js | 27 +++++++++++++++++++++------ lib/do_create_instance.js | 16 +++++++--------- lib/do_wait_instance.js | 17 +++++++++-------- 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/lib/distractions.js b/lib/distractions.js index 768e4bc..6b65bd4 100644 --- a/lib/distractions.js +++ b/lib/distractions.js @@ -12,25 +12,40 @@ * * Usage: * var distractions = require('./distractions'); - * var distraction = distractions.createDistraction(); + * var distraction = distractions.createDistraction([num]); * setTimeout(function () { * distraction.destroy(); * }, 5000); */ +var assert = require('assert-plus'); var bigspinner = require('bigspinner'); -function createDistraction() { - var BORDER = 10; +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; + height = Math.max(2, process.stdout.rows - 2 - BORDER); + width = Math.max(2, process.stdout.columns - 1 - BORDER); + } return bigspinner.createSpinner({ delay: 50, positions: 40, stream: process.stderr, - height: Math.max(2, process.stdout.rows - 2 - BORDER), - width: Math.max(2, process.stdout.columns - 1 - BORDER), + height: height, + width: width, hideCursor: true, - fontChar: '\u2588' // '\x1b[7m \x1b[m' + //fontChar: '\u2588' // '\x1b[7m \x1b[m' + fontChar: '#' }); } diff --git a/lib/do_create_instance.js b/lib/do_create_instance.js index c65f968..5c0fa7f 100644 --- a/lib/do_create_instance.js +++ b/lib/do_create_instance.js @@ -125,9 +125,11 @@ function do_create_instance(subcmd, opts, args, callback) { return next(); } + // 1 'wait': no distraction. + // >1 'wait': distraction, pass in the N. var distraction; - if (!opts.quiet && process.stderr.isTTY) { - distraction = distractions.createDistraction(); + if (process.stderr.isTTY && opts.wait.length > 1) { + distraction = distractions.createDistraction(opts.wait.length); } // Dry-run: fake wait for a few seconds. @@ -205,13 +207,9 @@ do_create_instance.options = [ }, { names: ['wait', 'w'], - type: 'bool', - help: 'Wait for the creation to complete.' - }, - { - names: ['quiet', 'q'], - type: 'bool', - help: 'No progress spinner while waiting.' + type: 'arrayOfBool', + help: 'Wait for the creation to complete. Use multiple times for a ' + + 'spinner.' }, { names: ['json', 'j'], diff --git a/lib/do_wait_instance.js b/lib/do_wait_instance.js index 4226837..d4e53a6 100644 --- a/lib/do_wait_instance.js +++ b/lib/do_wait_instance.js @@ -72,8 +72,14 @@ function do_wait_instance(subcmd, opts, args, cb) { 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(); } @@ -122,17 +128,12 @@ do_wait_instance.options = [ type: 'bool', help: 'Show this help.' }, - { - names: ['quiet', 'q'], - type: 'bool', - help: 'No progress spinner while waiting.' - }, { names: ['states', 's'], type: 'arrayOfString', default: ['running', 'failed'], helpArg: 'STATES', - help: 'Instance states on which to wait. Default is "running,failed".' + help: 'Instance states on which to wait. Default is "running,failed". ' + 'Values can be comma-separated or multiple uses of the option.' } ];