2013-08-29 19:26:22 +02:00
|
|
|
# readlineSync
|
2013-08-29 12:55:23 +02:00
|
|
|
|
2013-08-29 19:26:22 +02:00
|
|
|
Synchronous [Readline](http://nodejs.org/api/readline.html) for interactively running.
|
|
|
|
The interface is used with process.stdin and process.stdout in order to accept user input.
|
2013-08-29 12:55:23 +02:00
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
```js
|
|
|
|
var readlineSync = require('readline-sync');
|
2013-08-29 19:26:22 +02:00
|
|
|
var answer = readlineSync.question('What is your favorite food? :');
|
2013-08-29 12:55:23 +02:00
|
|
|
console.log('Oh, so your favorite food is ' + answer);
|
|
|
|
```
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
```
|
|
|
|
npm install -g readline-sync
|
|
|
|
```
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
2013-08-29 19:26:22 +02:00
|
|
|
### setPrompt
|
|
|
|
|
|
|
|
```js
|
|
|
|
readlineSync.setPrompt(prompt)
|
|
|
|
```
|
|
|
|
|
|
|
|
Sets the prompt, for example when you run `node` on the command line, you see `> `, which is node's prompt.
|
|
|
|
|
|
|
|
### prompt
|
|
|
|
|
|
|
|
```js
|
|
|
|
line = readlineSync.prompt()
|
|
|
|
```
|
|
|
|
|
|
|
|
Readies readline for input from the user, putting the current `setPrompt` options on a new line, giving the user a new spot to write.
|
|
|
|
|
|
|
|
### question
|
|
|
|
|
|
|
|
```js
|
|
|
|
line = readlineSync.question(query)
|
|
|
|
```
|
|
|
|
|
|
|
|
Displays the `query` to the user, and then returns the user's response after it has been typed.
|
|
|
|
|
|
|
|
### setEncoding
|
|
|
|
|
2013-08-29 12:55:23 +02:00
|
|
|
```js
|
2013-08-29 19:26:22 +02:00
|
|
|
readlineSync.setPrompt(encoding)
|
2013-08-29 12:55:23 +02:00
|
|
|
```
|
|
|
|
|
2013-08-29 19:26:22 +02:00
|
|
|
Set the encoding method of input (user's response) and output (`prompt`). Defaults to 'utf8'.
|
2013-08-29 12:55:23 +02:00
|
|
|
|
|
|
|
## Release History
|
2013-08-29 19:26:22 +02:00
|
|
|
* 2013-08-30 v0.2.0 Rewrite exporting methods.
|
2013-08-29 12:55:23 +02:00
|
|
|
* 2013-08-29 v0.1.0 Initial release.
|