{"name":"prompt","description":"A beautiful command-line prompt for node.js","version":"0.2.13","author":{"name":"Nodejitsu Inc.","email":"info@nodejitsu.com"},"maintainers":[{"name":"indexzero","email":"charlie.robbins@gmail.com"},{"name":"mmalecki","email":"me@mmalecki.com"},{"name":"fedor.indutny","email":"fedor.indutny@gmail.com"},{"name":"jcrugzz","email":"jcrugzz@gmail.com"}],"repository":{"type":"git","url":"http://github.com/flatiron/prompt.git"},"dependencies":{"pkginfo":"0.x.x","read":"1.0.x","revalidator":"0.1.x","utile":"0.2.x","winston":"0.6.x"},"devDependencies":{"vows":"0.7.0"},"main":"./lib/prompt","scripts":{"test":"vows test/prompt-test.js --spec","test-all":"vows --spec"},"engines":{"node":">= 0.6.6"},"gitHead":"fc694eea7c5c0b1b97f4faa074526f0eb5e967f0","bugs":{"url":"https://github.com/flatiron/prompt/issues"},"homepage":"https://github.com/flatiron/prompt","_id":"prompt@0.2.13","_shasum":"58c1dab30cf3aab470b658511b121ec9d4ccafaa","_from":".","_npmVersion":"1.4.13","_npmUser":{"name":"jcrugzz","email":"jcrugzz@gmail.com"},"dist":{"shasum":"58c1dab30cf3aab470b658511b121ec9d4ccafaa","tarball":"http://registry-npm.ywwl.com/prompt/download/prompt-0.2.13.tgz","integrity":"sha512-uP8rdHDusddzSWR0rT/P8GlVbhMVjrZefoY3eEWed8bJ3UIZ4wAmFaNn+P9YgGzHGFq8Azx6ifz7EJYffJOZZA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGdC9TCKJgH0P+2EXctYMKdJO5Y2S+36TvBX+TcimPziAiEA32978liASkJP+n5lvSHcG2FcPX+K+J0zvv4PWN46BDY="}],"size":22016,"noattachment":false,"key":"/prompt/-/prompt-0.2.13.tgz"},"directories":{},"readme":"# prompt [![Build Status](https://secure.travis-ci.org/flatiron/prompt.svg)](http://travis-ci.org/flatiron/prompt) [![Npm package version](https://img.shields.io/npm/v/prompt.svg?maxAge=2592000)](https://npmjs.com/package/prompt)\n\n\nA beautiful command-line prompt for node.js\n\n## Features\n\n* prompts the user for input\n* supports validation and defaults\n* hides passwords\n\n## Usage\nUsing prompt is relatively straight forward. There are two core methods you should be aware of: `prompt.get()` and `prompt.addProperties()`. Their methods take strings representing property names in addition to objects for complex property validation (and more). There are a number of [examples][0] that you should examine for detailed usage.\n\n### Getting Basic Prompt Information\nGetting started with `prompt` is easy. Lets take a look at `examples/simple-prompt.js`:\n\n``` js\n  var prompt = require('prompt');\n\n  //\n  // Start the prompt\n  //\n  prompt.start();\n\n  //\n  // Get two properties from the user: username and email\n  //\n  prompt.get(['username', 'email'], function (err, result) {\n    //\n    // Log the results.\n    //\n    console.log('Command-line input received:');\n    console.log('  username: ' + result.username);\n    console.log('  email: ' + result.email);\n  });\n```\n\nThis will result in the following command-line output:\n\n```\n  $ node examples/simple-prompt.js\n  prompt: username: some-user\n  prompt: email: some-user@some-place.org\n  Command-line input received:\n    username: some-user\n    email: some-user@some-place.org\n```\n\nIf no callback is passed to `prompt.get(schema)`, then it returns a `Promise`, so you can also write:\n```js\nconst {username, email} = await prompt.get(['username', 'email']);\n```\n\n\n### Prompting with Validation, Default Values, and More (Complex Properties)\nIn addition to prompting the user with simple string prompts, there is a robust API for getting and validating complex information from a command-line prompt. Here's a quick sample:\n\n``` js\n  var schema = {\n    properties: {\n      name: {\n        pattern: /^[a-zA-Z\\s\\-]+$/,\n        message: 'Name must be only letters, spaces, or dashes',\n        required: true\n      },\n      password: {\n        hidden: true\n      }\n    }\n  };\n\n  //\n  // Start the prompt\n  //\n  prompt.start();\n\n  //\n  // Get two properties from the user: name, password\n  //\n  prompt.get(schema, function (err, result) {\n    //\n    // Log the results.\n    //\n    console.log('Command-line input received:');\n    console.log('  name: ' + result.name);\n    console.log('  password: ' + result.password);\n  });\n```\n\nPretty easy right? The output from the above script is:\n\n```\n  $ node examples/property-prompt.js\n  prompt: name: nodejitsu000\n  error:  Invalid input for name\n  error:  Name must be only letters, spaces, or dashes\n  prompt: name: Nodejitsu Inc\n  prompt: password:\n  Command-line input received:\n    name: Nodejitsu Inc\n    password: some-password\n```\n\n## Valid Property Settings\n`prompt` understands JSON-schema with a few extra parameters and uses [revalidator](https://github.com/flatiron/revalidator) for validation.\n\nHere's an overview of the properties that may be used for validation and prompting controls:\n\n``` js\n  {\n    description: 'Enter your password',     // Prompt displayed to the user. If not supplied name will be used.\n    type: 'string',                 // Specify the type of input to expect.\n    pattern: /^\\w+$/,                  // Regular expression that input must be valid against.\n    message: 'Password must be letters', // Warning message to display if validation fails.\n    hidden: true,                        // If true, characters entered will either not be output to console or will be outputed using the `replace` string.\n    replace: '*',                        // If `hidden` is set it will replace each hidden character with the specified string.\n    default: 'lamepassword',             // Default value to use if no value is entered.\n    required: true                        // If true, value entered must be non-empty.\n    before: function(value) { return 'v' + value; } // Runs before node-prompt callbacks. It modifies user's input\n  }\n```\n\nAlternatives to `pattern` include `format` and `conform`, as documented in [revalidator](https://github.com/flatiron/revalidator).\n\nSupported types are `string`, `boolean`, `number`, `integer`, `array`\n\nUsing `type: 'boolean'` accepts case insensitive values 'true', 't', 'false', 'f'\n\nUsing `type: 'array'` has some special cases.\n\n- `description` will not work in the schema if `type: 'array'` is defined.\n- `maxItems` takes precedence over `minItems`.\n- Arrays that do not have `maxItems` defined will require users to `SIGINT` (`^C`) before the array is ended.\n- If `SIGINT` (`^C`) is triggered before `minItems` is met, a validation error will appear. This will require users to `SIGEOF` (`^D`) to end the input.\n\nFor more information on things such as `maxItems` and `minItems`, refer to the [revalidator](https://github.com/flatiron/revalidator) repository.\n\n### Alternate Validation API:\n\nPrompt, in addition to iterating over JSON-Schema properties, will also happily iterate over an array of validation objects given an extra 'name' property:\n\n```js\n  var prompt = require('../lib/prompt');\n\n  //\n  // Start the prompt\n  //\n  prompt.start();\n\n  //\n  // Get two properties from the user: username and password\n  //\n  prompt.get([{\n      name: 'username',\n      required: true\n    }, {\n      name: 'password',\n      hidden: true,\n      conform: function (value) {\n        return true;\n      }\n    }], function (err, result) {\n    //\n    // Log the results.\n    //\n    console.log('Command-line input received:');\n    console.log('  username: ' + result.username);\n    console.log('  password: ' + result.password);\n  });\n```\n\n### Backward Compatibility\n\nNote that, while this structure is similar to that used by prompt 0.1.x, that the object properties use the same names as in JSON-Schema. prompt 0.2.x is backward compatible with prompt 0.1.x except for asynchronous validation.\n\n### Skipping Prompts\n\nSometimes power users may wish to skip prompts and specify all data as command line options.\nif a value is set as a property of `prompt.override` prompt will use that instead of\nprompting the user.\n\n``` js\n  //prompt-override.js\n\n  var prompt = require('prompt'),\n      optimist = require('optimist')\n\n  //\n  // set the overrides\n  //\n  prompt.override = optimist.argv\n\n  //\n  // Start the prompt\n  //\n  prompt.start();\n\n  //\n  // Get two properties from the user: username and email\n  //\n  prompt.get(['username', 'email'], function (err, result) {\n    //\n    // Log the results.\n    //\n    console.log('Command-line input received:');\n    console.log('  username: ' + result.username);\n    console.log('  email: ' + result.email);\n  })\n\n  //: node prompt-override.js --username USER --email EMAIL\n```\n\nIt is also possible to skip prompts dynamically based on previous prompts.\nIf an `ask` method is added, prompt will use it to determine if the prompt should be displayed.\nIf `ask` returns true the prompt is displayed. otherwise, the default value or empty string are used.\n\n``` js\n  var schema = {\n    properties: {\n      proxy: {\n        description: 'Proxy url',\n      },\n      proxyCredentials: {\n        description: 'Proxy credentials',\n        ask: function() {\n          // only ask for proxy credentials if a proxy was set\n          return prompt.history('proxy').value > 0;\n        }\n      }\n    }\n  };\n\n  //\n  // Start the prompt\n  //\n  prompt.start();\n\n  //\n  // Get one or two properties from the user, depending on\n  // what the user answered for proxy\n  //\n  prompt.get(schema, function (err, result) {\n    //\n    // Log the results.\n    //\n    console.log('Command-line input received:');\n    console.log('  proxy: ' + result.proxy);\n    console.log('  credentials: ' + result.proxyCredentials);\n  });\n```\n\n\n### Adding Properties to an Object\nA common use-case for prompting users for data from the command-line is to extend or create a configuration object that is passed onto the entry-point method for your CLI tool. `prompt` exposes a convenience method for doing just this:\n\n``` js\n  var obj = {\n    password: 'lamepassword',\n    mindset: 'NY'\n  }\n\n  //\n  // Log the initial object.\n  //\n  console.log('Initial object to be extended:');\n  console.dir(obj);\n\n  //\n  // Add two properties to the empty object: username and email\n  //\n  prompt.addProperties(obj, ['username', 'email'], function (err) {\n    //\n    // Log the results.\n    //\n    console.log('Updated object received:');\n    console.dir(obj);\n  });\n```\n\n### Prompt history\nYou can use the `prompt.history()` method to get access to previous prompt input.\n\n``` js\n  prompt.get([{\n    name: 'name',\n    description: 'Your name',\n    type: 'string',\n    required: true\n  }, {\n    name: 'surname',\n    description: 'Your surname',\n    type: 'string',\n    required: true,\n    message: 'Please dont use the demo credentials',\n    conform: function(surname) {\n      var name = prompt.history('name').value;\n      return (name !== 'John' || surname !== 'Smith');\n    }\n  }], function(err, results) {\n    console.log(results);\n  });\n```\n\n## Customizing your prompt\nAside from changing `property.message`, you can also change `prompt.message`\nand `prompt.delimiter` to change the appearance of your prompt.\n\nThe basic structure of a prompt is this:\n\n``` js\nprompt.message + prompt.delimiter + property.message + prompt.delimiter;\n```\n\nThe default `prompt.message` is \"prompt,\" the default `prompt.delimiter` is\n\": \", and the default `property.message` is `property.name`.\nChanging these allows you to customize the appearance of your prompts! In\naddition, prompt supports ANSI color codes via the\n[colors module](https://github.com/DABH/colors.js) for custom colors. For a\nvery colorful example:\n\n``` js\n  var prompt = require(\"prompt\");\n  var colors = require(\"@colors/colors/safe\");\n  //\n  // Setting these properties customizes the prompt.\n  //\n  prompt.message = colors.rainbow(\"Question!\");\n  prompt.delimiter = colors.green(\"><\");\n\n  prompt.start();\n\n  prompt.get({\n    properties: {\n      name: {\n        description: colors.magenta(\"What is your name?\")\n      }\n    }\n  }, function (err, result) {\n    console.log(colors.cyan(\"You said your name is: \" + result.name));\n  });\n```\n\nIf you don't want colors, you can set\n\n```js\nvar prompt = require('prompt');\n\nprompt.colors = false;\n```\n\n## Integration with streamlinejs\n\nWhen integrating prompt with projects using streamlinejs such as the following\n\n```\nprompt.start();\nfunction test_prompt(_){\n    console.log(prompt.get(loadDataValues(), _).output);\n}\ntest_prompt(_);\n```\n\nThis will work, however the process is then stuck with a stdin stream still open. If you setup the traditional way (with callback) such as this\n\n ```\nprompt.start();\nfunction test_prompt(){\n    prompt.get(loadDataValues(), function(err, data){\n        console.log(data.output);\n    });\n}\ntest_prompt();\n```\nThis works and ends correctly.\n\nTo resolve this we have added a new method to prompt, which will stop the stdin stream\n\n```\n//\n// ### function stop ()\n// Stops input coming in from stdin\n//\nprompt.stop = function () {\n    if (prompt.stopped || !prompt.started) {\n        return;\n    }\n\n    stdin.destroy();\n    prompt.emit('stop');\n    prompt.stopped = true;\n    prompt.started = false;\n    prompt.paused = false;\n    return prompt;\n}\n```\n\nAnd you can find an example in the example folder `examples/prompt-streamline.js`\n\n```\n/*\n * prompt-streamline._js: Example of how to use prompt with streamlinejs.\n *\n * calling syntax: _node prompt-streamline._js\n *\n */\nvar prompt = require('../lib/prompt');\n\nfunction getSampleData(){\n    return [\n        {\n            name: 'username',\n            message: 'Enter a username'\n        }\n    ];\n};\n\n//\n// Start the prompt\n//\nprompt.start();\n\nfunction get_username_prompt(_){\n    console.log(prompt.get(getSampleData(), _).username);\n}\n\nget_username_prompt(_);\n\n//\n// Clean the prompt\n//\nprompt.stop();\n```\n\n## Disabling prompt's built-in SIGINT handling\n\nBy default, prompt prompt binds a process-killing event handler to the SIGINT event (CTRL+C). This allows easily exiting from prompts, but can prevent an app from executing other event handlers when an interrupt is received. In order to override this default behavior, pass a `{noHandleSIGINT: true}` option into `prompt.start`.\n\n``` js\n  //\n  // Disable prompt's built-in SIGINT handling:\n  //\n  prompt.start({noHandleSIGINT: true});\n  \n  process.on('SIGINT', function() {\n    console.log(\"This will execute when you hit CTRL+C\");\n    process.exit();\n  });\n```\n\n\n## Installation\n\n``` bash\n  $ [sudo] npm install prompt\n```\n\n## Running tests\n\n``` bash\n  $ npm test\n```\n\n#### License: MIT\n#### Author: [Charlie Robbins](http://github.com/indexzero)\n#### Contributors: [Josh Holbrook](http://github.com/jesusabdullah), [Pavan Kumar Sunkara](http://github.com/pksunkara)\n\n[0]: https://github.com/flatiron/prompt/tree/master/examples\n","publish_time":1401054095731,"_cnpm_publish_time":1401054095731,"dist-tags":{"latest":"1.3.0"}}