Coder Social home page Coder Social logo

prompt's Introduction

Framework components for node.js and the browser

Example HTTP Server:

var flatiron = require('flatiron'),
    app = flatiron.app;

app.use(flatiron.plugins.http);

app.router.get('/', function () {
  this.res.writeHead(200, { 'Content-Type': 'text/plain' });
  this.res.end('Hello world!\n');
});

app.start(8080);

Example HTTPS Server:

var flatiron = require('flatiron'),
    app = flatiron.app;

app.use(flatiron.plugins.http, {
  https: {
    cert: 'path/to/cert.pem',
    key: 'path/to/key.pem',
    ca: 'path/to/ca.pem'
  }
});

app.router.get('/', function () {
  this.res.writeHead(200, { 'Content-Type': 'text/plain' });
  this.res.end('Hello world!\n');
});

app.start(8080);

Example CLI Application:

// example.js

var flatiron = require('flatiron'),
    app = flatiron.app;

app.use(flatiron.plugins.cli, {
  dir: __dirname,
  usage: [
    'This is a basic flatiron cli application example!',
    '',
    'hello - say hello to somebody.'
  ]
});

app.cmd('hello', function () {
  app.prompt.get('name', function (err, result) {
    app.log.info('hello '+result.name+'!');
  })
})

app.start();

Run It:

% node example.js hello
prompt: name: world
info:   hello world!

Installation

Installing NPM (Node Package Manager)

  curl http://npmjs.org/install.sh | sh

Installing Flatiron

  [sudo] npm install flatiron

Installing Union (Required for flatiron.plugins.http)

  npm install union

Usage:

Start With flatiron.app:

flatiron.app is a broadway injection container. To be brief, what it does is allow plugins to modify the app object directly:

var flatiron = require('flatiron'),
    app = flatiron.app;

var hello = {
  attach: function (options) {
    this.hello = options.message || 'Why hello!';
  }
};

app.use(hello, {
  message: "Hi! How are you?"
});

// Will print, "Hi! How are you?"
console.log(app.hello);

Virtually all additional functionality in flatiron comes from broadway plugins, such as flatiron.plugins.http and flatiron.plugins.cli.

app.config

flatiron.app comes with a config plugin pre-loaded, which adds configuration management courtesy nconf. app.config has the same api as the nconf object.

The literal store is configured by default. If you want to use different stores you can easily attach them to the app.config instance.

// add the `env` store to the config
app.config.use('env');

// add the `file` store the the config
app.config.use('file', { file: 'path/to/config.json' });

// or using an alternate syntax
app.config.env().file({ file: 'path/to/config.json' });

// and removing stores
app.config.remove('literal');

app.log

flatiron.app will also load a log plugin during the init phase, which attaches a winston container to app.log. This logger is configured by combining the app.options.log property with the configuration retrieved from app.config.get('log').

Create An HTTP Server with flatiron.plugins.http(options):

This plugin adds http serving functionality to your flatiron app by attaching the following properties and methods:

Define Routes with app.router:

This is a director router configured to route http requests after the middlewares in app.http.before are applied. Example routes include:

// GET /
app.router.get('/', function () {
  this.res.writeHead(200, { 'Content-Type': 'text/plain' });
  this.res.end('Hello world!\n');
});

// POST to /
app.router.post('/', function () {
  this.res.writeHead(200, { 'Content-Type': 'text/plain' });
  this.res.write('Hey, you posted some cool data!\n');
  this.res.end(util.inspect(this.req.body, true, 2, true) + '\n');
});

// Parameterized routes
app.router.get('/sandwich/:type', function (type) {
  if (~['bacon', 'burger'].indexOf(type)) {
    this.res.writeHead(200, { 'Content-Type': 'text/plain' });
    this.res.end('Serving ' + type + ' sandwich!\n');
  }
  else {
    this.res.writeHead(404, { 'Content-Type': 'text/plain' });
    this.res.end('No such sandwich, sorry!\n');
  }
});

app.router can also route against regular expressions and more! To learn more about director's advanced functionality, visit director's project page.

Access The Server with app.server:

This is a union middleware kernel.

Modify the Server Options with app.http:

This object contains options that are passed to the union server, including app.http.before, app.http.after and app.http.headers.

These properties may be set by passing them through as options:

app.use(flatiron.plugins.http, {
  before: [],
  after: []
});

You can read more about these options on the union project page.

Start The Server with app.start(port, <host>, <callback(err)>)

This method will both call app.init (which will call any asynchronous initialization steps on loaded plugins) and start the http server with the given arguments. For example, the following will start your flatiron http server on port 8080:

app.start(8080);

Create a CLI Application with flatiron.plugins.cli(options)

This plugin turns your app into a cli application framework. For example, [jitsu] (https://github.com/nodejitsu/jitsu) uses flatiron and the cli plugin.

Valid options include:

{
  "argvOptions": {}, // A configuration hash passed to the cli argv parser.
  "usage": [ "foo", "bar" ], // A message to show for cli usage. Joins arrays with `\n`.
  "dir": require('path').join(__dirname, 'lib', 'commands'), // A directory with commands to lazy-load
  "notFoundUsage": false // Disable help messages when command not found
}

Add lazy-loaded CLI commands with options.dir and app.commands:

Flatiron CLI will automatically lazy-load modules defining commands in the directory specified by options.dir. For example:

// example2.js
var path = require('path'),
    flatiron = require('./lib/flatiron'),
    app = flatiron.app;

app.use(flatiron.plugins.cli, {
  dir: path.join(__dirname, 'cmds')
});

app.start();
// cmd/highfive.js
var highfive = module.exports = function highfive (person, cb) {
  this.log.info('High five to ' + person + '!');
  cb(null);
};

In the command, you expose a function of arguments and a callback. this is set to app, and the routing is taken care of automatically.

Here it is in action:

% node example2.js highfive Flatiron 
info:   High five to Flatiron!

You can also define these commands by adding them directly to app.commands yourself:

// example2b.js
var flatiron = require('./lib/flatiron'),
    app = flatiron.app;

var path = require('path'),
    flatiron = require('./lib/flatiron'),
    app = flatiron.app;

app.use(flatiron.plugins.cli);

app.commands.highfive = function (person, cb) {
  this.log.info('High five to ' + person + '!');
  cb(null);
};

app.start();
% node example2b.js highfive Flatiron 
info:   High five to Flatiron!

Callback will always be the last argument provided to a function assigned to command

app.commands.highfive = function (person, cb) {
  this.log.info('High five to ' + person + '!');
  console.log(arguments);
}
% node example2b.js highfive Flatiron lol haha
info:    High five to Flatiron!
{
  '0': 'Flatiron',
  '1': 'lol',
  '2': 'haha',
  '3': [Function]
}

Define Ad-Hoc Commands With app.cmd(path, handler):

This adds the cli routing path path to the app's CLI router, using the director route handler handler, aliasing app.router.on. cmd routes are defined the same way as http routes, except that it uses (a space) for a delimiter instead of /.

For example:

// example.js
var flatiron = require('./lib/flatiron'),
    app = flatiron.app;

app.use(flatiron.plugins.cli, {
  usage: [
    'usage: node test.js hello <person>',
    '',
    '  This will print "hello <person>"'
  ]
});

app.cmd('hello :person', function (person) {
  app.log.info('hello ' + person + '!');
});

app.start()

When you run this program correctly, it will say hello:

% node example.js hello person
info:   hello person!

If not, you get a friendly usage message:

% node test.js hello
help:   usage: node test.js hello <person>
help:
help:     This will print "hello <person>"

Check CLI Arguments with app.argv:

Once your app is started, app.argv will contain the optimist-parsed argv options hash, ready to go!

Here's an example:

// example3.js
var flatiron = require('./lib/flatiron'),
    app = flatiron.app;

app.use(flatiron.plugins.cli);

app.start();

app.log.info(JSON.stringify(app.argv));

This prints:

% node example3.js
info:    {"_":[], "$0": "node ./example3.js"}

Awesome!

Add a Default Help Command with options.usage:

When attaching the CLI plugin, just specify options.usage to get a friendly default message for when there aren't any matching routes:

// example4.js
var flatiron = require('./lib/flatiron'),
    app = flatiron.app;

app.use(flatiron.plugins.cli, {
  usage: [
    'Welcome to my app!',
    'Your command didn\'t do anything.',
    'This is expected.'
  ]
});

app.start();
% node example4.js 
help:   Welcome to my app!
help:   Your command didn't do anything.
help:   This is expected.

Start The Application with app.start(callback):

As seen in these examples, starting your app is as easy as app.start! this method takes a callback, which is called when an app.command completes. Here's a complete example demonstrating this behavior and how it integrates with options.usage:

// example5.js
var path = require('path'),
    flatiron = require('./lib/flatiron'),
    app = flatiron.app;

app.use(flatiron.plugins.cli, {
  usage: [
    '`node example5.js error`: Throws an error.',
    '`node example5.js friendly`: Does not throw an error.'
  ]
});

app.commands.error = function (cb) {
  cb(new Error('I\'m an error!'));
};

app.commands.friendly = function (cb) {
  cb(null);
}

app.start(function (err) {
  if (err) {
    app.log.error(err.message || 'You didn\'t call any commands!');
    app.log.warn('NOT OK.');
    return process.exit(1);
  }
  app.log.info('OK.');
});

Here's how our app behaves:

% node example5.js friendly
info:   OK.

% node example5.js error
error:  I'm an error!
warn:   NOT OK.

% node example5.js
help:   `node example2b.js error`: Throws an error.
help:   `node example2b.js friendly`: Does not throw an error.
error:  You didn't call any commands!
warn:   NOT OK.

Read More About Flatiron!

Articles

Sub-Projects

Tests

Tests are written in vows:

  $ npm test

License: MIT

prompt's People

Contributors

3rd-eden avatar alessioalex avatar avianflu avatar badsyntax avatar benatkin avatar bmeck avatar bradfol avatar caleteeter avatar caub avatar coderarity avatar dabh avatar dcm avatar dominictarr avatar dsych avatar eagerod avatar gangstead avatar goatslacker avatar indexzero avatar indutny avatar jcrugzz avatar jfhbrook avatar jordanyaker avatar losttime avatar marak avatar mmalecki avatar pksunkara avatar rubbingalcoholic avatar selfcontained avatar southern avatar yawnt 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

prompt's Issues

Version management

Quick question....

Why in your package.json you used a fixed version. It should be better to use a ~ in the require, it helps to follow the latest module based on its minor version without any change on your module.

eg. ~0.6.2 instead of 0.6.2

See : https://github.com/isaacs/node-semver

My 2 cents

Nested conditional prompts?

I have been looking for a way to nest prompts, but have been unsuccessful:

prompt.get(['question'], function(err, results) {
    if (results.question.toLowerCase() === 'y' || 'yes') {
        prompt.get(['question2'], function(err, results){
            do something;
        })
    } else {
        process.emit('exit');
    }
});

When I run this, regardless of what value the question prompt returns, question2 gets asked.

I have been using prompt for a large portion of my script, so would like to incorporate it in this instance as well. Before I go off and write a replacement function, I wanted to see if somehting like this would be supported (and I am just missing it)

Thanks

No support for Array type in JSON-Schema implementation

Currently, there is no way enter valid values for arrays.

Example:

var prompt = require('../lib/prompt');

var schema = {
  properties: {
    flavors: {
      type: 'array'
    }
  }
};

prompt.start();
prompt.get(schema, function (err, result) {
  if(err) {
    console.log('cancelled error');
    return;
  }
  console.log(err, result);
});

Instead of not being able to enter any values, the user should be presented with a mini-menu for adding items to an array until they are done adding items.

Backspace key does not appear to register while 'hidden' is 'true'

While using Prompt's 'hidden' property to ask for password data, I noticed that hitting a wrong key and then hitting backspace did not allow me to correct my mistake on the fly - when I checked the data that Prompt returned, every letter key I pressed was present in the final string, as if backspace had never been pressed.

Allow for falsy value options

When prompting the user for input, it should be possible to use a falsy value as an option, e.g. options.message to be the empty string, or options.colors to be false.

In addition, when options.message is the empty string, the delimiter should not be printed before the question.

prompt .toLowerCases property names.

This doesn't seem to work:

prompt.get([ 'hookName' ], function (err, results) {
  introspect.generate(results.hookName);
});

because instead of results having a .hookName property, it has a .hookname property.

Imo, it would be nice to fix this, but .toLowerCase-ing strikes me as a deliberate thing to do.

"before" is ignored if description is present, and required flag + default value is uneffective (need to refactor regexp)

Hi guys prompt is a great module, but I've found a couple of minor issues:

var schema={
  properties:{
   filename: {
      before: function(value) { return 'v -> ' + value.red; },
//       description:'Enter output file name'.green,
      pattern: /\b|(^[a-zA-Z\s\-]+$)/,
      message: 'Name must be only letters, spaces, or dashes',
      default: 'filename.json',
      required: false
    },
  }
}

If description is uncommented, then the before function is ignored. Why?

pattern has to be \b|(actual pattern) to allow empty strings, as in (http://stackoverflow.com/questions/3333461/regular-expression-which-matches-a-pattern-or-is-an-empty-string). Otherwise required flag is ignored and an error message is prompted, ignoring the default value and asking for a valid string.

Using Node.js 0.8.15 on Ubuntu 12.04

What if there was invalid value in one of array items?

There seems no chance for user to go back and fix it.

?> numbers1 54
?> numbers2 a  <= INVALID VALUE
?> numbers3
-------------- { '0': '54' }
-------------- { '0': 'a' }
error:   Invalid input for numbers
?> numbers3 <= HOW TO FIX number2 ?

Alternate name for "default" property?

Would it be possible to use an alternate name or create an alias for the "default" property? JSHint is reporting it as a reserved word when I try to lint my code (because it is a reserved word).

automatically call .start()?

The idea is to eliminate the need to call prompt.start().

In a closure containing prompt.start and prompt.get:
  var started = false;
in prompt.start:
     started = true;

in prompt.get:
     if (!started) prompt.start();

This could be implemented directly with extendFunction:

(function() {
  var started = false;
  extendFunction('prompt.start', function(){
    started = true;
  });
  extendFunction('prompt.get', function(){
    if (!started) prompt.start();
  });
})();

Prompt properties should adhere to JSON-Schema format

Currently prompt properties are contained in an array of objects with a name properties in each object.

JSON-Schema properties are stored as key-value pairs where the key is the name property and the value is an object which represents the specific property.

We should stick to the JSON-Schema format since we are already using it in resourceful and revalidator.

Support better port input validation (ie. functions)

related : nodejitsu/jitsu#18

Basically you have to jump through hoops right now if there is a list of properties being added to an object and you need to use a function (in this case a http request) to test if something is valid. In this case we should allow validator to be a simple function that matches :

function myValidator ( newValue, next ) {
  next( isValid( newValue ) );
}

Prompt using utile wrong bug

The signature has changed. The "capitalize" function is no longer part of the "inflect" submodule but is on utile directly
so

capitalize = utile.inflect.capitalize, 

is now

capitalize = utile.capitalize, 

prompt.js

The following needs to be changed from:

var events = require('events'),
    readline = require('readline'),
    utile = require('utile'),
    async = utile.async,
    capitalize = utile.inflect.capitalize, 
    read = require('read'),
    validate = require('revalidator').validate,
    winston = require('winston');

to:

var events = require('events'),
    readline = require('readline'),
    utile = require('utile'),
    async = utile.async,
    capitalize = utile.capitalize, 
    read = require('read'),
    validate = require('revalidator').validate,
    winston = require('winston');

Prompt not blocking

on node v0.8.16 prompt is not blocking when using example code:

var prompt = require('prompt');

//
// Start the prompt
//
prompt.start();

//
// Get two properties from the user: username and email
//
prompt.get(['username', 'email'], function (err, result) {
//
// Log the results.
//
console.log('Command-line input received:');
console.log(' username: ' + result.username);
console.log(' email: ' + result.email);
});

Invalid cursor position after CTRL-C on mac os

Not sure if this is Mac OS specific or not.

To reproduce:

var prompt = require('../lib/prompt');

var schema = {
  properties: {
    cookies: {
      name: 'cookies',
      type: 'number',
      default: 0
    }
  }
};

prompt.start();
prompt.get(schema, function (err, result) {
  if(err) {
    console.log('cancelled error');
    return;
  }
  console.log(err, result);
});

**Run the script, and press CTRL-C when prompted ( to cancel prompt )

~/dev/flatiron/prompt/node examples/schema.js 
prompt: cookies:  cancelled error
~/dev/flatiron/prompt/

Notice that the console.log doesn't register as a new line? It's dumping it on the same line as the prompt. Canceling a prompt should jump the cursor to the start of the next line.

Prompt produces errors in conjunction with Cygwin

Running prompt on a Windows machine within the Cygwin environment produces the following error output. (I've reduced the test-case down to a 'simplest' example).

Node-prompt does run properly in the normal windows environment, but I'd like to use prompt along with some libraries that require cygwin-type support.
It does seem to be a prompt specific problem as other nodejs libraries I've used do not have the same problem (examples: http, express, optimist, socket.io)

Simple Example (prompt-test.js)

var prompt = require('prompt');
prompt.start();
prompt.get(['input'], function (err, result) {
    console.log('input: ' + result.input);
});

Output

prompt: input:
events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: read ENOTCONN
    at errnoException (net.js:884:11)
    at Socket._read (net.js:389:21)
    at Socket.Readable.read (_stream_readable.js:304:10)
    at Socket.read (net.js:291:43)
    at new Socket (net.js:185:10)
    at process.stdin (node.js:660:19)
    at EventEmitter.prompt.start (~\node_modules\prompt\lib\prompt.js:75:38)
    at Object.<anonymous> (\path\to\file\prompt-test.js:2:8)

Extraneous space prepended to delimiter

Hi,

See line 194 of prompt.js:

191  prompt.getInput = function (prop, callback) {
192    var name   = prop.message || prop.name || prop,
193        propName = prop.name || prop,
194        delim  = prompt.delimiter + ' ',
195        raw    = [prompt.message, delim + name.grey, delim.grey],
196        read   = prop.hidden ? prompt.readLineHidden : prompt.readLine,
197        length, msg;

If I set prompt.message and prompt.delimiter to '' (empty string) I would like the property message to begin in the first column of the terminal. As it stands, it will be indented by a single space.

The README states:

The basic structure of a prompt is this:
    prompt.message + prompt.delimiter + property.message + prompt.delimiter;

The default prompt.message is "prompt," the default prompt.delimiter is ": ", and 
the default property.message is property.name.

This isn't really the case. The default prompt.delimiter is ":" and you pad it with an additional space.

Thanks,
-John

cursor position error with multibyte string descriptions

schema:

schema =
    properties:
        'username':
            description: '用户名'
            pattern: /^[a-zA-Z\s\-]+$/
            message: '用户名必须由字母、空格、横线组成'
            required: true
        'password':
            description: '密码'
            required: true
            hidden: true

result:

prompt: 用户名d
prompt: 密码:
{ username: 'd', password: 'a' }

and i have another question:
How to remove the prefix of each line such as "prompt: " "error: ". or place them with other strings

提示: 
错误: 
...

_

_

override property to bypass prompt.

Although prompting is a good UX for first time users, power users may prefer passing in all the options as cli arguments.

I propose adding prompt.override which could be used to achive this:

prompt.override = {name: 'whoever'}

prompt.get(['name'], function (err,answer){
   //it will just take name from .override and not prompt the user. 
})

Then it would be a one line change to add this feature to all the nodejitsu cli tools, prompt.override = optimist.argv

the option would still be validated, and would call back an error if it failed.

configure & disable colors

I see that winston supports configurable colors. It would be nice if prompt did, too. Perhaps it could use the same code to do it if winston's color facility got reorganized a little bit.

process.openStdin() cause problems in Windows

Using process.openStdin() cause some problems in windows, when prompting in a event loop queued callback. I first open this issue in flatiron/flatiron all the explanation is here.

The easy way to reproduce this problem is running something like this:

process.nextTick(function(){
    process.stdin.resume();
    process.stdin.setEncoding('utf8');
    process.stdin.on('error', function (err) {
        console.log(err);
        process.exit();
    });
    process.stdin.on('data', function (chunk) {
        process.stdout.write('data: ' + chunk);
    });
});

process.openStdin();
process.stdin.pause();

BUG: When I add validation to a prompt schema, the name is outputted instead of the description when prompting.

e.g. If I do this:

var promptProperties = [                                                                                                                                   
     {
         description: "Enter your username",
         name: 'username',
         validator: /^[a-zAZ0-9\._-]+$/,
         warning: 'Username must be only letters and/or numbers'
     },
     {
         description: "Enter your password",
         name: 'password',
         hidden: true
     },  
     {
         description: "Enter the message subject",
         name: 'subject'
     },  
     {
         description: "Enter the email message",
         name: 'message'
     }
];

then the first prompt shows prompt: username: but if I do

var promptProperties = [                                                                                                                                   
     {
         description: "Enter your username",
         name: 'username',
     },
     {
         description: "Enter your password",
         name: 'password',
         hidden: true
     },  
     {
         description: "Enter the message subject",
         name: 'subject'
     },  
     {
         description: "Enter the email message",
         name: 'message'
     }   
];

then the first prompt shows prompt: Enter your username: as expected.

read package dependency problem

$ npm install -d
npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
npm info preinstall [email protected]
npm http GET https://registry.npmjs.org/vows
npm http GET https://registry.npmjs.org/pkginfo
npm http GET https://registry.npmjs.org/read
npm http GET https://registry.npmjs.org/revalidator
npm http GET https://registry.npmjs.org/utile
npm http GET https://registry.npmjs.org/winston
npm http 304 https://registry.npmjs.org/read

npm ERR! Error: No compatible version found: read@'>=1.0.0- <1.1.0-'
npm ERR! Valid install targets:
npm ERR! ["0.0.1","0.0.2","0.0.3","0.1.0","0.1.1"]
npm ERR! at installTargetsError (/usr/local/lib/node_modules/npm/lib/cache.js:496:10)
npm ERR! at next_ (/usr/local/lib/node_modules/npm/lib/cache.js:446:17)
npm ERR! at next (/usr/local/lib/node_modules/npm/lib/cache.js:423:44)
npm ERR! at /usr/local/lib/node_modules/npm/lib/cache.js:416:5
npm ERR! at saved (/usr/local/lib/node_modules/npm/lib/utils/npm-registry-client/get.js:151:7)
npm ERR! at Object.oncomplete (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:230:7)
npm ERR! You may report this log at:
npm ERR! http://github.com/isaacs/npm/issues
npm ERR! or email it to:
npm ERR! [email protected]
npm ERR!
npm ERR! System Darwin 12.0.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-d"
npm ERR! cwd /Users/kimon/Documents/fourleafcl/temp/prompt/prompt
npm ERR! node -v v0.6.19
npm ERR! npm -v 1.1.24
npm ERR! message No compatible version found: read@'>=1.0.0- <1.1.0-'
npm ERR! message Valid install targets:
npm ERR! message ["0.0.1","0.0.2","0.0.3","0.1.0","0.1.1"]
npm http 304 https://registry.npmjs.org/utile
npm http 304 https://registry.npmjs.org/pkginfo
npm http 304 https://registry.npmjs.org/revalidator
npm http 304 https://registry.npmjs.org/winston
npm http 200 https://registry.npmjs.org/vows
npm http GET https://registry.npmjs.org/vows/-/vows-0.6.3.tgz
npm http 200 https://registry.npmjs.org/vows/-/vows-0.6.3.tgz
npm info shasum 5b4b2abd99ef1e6b224dc7c58031742f7288b02a
npm info shasum /var/folders/8h/hdz315fj0mdd96p8h5pwfpf00000gn/T/npm-1344029022746/1344029022746-0.9754867081064731/tmp.tgz
npm info shasum 5b4b2abd99ef1e6b224dc7c58031742f7288b02a
npm info shasum /Users/kimon/.npm/vows/0.6.3/package.tgz
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/kimon/Documents/fourleafcl/temp/prompt/prompt/npm-debug.log
npm not ok
npm not ok

exit codes

could we get non-zero exit codes if a user exits out of a prompt?

i tried this, didn't work :(

process.on('exit', function () {
    process.exit(1);
});

Chinese characters problem

var prompt = require('prompt');
prompt.start();

prompt.get(['中文'], function (err, result) {
console.log(' username: ' + result['中文']);
});

this works fine itself.
1

but when i use this snippet in my project,it comes across problem below:
2

the cursor goes in wrong position :(

Bug: Default values not registering for Numbers in JSON-schema API

To replicate:

var prompt = require('../lib/prompt');

var schema = {
  properties: {
    cookies: {
      name: 'cookies',
      format: 'number',
      default: 10
    }
  }
};

prompt.start();
prompt.get(schema, function (err, result) {
  console.log(result);
});
prompt: cookies:  (10) 
[ENTER]

If user presses ENTER without typing value, 10 ( the default value ) is not picked up in the result.

Conditional prompt

There should be a way to do conditional prompt. Useful when some questions depends on the answer of others.

Printing to Console Refresh Prompt Needed

It would be very nice to be able to still do console.log statements to stdout and the prompt would fix itself. Or at minimum have the ability to do prompt.reprompt() and whatever the current prompt, if there is one, is reprinted to stdout.

To make it full fledged goodness you would need to cache the characters typed at the current prompted, print X delete characters removing the old prompt and the cached thus far typed characters and then, after console.log...., reprompt the current prompt with cached content.

FYI - I have socket.io stuff and incoming data is printed out and that is breaking the prompts.

Including description and type: 'number' causes invalid input

Including both a type:'number' and description key seems to break the input.

var fields = {
  price : {
    description : 'Price',
    default : 10,
    type : 'number'
  }
};

prompt.get({ properties : fields }, function (err, result) { 
  // other stuff...
 });

Output:

prompt: Price:  (10) 
error:   Invalid input for Price
prompt: Price:  (10) 1
error:   Invalid input for Price

Using message instead fixes the problem, but doesn't give you a nice name in the input.

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.