prompt-promise
Version:
Sane CLI user-input (command prompt, confirm, multiline, password) as promises, it can be used with co@4
100 lines (77 loc) • 3.07 kB
Markdown
as promises, it can be used with [co@4][co]
```
npm i --save prompt-promise
```
```
npm run with-co
npm run without-co
```
> For more use-cases see [examples](./examples)
```js
var co = require('co');
var prompt = require('prompt-promise');
var res = [];
prompt('username: ')
.then(function username(val) {
res.push(val);
return prompt.password('password: ');
})
.then(function pasword(val) {
res.push(val);
console.log(res);
prompt.done();
})
.catch(function rejected(err) {
console.log('error:', err.stack);
prompt.finish();
});
// or with `co@4`
co(function * genPrompt() {
var username = yield prompt('username: ');
var password = yield prompt.password('password: ');
return yield [username, password];
})
.then(function fulfilled(array) {
console.log('response:', array);
prompt.end();
})
.catch(function rejected(err) {
console.log('error:', err.stack);
process.stdin.pause();
});
```
`.end()`, `.done()`, `.finish()` are just aliases for `process.stdin.pause();` its required, nah..
**Charlike Mike Reagent**
+ [gratipay/tunnckoCore][author-gratipay]
+ [twitter/tunnckoCore][author-twitter]
+ [github/tunnckoCore][author-github]
+ [npmjs/tunnckoCore][author-npmjs]
+ [more ...][contrib-more]
Copyright (c) 2014-2015 [Charlike Mike Reagent][contrib-more], [contributors][contrib-graf].
Copyright (c) 2014 [TJ Holowaychuk](https://github.com/tj), [contributors][contrib-graf].
Released under the [`MIT`][license-url] license.
[ ]: http://npm.im/prompt-promise
[ ]: https://img.shields.io/npm/v/prompt-promise.svg?style=flat&label=prompt-promise
[ ]: https://coveralls.io/r/tunnckoCore/prompt-promise?branch=master
[ ]: https://img.shields.io/coveralls/tunnckoCore/prompt-promise.svg?style=flat
[ ]: https://github.com/tunnckoCore/prompt-promise/blob/master/license.md
[ ]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat
[ ]: https://travis-ci.org/tunnckoCore/prompt-promise
[ ]: https://img.shields.io/travis/tunnckoCore/prompt-promise.svg?style=flat
[ ]: https://david-dm.org/tunnckoCore/prompt-promise
[ ]: https://img.shields.io/david/tunnckoCore/prompt-promise.svg?style=flat
[ ]: https://gratipay.com/tunnckoCore
[ ]: https://twitter.com/tunnckoCore
[ ]: https://github.com/tunnckoCore
[ ]: https://npmjs.org/~tunnckocore
[ ]: http://j.mp/1stW47C
[ ]: https://github.com/tunnckoCore/prompt-promise/graphs/contributors
***
_Powered and automated by [kdf](https://github.com/tunnckoCore), January 31, 2015_
[ ]: https://github.com/tj/co
> Sane CLI user-input (command prompt, confirm, multiline, password)