@@ -13,7 +13,8 @@ program to gracefully exit:
1313
1414 var rl = readline.createInterface({
1515 input: process.stdin,
16- output: process.stdout
16+ output: process.stdout,
17+ history: ['foo', 'bar', ...]
1718 });
1819
1920 rl.question("What do you think of node.js? ", function(answer) {
@@ -38,6 +39,8 @@ the following values:
3839 - ` terminal ` - pass ` true ` if the ` input ` and ` output ` streams should be
3940 treated like a TTY, and have ANSI/VT100 escape codes written to it.
4041 Defaults to checking ` isTTY ` on the ` output ` stream upon instantiation.
42+
43+ - ` history ` - pass history(Array) to start the cli with previous history (Optional).
4144
4245The ` completer ` function is given the current line entered by the user, and
4346is supposed to return an Array with 2 entries:
@@ -70,11 +73,24 @@ Also `completer` can be run in async mode if it accepts two arguments:
7073 var readline = require('readline');
7174 var rl = readline.createInterface({
7275 input: process.stdin,
73- output: process.stdout
76+ output: process.stdout,
77+ // start the cli with previous history
78+ history: ['foo', 'bar', ...]
7479 });
7580
7681Once you have a readline instance, you most commonly listen for the
77- ` "line" ` event.
82+ ` "line" ` and ` "close" ` events:
83+
84+ rl
85+ .on('line', function(line) {
86+ // ...
87+ lr.pause();
88+ fs.appendFile('path/to/history', line, rl.resume.bind(rl));
89+ })
90+ .on('close', function() {
91+ var history = rl.history;
92+ // save history and exit()
93+ });
7894
7995If ` terminal ` is ` true ` for this instance then the ` output ` stream will get
8096the best compatibility if it defines an ` output.columns ` property, and fires
@@ -91,6 +107,10 @@ stream.
91107Sets the prompt, for example when you run ` node ` on the command line, you see
92108` > ` , which is node's prompt.
93109
110+ ### rl.setHistorySize(size)
111+
112+ Sets the length of history size, the default is 30.
113+
94114### rl.prompt([ preserveCursor] )
95115
96116Readies readline for input from the user, putting the current ` setPrompt `
0 commit comments