From 934c82b8b8f0dabbcc5635f1912fa905103a4865 Mon Sep 17 00:00:00 2001 From: Nebu Date: Wed, 20 Apr 2011 12:04:42 -0400 Subject: [PATCH] Partially documented the readline module. --- doc/api/readline.markdown | 61 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/doc/api/readline.markdown b/doc/api/readline.markdown index e69de29..661ad94 100644 --- a/doc/api/readline.markdown +++ b/doc/api/readline.markdown @@ -0,0 +1,61 @@ +## Readline + +This module allows reading of a stream (such as STDIN) on a line-by-line basis. + +Note that once you've invoked this module, your node program will not terminate +until you've closed the interface, and the STDIN stream. Here's how to allow +your program to gracefully terminate: + +
+var readline = require('readline');
+
+var i = readline.createInterface(process.sdtin, process.stdout, null);
+i.question("What do you think of node.js?", function(answer) {
+  //TODO: Log the answer in a database
+  console.log("Thank you for your valuable feedback.");
+  i.close();                //These two lines together allow the program to
+  process.stdin.destroy();  //terminate. Without them, it would run forever.
+});
+
+ +### createInterface(input, output, completer) + +Returns an interface object, which reads from input, and writes to output. +TODO: I think "completer" is used for tab-completion, but not sure. + +### interface.setPrompt(prompt, length) + +TODO + +### interface.prompt() + +TODO: Appears to trigger showing the prompt. + +### interface.question(query, cb) + +Displays the query to the user, and then calls the callback after the user +has typed in their response. + +Example usage: + +
+interface.question("What is your favorite food?", function(answer) {
+  console.log("Oh, so your favorite food is " + answer);
+});
+
+ +### interface.close() + +TODO + +### interface.pause() + +TODO + +### interface.resume() + +TODO + +### interface.write() + +TODO -- 2.7.4