summaryrefslogtreecommitdiff
path: root/node_modules/prompt/examples/history.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/prompt/examples/history.js')
-rw-r--r--node_modules/prompt/examples/history.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/node_modules/prompt/examples/history.js b/node_modules/prompt/examples/history.js
new file mode 100644
index 0000000..fd4369d
--- /dev/null
+++ b/node_modules/prompt/examples/history.js
@@ -0,0 +1,44 @@
+/*
+ * history.js: Example of using the prompt history capabilities.
+ *
+ * (C) 2010, Nodejitsu Inc.
+ *
+ */
+
+var prompt = require('../lib/prompt');
+
+//
+// Start the prompt
+//
+prompt.start();
+
+var properties = {
+ properties: {
+ animal: {
+ description: 'Enter an animal',
+ default: 'dog',
+ pattern: /dog|cat/
+ },
+ sound: {
+ description: 'What sound does this animal make?',
+ conform: function (value) {
+ var animal = prompt.history(0).value;
+
+ return animal === 'dog' && value === 'woof'
+ || animal === 'cat' && value === 'meow';
+ }
+ }
+ }
+}
+
+//
+// Get two properties from the user
+//
+prompt.get(properties, function (err, result) {
+ //
+ // Log the results.
+ //
+ console.log('Command-line input received:');
+ console.log(' animal: ' + result.animal);
+ console.log(' sound: ' + result.sound);
+});