From f5d4a8231f564bbbbe839fa6efc140768ea1c47a Mon Sep 17 00:00:00 2001 From: anseki Date: Sun, 8 Mar 2015 00:19:40 +0900 Subject: [PATCH] Change a method to open TTY. --- lib/read.bat | 1 - lib/readline-sync.js | 202 ++++++++++++++++++++++++++++++------------- 2 files changed, 141 insertions(+), 62 deletions(-) diff --git a/lib/read.bat b/lib/read.bat index ce34b36..0b883d0 100644 --- a/lib/read.bat +++ b/lib/read.bat @@ -7,7 +7,6 @@ if "%~1"=="noechoback" ( if ERRORLEVEL 1 exit /b 1 ) else ( set /p INPUT=CON - if ERRORLEVEL 1 exit /b 1 ) set /p ="'%INPUT%'"%Q%' + pathStatus + '%Q%%Q%) 2>%Q%' + pathStderr + '%Q%' + ' |%Q%' + process.execPath + '%Q% %Q%' + __dirname + '\\encrypt.js%Q%' + ' %Q%' + ALGORITHM_CIPHER + '%Q% %Q%' + password + '%Q%' + ' >%Q%' + pathStdout + '%Q%' + ' & (echo 1)>%Q%' + pathDone + '%Q%']; } else { - cmdArgs = ['-c', + execArgs = ['-c', // Use `()`, not `{}` for `-c` (text param) - '(' + SHELL_PATH + ' "' + SHELL_CMD + '" ' + args.join(' ') + + '(' + SHELL_PATH + ' "' + SHELL_CMD + '"' + + cmdArgs.map(function(arg) { return ' "' + arg + '"'; }).join('') + '; echo $?>"' + pathStatus + '") 2>"' + pathStderr + '"' + ' |"' + process.execPath + '" "' + __dirname + '/encrypt.js"' + ' "' + ALGORITHM_CIPHER + '" "' + password + '"' + ' >"' + pathStdout + '"' + '; echo 1 >"' + pathDone + '"']; } - childProc.spawn(SHELL_PATH, cmdArgs, execOptions); + childProc.spawn(SHELL_PATH, execArgs, execOptions); while (fs.readFileSync(pathDone, {encoding: encoding}).trim() !== '1') {} if (fs.readFileSync(pathStatus, {encoding: encoding}).trim() === '0') { @@ -177,7 +251,7 @@ function _execSyncByFile(args, execOptions) { res.error = new Error(DEFAULT_ERR_MSG); res.error.method = '_execSyncByFile'; res.error.command = SHELL_CMD; - res.error.args = args; + res.error.args = cmdArgs; res.error.shellMessage = fs.readFileSync(pathStderr, {encoding: encoding}).trim(); } @@ -218,21 +292,27 @@ exports.setBufferSize = function(newBufSize) { }; exports.prompt = function(options) { - return _readlineSync(promptText, options); + options = options || {}; + options.display = promptText + ''; + options.keyIn = false; + return _readlineSync(options); }; exports.question = function(query, options) { - return _readlineSync( + options = options || {}; /* jshint eqnull:true */ - query != null ? query : '', + options.display = query != null ? query + '' : ''; /* jshint eqnull:false */ - options); + options.keyIn = false; + return _readlineSync(options); }; -exports.keyIn = function(query) { - return _readlineSync( +exports.keyIn = function(query, options) { + options = options || {}; /* jshint eqnull:true */ - query != null ? query : '', + options.display = query != null ? query + '' : ''; /* jshint eqnull:false */ - {keyIn: true}); + options.keyIn = true; + options.noEchoBack = false; + return _readlineSync(options); };