From 805c70b17d62a78e43b6d2c6b464158f69680419 Mon Sep 17 00:00:00 2001 From: isaacs Date: Mon, 23 Jul 2012 14:49:09 -0700 Subject: read@0.1.1 --- node_modules/read/.npmignore | 2 ++ node_modules/read/README.md | 4 +++- node_modules/read/lib/read.js | 51 +++++++++++++++++++++++++----------------- node_modules/read/package.json | 6 ++--- 4 files changed, 38 insertions(+), 25 deletions(-) create mode 100644 node_modules/read/.npmignore (limited to 'node_modules/read') diff --git a/node_modules/read/.npmignore b/node_modules/read/.npmignore new file mode 100644 index 000000000..0db216bfa --- /dev/null +++ b/node_modules/read/.npmignore @@ -0,0 +1,2 @@ +npm-debug.log +node_modules diff --git a/node_modules/read/README.md b/node_modules/read/README.md index 0c90e1445..2c19d1401 100644 --- a/node_modules/read/README.md +++ b/node_modules/read/README.md @@ -20,9 +20,11 @@ Every option is optional. * `num` Max number of chars to read from terminal. * `timeout` Number of ms to wait for user input before giving up. * `default` The default value if the user enters nothing. +* `stdin` Readable stream to get input data from. (default `process.stdin`) +* `stdout` Writeable stream to write prompts to. (default: `process.stdout`) If silent is true, or num is set, and the input is a TTY, -then read will set raw mode, and read character by character. +then read will set raw mode, and read character by character. At this time, backspace and arrow keys are not supported very well. It's probably not too hard to add support for this, perhaps using node's diff --git a/node_modules/read/lib/read.js b/node_modules/read/lib/read.js index eb00fd5c6..9f3edb57f 100644 --- a/node_modules/read/lib/read.js +++ b/node_modules/read/lib/read.js @@ -4,12 +4,12 @@ module.exports = read var buffer = "" , tty = require("tty") , StringDecoder = require("string_decoder").StringDecoder + , stdin + , stdout -function raw (mode) { - if (process.stdin.setRawMode) { - if (process.stdin.isTTY) { - process.stdin.setRawMode(mode) - } +function raw (stdin, mode) { + if (stdin.setRawMode && stdin.isTTY) { + stdin.setRawMode(mode) return } // old style @@ -28,19 +28,22 @@ function read (opts, cb) { , timeout = opts.timeout , num = opts.num || null + stdin = opts.stdin || process.stdin + stdout = opts.stdout || process.stdout + if (p && def) p += "("+(silent ? "