flatiron / prompt

a beautiful command-line prompt for node.js

Home Page:http://github.com/flatiron/prompt

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Option to wait for input?

samgensburg opened this issue · comments

I'm currently creating a simple command-line application that takes in a series (potentially infinite) of commands, and responds to each one at a time. I'd like this to look a bit like this:

prompt.start();
while(true) {
    result = prompt.getSync();
    if (result.command == 'quit') { exit(1); }
    // do something with result
}

Would it be possible to create a version of result.get that would hold execution until a result is returned?

anyone have any ideas? @samgensburg did you figure out a fix?

const prompt = require('prompt');
const getPrompt = require('util').promisify(prompt.get).bind(prompt);

(async function () {
  const { foo, bar } = await getPrompt({
    properties: {
      foo: {
        description: 'Foo',
        // ...
      }
  });
})()

now Ideally this lib should work with promises,