PCjs CLI now repeats previous commands (just press Enter again)

This commit is contained in:
Jeff Parsons 2015-04-05 12:13:14 -07:00 committed by jeffpar
commit a0cd3578d9

View file

@ -44,6 +44,7 @@ var fConsole = false;
var fDebug = false; var fDebug = false;
var args = proc.getArgs(); var args = proc.getArgs();
var argv = args.argv; var argv = args.argv;
var sCmdPrev = null;
if (argv['console'] !== undefined) fConsole = argv['console']; if (argv['console'] !== undefined) fConsole = argv['console'];
if (argv['debug'] !== undefined) fDebug = argv['debug']; if (argv['debug'] !== undefined) fDebug = argv['debug'];
@ -272,6 +273,12 @@ function loadMachine(sFile)
*/ */
function doCommand(sCmd) function doCommand(sCmd)
{ {
if (!sCmd) {
sCmd = sCmdPrev;
} else {
sCmdPrev = sCmd;
}
var result = false; var result = false;
var aTokens = sCmd.split(' '); var aTokens = sCmd.split(' ');
@ -330,10 +337,12 @@ function doCommand(sCmd)
var onCommand = function (cmd, context, filename, callback) var onCommand = function (cmd, context, filename, callback)
{ {
var result = false; var result = false;
/*
* WARNING: After updating from Node v0.10.x to v0.11.x, the incoming expression in "cmd" is no longer
* parenthesized, so I had to tweak the RegExp below. But... WTF. Do we not care what we break, folks?
*/
var match = cmd.match(/^\(?\s*(.*?)\s*\)?$/); var match = cmd.match(/^\(?\s*(.*?)\s*\)?$/);
if (match) { if (match) result = doCommand(match[1]);
result = doCommand(match[1]);
}
callback(null, result); callback(null, result);
}; };