Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

I started documenting readline #1076

Closed
wants to merge 3 commits into from

4 participants

@hij1nx

I added some information about readline, something seems better than nothing. I will do another more thorough pass on this module if this looks like a good start.

@indexzero

Cool. Looks like this might have to merged after the commit from @dtrejo yesterday: f4e69e4

Moarrrr docs! Moarrr awesome!

@hij1nx

wtf? haha, i did this yesterday but was too busy to commit! nice @DTrejo =)

@DTrejo

The auto-complete section of what I merged is wrong, I think.

Also, there's a buncha stuff you have there that I don't. Still worth adding it, @hijinx :)

@ry ry closed this
@ry
ry commented

@hijinx rebase your patch on top of @DTrego's changes and open a new pull

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 19, 2011
  1. started readline docs

    hij1nx authored
  2. readline format docs

    hij1nx authored
  3. fixed minor typo

    hij1nx authored
This page is out of date. Refresh to see the latest.
Showing with 111 additions and 0 deletions.
  1. +111 −0 doc/api/readline.markdown
View
111 doc/api/readline.markdown
@@ -0,0 +1,111 @@
+## readline
+
+This module provides utilities for capturing user input. This module is used by the REPL.
+It provides the following methods:
+
+### readline.createInterface(inputStream, outputStream [, completer])
+
+A constructor to create a readline interface.
+Accepts an `inputStream`, an `outputStream` and an optional `completer` function.
+
+Example:
+
+ var readline = require('readline');
+ var rl = readline.createInterface(process.stdin, process.stdout);
+
+ rl.setPrompt('Enter an email address: ');
+ rl.prompt();
+
+ rl.on('line', function(value) {
+ console.log(value)
+ process.kill(process.pid);
+ });
+
+Readline supports tab completion, you can pass a custom completion function that will be executed when the tab key is pressed.
+
+ var commands = [
+ 'info@foo.com',
+ 'support@foo.com',
+ 'sales@foo.com',
+ 'partnership@foo.com'
+ ];
+
+ function complete(line) {
+
+ // Match me with a command.
+ var matches = [];
+
+ // Remove leading whitespace
+ line = line.replace(/^\s*/, '');
+
+ for (var i = 0; i < commands.length; i++) {
+ if (commands[i].indexOf(line) >= 0) {
+ matches.push(commands[i]);
+ }
+ }
+
+ return [matches, line];
+ };
+
+### readline.setPrompt(string)
+
+Set the prompt to the string provided.
+
+### readline.prompt()
+
+Display the prompt.
+
+### readline.question(string, callback)
+
+Set the prompt to the string provided, after input is captured, call the callback.
+
+### key and key combination behaviors
+
+#### Control and shift pressed
+
+ `shift + backspace` delete until end of line toward the left
+ `delete` delete until end of line toward the right
+
+#### Control key pressed
+
+ `ctrl + c` emit SIGINT
+ `ctrl + h` delete left
+ `ctrl + d` delete right or EOF
+ `ctrl + u` delete the whole line
+ `ctrl + k` delete from current to end of line
+ `ctrl + a` move cursor to the start of the line
+ `ctrl + e` move cursor to the end of the line
+ `ctrl + b` move cursor back one character
+ `ctrl + f` move cursor forward one character
+ `ctrl + n` next history item
+ `ctrl + p` previous history item
+ `ctrl + z` exit readline
+
+ `ctrl + delete` delete forward to a word boundary
+ `ctrl + w` or `ctrl + backspace` delete backwards to a word boundary
+ `ctrl + backspace` delete word left
+
+ `ctrl + left` move cursor word left
+ `ctrl + right` move cursor word right
+
+#### Meta key pressed
+
+ `meta + b` move cursor backward word
+ `meta + f` move cursor forward word
+ `meta + d` or `meta + delete` delete forward word
+ `meta + backspace' delete backwards to a word boundary
+
+#### No modifier keys pressed
+
+ `enter` emits the `line` the event and adds the value of the line as history.
+ `backspace` delete a character to the left
+ `delete` delete a character to the right
+ `tab` attempt tab completion (see the `completer` object as detailed above)
+ `left` move cursor left
+ `right` move cursor right
+ `home` move cursor to the beginning of the line
+ `end` move cursor to the end of the line
+
+ `up` previous history item
+ `down` next history item
+
Something went wrong with that request. Please try again.