Giter Site home page Giter Site logo

co-prompt's Introduction

co-prompt

Sane terminal user-input for nodejs that return thunks for co.

Installation

$ npm install co-prompt

Examples

var name = yield prompt('username: ');
var pass = yield password('password: ');
var desc = yield multiline('description: ');
var ok = yield confirm('are you sure? ');

API

prompt(msg)

Prompt for user input with msg.

prompt.password(msg, [mask])

Prompt for password input with msg and optional mask defaulting to "*".

prompt.multiline(msg)

Prompt for multi-line input with msg.

prompt.confirm(msg)

Prompt for confirmation with msg.

License

MIT

co-prompt's People

Contributors

forbeslindesay avatar tj avatar yaru22 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

co-prompt's Issues

doesn't work on os 10.9

10.9.1
node 0.11.9

var co = require('co');

var prompt = require('co-prompt');
var password = prompt.password;
var confirm = prompt.confirm;

co(function *(){
  var ok = yield confirm('are you sure? ');
  console.log('answer: %s', ok);
  process.stdin.pause();
});

Doesn't do anything when run with node --harmony-generators untitled.js. Just quits.

For node 0.10.21, errors with unexpected token *.

My Node.js process doesn't terminate when using prompt function

I suspect that the problem is that process.stdin is still referenced. See this SO answer.

I have tried another approach using readline:

const readline = require('readline');

function prompt(msg){
  return new Promise((resolve, reject) => {
    const rl = readline.createInterface({
      input: process.stdin,
      output: process.stdout
    });

    rl.question(msg, (answer) => {
      rl.close();
      resolve(answer);
    });
  });
}

What do you think?

Restricting possible user inputs

This isn't really an issue, just a question?

This is how i currently restrict the possible inputs

let a = (yield prompt("Create app? (Y/n) ")) || "Y";
while (!(/^([yn]|(yes)|(no))$/ig.test(a))) a= yield prompt("Create app? (Y/n) ");

Is there a better way of doing it?

prompt Unexpected identifier

i require the co-prompt, but throw an error that say " SyntaxError: Unexpected identifier"
var prompt1 = require("co-prompt");
var name = yield prompt1('username: ');

the error point to second prompt1

i have no idea to resovle it, could you give me the answer?

prompt.password is not working on windows

I tried to get password from gitbash then it showing error

Unhandled Rejection at: Promise {
<rejected> TypeError: process.stdin.setRawMode is not a functions
at ..\node_modules\co-promt\index.js:71:19

after commenting this, passoword take every key as a input.
I will try to solve this weekend, Small help will be appreciated.

prompt in an array

I want to loop through an array and create a series of prompts based off of this array.
I seem to be having trouble stopping the loop in order to collect each prompt sequentially.
For Example, if I have an array named DefaultArray, I want to create a prompt for each item in the DefaultArray:

var co = require('co');
var forEach = require('co-foreach');
var prompt = require('co-prompt');

forEach(defaultVars, function * (item, idx) {
    // do something awesome with generators
    var value = yield prompt(item + ': ');
    console.log(value);
}).then(handleFinish);

Suppose DefaultArray = ['Do you like Apples?', 'Do you like Oranges?'];

I would expect to see:
Do you like Apples?: yes
yes
Do you like Oranges?: no
no

Instead I see:
Do you like Apples?:Do you like Oranges?: yes
yes
yes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.