Skip to content

Commit 29054ff

Browse files
tflanaganrvagg
authored andcommitted
doc: sort readline alphabetically
Reorders, with no contextual changes, the readline documentation alphabetically. PR-URL: #3662 Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 389ead3 commit 29054ff

File tree

1 file changed

+105
-106
lines changed

1 file changed

+105
-106
lines changed

doc/api/readline.markdown

+105-106
Original file line numberDiff line numberDiff line change
@@ -23,75 +23,21 @@ program to gracefully exit:
2323
rl.close();
2424
});
2525

26-
## readline.createInterface(options)
27-
28-
Creates a readline `Interface` instance. Accepts an "options" Object that takes
29-
the following values:
30-
31-
- `input` - the readable stream to listen to (Required).
32-
33-
- `output` - the writable stream to write readline data to (Optional).
34-
35-
- `completer` - an optional function that is used for Tab autocompletion. See
36-
below for an example of using this.
37-
38-
- `terminal` - pass `true` if the `input` and `output` streams should be
39-
treated like a TTY, and have ANSI/VT100 escape codes written to it.
40-
Defaults to checking `isTTY` on the `output` stream upon instantiation.
41-
42-
- `historySize` - maximum number of history lines retained. Defaults to `30`.
43-
44-
The `completer` function is given the current line entered by the user, and
45-
is supposed to return an Array with 2 entries:
46-
47-
1. An Array with matching entries for the completion.
48-
49-
2. The substring that was used for the matching.
50-
51-
Which ends up looking something like:
52-
`[[substr1, substr2, ...], originalsubstring]`.
53-
54-
Example:
55-
56-
function completer(line) {
57-
var completions = '.help .error .exit .quit .q'.split(' ')
58-
var hits = completions.filter(function(c) { return c.indexOf(line) == 0 })
59-
// show all completions if none found
60-
return [hits.length ? hits : completions, line]
61-
}
62-
63-
Also `completer` can be run in async mode if it accepts two arguments:
64-
65-
function completer(linePartial, callback) {
66-
callback(null, [['123'], linePartial]);
67-
}
68-
69-
`createInterface` is commonly used with `process.stdin` and
70-
`process.stdout` in order to accept user input:
71-
72-
var readline = require('readline');
73-
var rl = readline.createInterface({
74-
input: process.stdin,
75-
output: process.stdout
76-
});
77-
78-
Once you have a readline instance, you most commonly listen for the
79-
`"line"` event.
80-
81-
If `terminal` is `true` for this instance then the `output` stream will get
82-
the best compatibility if it defines an `output.columns` property, and fires
83-
a `"resize"` event on the `output` if/when the columns ever change
84-
(`process.stdout` does this automatically when it is a TTY).
85-
8626
## Class: Interface
8727

8828
The class that represents a readline interface with an input and output
8929
stream.
9030

91-
### rl.setPrompt(prompt)
31+
### rl.close()
9232

93-
Sets the prompt, for example when you run `node` on the command line, you see
94-
`> `, which is node.js's prompt.
33+
Closes the `Interface` instance, relinquishing control on the `input` and
34+
`output` streams. The "close" event will also be emitted.
35+
36+
### rl.pause()
37+
38+
Pauses the readline `input` stream, allowing it to be resumed later if needed.
39+
40+
Note that this doesn't immediately pause the stream of events. Several events may be emitted after calling `pause`, including `line`.
9541

9642
### rl.prompt([preserveCursor])
9743

@@ -123,20 +69,14 @@ Example usage:
12369
console.log('Oh, so your favorite food is ' + answer);
12470
});
12571

126-
### rl.pause()
127-
128-
Pauses the readline `input` stream, allowing it to be resumed later if needed.
129-
130-
Note that this doesn't immediately pause the stream of events. Several events may be emitted after calling `pause`, including `line`.
131-
13272
### rl.resume()
13373

13474
Resumes the readline `input` stream.
13575

136-
### rl.close()
76+
### rl.setPrompt(prompt)
13777

138-
Closes the `Interface` instance, relinquishing control on the `input` and
139-
`output` streams. The "close" event will also be emitted.
78+
Sets the prompt, for example when you run `node` on the command line, you see
79+
`> `, which is node.js's prompt.
14080

14181
### rl.write(data[, key])
14282

@@ -154,6 +94,19 @@ Example:
15494

15595
## Events
15696

97+
### Event: 'close'
98+
99+
`function () {}`
100+
101+
Emitted when `close()` is called.
102+
103+
Also emitted when the `input` stream receives its "end" event. The `Interface`
104+
instance should be considered "finished" once this is emitted. For example, when
105+
the `input` stream receives `^D`, respectively known as `EOT`.
106+
107+
This event is also called if there is no `SIGINT` event listener present when
108+
the `input` stream receives a `^C`, respectively known as `SIGINT`.
109+
157110
### Event: 'line'
158111

159112
`function (line) {}`
@@ -194,18 +147,23 @@ Example of listening for `resume`:
194147
console.log('Readline resumed.');
195148
});
196149

197-
### Event: 'close'
150+
### Event: 'SIGCONT'
198151

199152
`function () {}`
200153

201-
Emitted when `close()` is called.
154+
**This does not work on Windows.**
202155

203-
Also emitted when the `input` stream receives its "end" event. The `Interface`
204-
instance should be considered "finished" once this is emitted. For example, when
205-
the `input` stream receives `^D`, respectively known as `EOT`.
156+
Emitted whenever the `input` stream is sent to the background with `^Z`,
157+
respectively known as `SIGTSTP`, and then continued with `fg(1)`. This event
158+
only emits if the stream was not paused before sending the program to the
159+
background.
206160

207-
This event is also called if there is no `SIGINT` event listener present when
208-
the `input` stream receives a `^C`, respectively known as `SIGINT`.
161+
Example of listening for `SIGCONT`:
162+
163+
rl.on('SIGCONT', function() {
164+
// `prompt` will automatically resume the stream
165+
rl.prompt();
166+
});
209167

210168
### Event: 'SIGINT'
211169

@@ -247,25 +205,6 @@ Example of listening for `SIGTSTP`:
247205
console.log('Caught SIGTSTP.');
248206
});
249207

250-
### Event: 'SIGCONT'
251-
252-
`function () {}`
253-
254-
**This does not work on Windows.**
255-
256-
Emitted whenever the `input` stream is sent to the background with `^Z`,
257-
respectively known as `SIGTSTP`, and then continued with `fg(1)`. This event
258-
only emits if the stream was not paused before sending the program to the
259-
background.
260-
261-
Example of listening for `SIGCONT`:
262-
263-
rl.on('SIGCONT', function() {
264-
// `prompt` will automatically resume the stream
265-
rl.prompt();
266-
});
267-
268-
269208
## Example: Tiny CLI
270209

271210
Here's an example of how to use all these together to craft a tiny command
@@ -292,14 +231,6 @@ line interface:
292231
process.exit(0);
293232
});
294233

295-
## readline.cursorTo(stream, x, y)
296-
297-
Move cursor to the specified position in a given TTY stream.
298-
299-
## readline.moveCursor(stream, dx, dy)
300-
301-
Move cursor relative to it's current position in a given TTY stream.
302-
303234
## readline.clearLine(stream, dir)
304235

305236
Clears current line of given TTY stream in a specified direction.
@@ -312,3 +243,71 @@ Clears current line of given TTY stream in a specified direction.
312243
## readline.clearScreenDown(stream)
313244

314245
Clears the screen from the current position of the cursor down.
246+
247+
## readline.createInterface(options)
248+
249+
Creates a readline `Interface` instance. Accepts an "options" Object that takes
250+
the following values:
251+
252+
- `input` - the readable stream to listen to (Required).
253+
254+
- `output` - the writable stream to write readline data to (Optional).
255+
256+
- `completer` - an optional function that is used for Tab autocompletion. See
257+
below for an example of using this.
258+
259+
- `terminal` - pass `true` if the `input` and `output` streams should be
260+
treated like a TTY, and have ANSI/VT100 escape codes written to it.
261+
Defaults to checking `isTTY` on the `output` stream upon instantiation.
262+
263+
- `historySize` - maximum number of history lines retained. Defaults to `30`.
264+
265+
The `completer` function is given the current line entered by the user, and
266+
is supposed to return an Array with 2 entries:
267+
268+
1. An Array with matching entries for the completion.
269+
270+
2. The substring that was used for the matching.
271+
272+
Which ends up looking something like:
273+
`[[substr1, substr2, ...], originalsubstring]`.
274+
275+
Example:
276+
277+
function completer(line) {
278+
var completions = '.help .error .exit .quit .q'.split(' ')
279+
var hits = completions.filter(function(c) { return c.indexOf(line) == 0 })
280+
// show all completions if none found
281+
return [hits.length ? hits : completions, line]
282+
}
283+
284+
Also `completer` can be run in async mode if it accepts two arguments:
285+
286+
function completer(linePartial, callback) {
287+
callback(null, [['123'], linePartial]);
288+
}
289+
290+
`createInterface` is commonly used with `process.stdin` and
291+
`process.stdout` in order to accept user input:
292+
293+
var readline = require('readline');
294+
var rl = readline.createInterface({
295+
input: process.stdin,
296+
output: process.stdout
297+
});
298+
299+
Once you have a readline instance, you most commonly listen for the
300+
`"line"` event.
301+
302+
If `terminal` is `true` for this instance then the `output` stream will get
303+
the best compatibility if it defines an `output.columns` property, and fires
304+
a `"resize"` event on the `output` if/when the columns ever change
305+
(`process.stdout` does this automatically when it is a TTY).
306+
307+
## readline.cursorTo(stream, x, y)
308+
309+
Move cursor to the specified position in a given TTY stream.
310+
311+
## readline.moveCursor(stream, dx, dy)
312+
313+
Move cursor relative to it's current position in a given TTY stream.

0 commit comments

Comments
 (0)