Compare commits

...
This repository has been archived on 2020-01-20. You can view files and clone it, but cannot push or open issues or pull requests.

1 Commits

Author SHA1 Message Date
Dave Eddy
5cff14f261 snakey 2015-08-26 02:43:41 -04:00
2 changed files with 32 additions and 1 deletions

View File

@ -6,6 +6,8 @@
var bigspinner = require('bigspinner');
var format = require('util').format;
var path = require('path');
var spawn = require('child_process').spawn;
var tabula = require('tabula');
var vasync = require('vasync');
@ -95,8 +97,10 @@ function do_create_instance(subcmd, opts, args, callback) {
return next();
}
var spinner;
var spinner, child, killed;
var died = 0;
if (!opts.quiet && process.stderr.isTTY) {
/*
spinner = bigspinner.createSpinner({
delay: 250,
stream: process.stderr,
@ -105,6 +109,27 @@ function do_create_instance(subcmd, opts, args, callback) {
hideCursor: true,
fontChar: '#'
});
*/
var game = path.join(__dirname, '../node_modules/.bin/snake-game');
function makechild() {
var _now = Date.now();
child = spawn(game, {stdio: 'inherit'});
child.on('close', function (code) {
child = null;
if (!killed) {
var delta = Date.now() - _now;
died++;
console.error('[snake] survived %s',
common.humanDurationFromMs(delta));
makechild();
} else {
var ESC = '\u001b';
var CSI = ESC + '[';
process.stdout.write(CSI + '?25h');
}
});
}
makechild();
}
cloudapi.waitForMachineStates({
@ -114,6 +139,11 @@ function do_create_instance(subcmd, opts, args, callback) {
if (spinner) {
spinner.destroy();
}
if (child) {
killed = true;
child.kill('SIGINT');
console.error('[snake] died %d times!', died);
}
if (err) {
return next(err);
}

View File

@ -18,6 +18,7 @@
"once": "1.3.2",
"restify-clients": "1.0.0",
"smartdc-auth": "git+ssh://git@github.com:joyent/node-smartdc-auth.git#9f21966",
"snake-game": "^0.1.0",
"tabula": "1.4.2",
"vasync": "1.6.3",
"verror": "1.6.0"