From a0cd3578d9bf883443cdaebb5736cde577226f8b Mon Sep 17 00:00:00 2001 From: Jeff Parsons Date: Sun, 5 Apr 2015 12:13:14 -0700 Subject: [PATCH] PCjs CLI now repeats previous commands (just press Enter again) --- modules/pcjs/bin/pcjs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/pcjs/bin/pcjs b/modules/pcjs/bin/pcjs index ba474b539..59070beaa 100644 --- a/modules/pcjs/bin/pcjs +++ b/modules/pcjs/bin/pcjs @@ -44,6 +44,7 @@ var fConsole = false; var fDebug = false; var args = proc.getArgs(); var argv = args.argv; +var sCmdPrev = null; if (argv['console'] !== undefined) fConsole = argv['console']; if (argv['debug'] !== undefined) fDebug = argv['debug']; @@ -272,6 +273,12 @@ function loadMachine(sFile) */ function doCommand(sCmd) { + if (!sCmd) { + sCmd = sCmdPrev; + } else { + sCmdPrev = sCmd; + } + var result = false; var aTokens = sCmd.split(' '); @@ -330,10 +337,12 @@ function doCommand(sCmd) var onCommand = function (cmd, context, filename, callback) { 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*\)?$/); - if (match) { - result = doCommand(match[1]); - } + if (match) result = doCommand(match[1]); callback(null, result); };