diff --git a/README.md b/README.md index 4a8db16..adda1ba 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ currentValue = readlineSync.setPrompt([prompt]) Sets the prompt, for example when you run `node` on the command line, you see `> `, which is node's prompt. `prompt` may be string, or may not be (e.g. number, Date, Object, etc.). This is converted to string (i.e. `toString` method is called) before it is displayed every time. -For example: like bash `[foo-directory]# ` +For example: `[foo-directory]# ` like bash ```js readlineSync.setPrompt({toString: diff --git a/lib/encrypt.js b/lib/encrypt.js index b1e475b..ba8f62a 100644 --- a/lib/encrypt.js +++ b/lib/encrypt.js @@ -1,5 +1,5 @@ -var algorithmCipher = 'aes-256-cbc', - cipher = require('crypto').createCipher(algorithmCipher, process.argv[2]), +var cipher = require('crypto').createCipher( + process.argv[2] /*algorithm*/, process.argv[3] /*password*/), stdin = process.stdin, stdout = process.stdout, crypted = ''; diff --git a/lib/readline-sync.js b/lib/readline-sync.js index 536c0f0..99bdb15 100644 --- a/lib/readline-sync.js +++ b/lib/readline-sync.js @@ -95,14 +95,16 @@ function _readlineShell(noEchoBack) { shellPath = 'cmd.exe'; args = ['/V:ON', '/S', '/C', '%Q%' + __dirname + '\\read.bat%Q%' + optEchoBack + - ' |%Q%' + process.execPath + '%Q% %Q%' + __dirname + '\\encrypt.js%Q% %Q%' + password + '%Q%' + + ' |%Q%' + process.execPath + '%Q% %Q%' + __dirname + '\\encrypt.js%Q%' + + ' %Q%' + ALGORITHM_CIPHER + '%Q% %Q%' + password + '%Q%' + ' >%Q%' + pathStdout + '%Q%' + ' & (echo !ERRORLEVEL!)>%Q%' + pathStatus + '%Q% & (echo 1)>%Q%' + pathDone + '%Q%']; } else { shellPath = '/bin/sh'; args = ['-c', '(' + shellPath + ' "' + __dirname + '/read.sh"' + optEchoBack + ')' + - ' |"' + process.execPath + '" "' + __dirname + '/encrypt.js" "' + password + '"' + + ' |"' + process.execPath + '" "' + __dirname + '/encrypt.js"' + + ' "' + ALGORITHM_CIPHER + '" "' + password + '"' + ' >"' + pathStdout + '";' + ' echo $? >"' + pathStatus + '"; echo 1 >"' + pathDone + '"']; } @@ -110,9 +112,7 @@ function _readlineShell(noEchoBack) { stdin.pause(); // re-start in child process require('child_process').execFile(shellPath, args, {env: {Q: '"'}}); - while (true) { - if (fs.readFileSync(pathDone, {encoding: encoding}).trim() === '1') { break; } - } + while (fs.readFileSync(pathDone, {encoding: encoding}).trim() !== '1') {} if (fs.readFileSync(pathStatus, {encoding: encoding}).trim() === '0') { shellStdout = decipher.update(fs.readFileSync(pathStdout, {encoding: 'binary'}), 'hex', encoding) + diff --git a/package.json b/package.json index 32d08fe..2f0d7e7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "readline-sync", "description": "Synchronous Readline", - "version": "0.4.3", + "version": "0.4.4", "homepage": "https://github.com/anseki/readline-sync", "author": { "name": "anseki"