diff --git a/README.md b/README.md index 3095001..825b823 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ answer = readlineSync.question([query[, options]]) Displays the `query` to the user, and then returns the user's response after it has been typed. You can specify `options`. (see [Options](#options)) -The `query` 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. +The `query` 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. ### prompt @@ -127,7 +127,7 @@ console.log('Login ...'); The typed text is not shown on screen. -```shell +``` PASSWORD : Login ... ``` diff --git a/lib/readline-sync.js b/lib/readline-sync.js index 6fef6d4..6b891ee 100644 --- a/lib/readline-sync.js +++ b/lib/readline-sync.js @@ -9,7 +9,6 @@ 'use strict'; var - BUF_SIZE = 256, IS_WIN = process.platform === 'win32', SHELL_PATH = IS_WIN ? 'cmd.exe' : '/bin/sh', @@ -20,14 +19,15 @@ var childProc = require('child_process'), stdin = process.stdin, stdout = process.stdout, - buffer = new Buffer(BUF_SIZE), promptText = '> ', encoding = 'utf8', + bufSize = 256, useShell = true, print, tempdir, salt = 0; function _readlineSync(display, options) { - var input = '', rsize, err; + var input = '', buffer = new Buffer(bufSize), + rsize, err; if (display !== '') { // null and undefined were excluded. if (typeof print === 'function') { print(display, encoding); } @@ -49,7 +49,7 @@ function _readlineSync(display, options) { rsize = 0; try { - rsize = fs.readSync(stdin.fd, buffer, 0, BUF_SIZE); + rsize = fs.readSync(stdin.fd, buffer, 0, bufSize); } catch (e) { if (e.code === 'EOF') { break; } // pipe @@ -197,6 +197,13 @@ exports.setEncoding = function(newEncoding) { return encoding; }; +exports.setBufferSize = function(newBufSize) { + if (typeof newBufSize === 'number') { + bufSize = newBufSize; + } + return bufSize; +}; + exports.prompt = function(options) { return _readlineSync(promptText, options); };