1 | For reading user input from stdin.
|
2 |
|
3 | ## USAGE
|
4 |
|
5 | ```javascript
|
6 | var read = require("read")
|
7 | read(options, callback)
|
8 | ```
|
9 |
|
10 | The callback gets called with either the user input, or the default
|
11 | specified, or an error, in the traditional `callback(error, result)`
|
12 | node style.
|
13 |
|
14 | ## OPTIONS
|
15 |
|
16 | Every option is optional.
|
17 |
|
18 | * `prompt` What to write to stdout before reading input.
|
19 | * `silent` Don't echo the output as the user types it.
|
20 | * `num` Max number of chars to read from terminal.
|
21 | * `delim` The char that means we're done. Default: `"\n"`
|
22 | * `timeout` Number of ms to wait for user input before giving up.
|
23 | * `default` The default value if the user enters nothing.
|
24 |
|
25 | If silent is true, or num is set, or delim is something other than
|
26 | `"\n"`, then read will set raw mode, and read character by character.
|
27 |
|
28 | At this time, backspace and arrow keys are not supported in raw mode.
|
29 | It's probably not too hard to add support for this, perhaps using node's
|
30 | built-in readline module.
|
31 |
|
32 | ## CONTRIBUTING
|
33 |
|
34 | Patches welcome.
|
35 |
|
36 | ## BUGS
|
37 |
|
38 | In node 0.6.0 through 0.6.5, you must explicitly call
|
39 | `process.stdin.destroy()` or `process.exit()` when you know that your
|
40 | program is done reading, or else it will keep the event loop running
|
41 | forever.
|
42 |
|
43 | See: <https://github.com/joyent/node/issues/2257>
|