-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
readline: persistent history + repl changes #596
Conversation
Is there a benefit to loading the current history into memory rather than just appending to the as-is history file? From what I'm seeing, it would allow a programmer to access previous history - at the expense of a breaking change to what they might have previously relied on (i.e., first command ran = first index). |
Sorry, I didn't get your point. |
@a8m its alright. I intended to ask: why load on startup and overwrite the entire file every time a new line is entered, rather than appending each time a new line is entered? For a big file (lets say 10Mb), and someone enters twenty lines, that'd be ~210Mb of input / output rather than just a few bytes (~8Kb) by appending to the file using Edit: this would also allow for two readline's to be run at once with the same history file. |
I agree with you @brendanashworth, it really more sense. var rl = readline.createInterface({
//...
history: 'path/to/history'
});
rl.setHistorySize(100); what are your thoughts? |
@a8m I like that idea, 👍 from me on that topic. On a side note, could you clean up your commit title and description to fit the guidelines? |
f5ee0c9
to
dff142f
Compare
Update: Also, I've updated the docs and the tests too. |
@@ -31,6 +31,8 @@ const rl = require('readline'); | |||
const Console = require('console').Console; | |||
const domain = require('domain'); | |||
const debug = util.debuglog('repl'); | |||
const HISTORY_PATH = path.join(process.env.HOME || process.env.USERPROFILE, | |||
'.iojs_history'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change should not be made to the REPL module, it should be specific to iojs command line repl.
dff142f
to
62b629b
Compare
/cc @chrisdickinson |
I don't think |
+1 to @vkurchatkin's comment above |
@vkurchatkin writing to the terminal is also io, but I get your point. readline.createInterface({
//...
history: loadSync('history')
})
.on('line', // append to a file)
.on('close', // or save on closing) If this is acceptable to you guys, I'll make this changes. |
@a8m it is, but |
86fb5d8
to
3755b30
Compare
What @vkurchatkin said. |
@piscisaureus this PR was updated after @vkurchatkin comments. |
@@ -13,7 +13,8 @@ program to gracefully exit: | |||
|
|||
var rl = readline.createInterface({ | |||
input: process.stdin, | |||
output: process.stdout | |||
output: process.stdout, | |||
history: loadHistorySync() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not clear from the example what is the result of loadHistorySync()
. It's better to use array literal
3755b30
to
b577268
Compare
@@ -24,7 +21,7 @@ exports.createInterface = function(input, output, completer, terminal) { | |||
}; | |||
|
|||
|
|||
function Interface(input, output, completer, terminal) { | |||
function Interface(input, output, completer, terminal, history) { | |||
if (!(this instanceof Interface)) { | |||
return new Interface(input, output, completer, terminal); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
history
should be passed here as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right! (I'm usually using it with option
object)
changed!
b577268
to
761826c
Compare
761826c
to
b5e62c9
Compare
(user ? (process.getuid() === 0 ? '/root' : '/home/' + user) : null); | ||
} | ||
return home || null; | ||
})() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: missing semicolon here
Is there an update on this? It hasn't been touched in a while. |
It's up to you guys. |
With 0450ce7 landed, I think this may be obsolete now. |
Yep, seems like it. |
As I commented in #343
I think the persistent history support should be part of the
readline
module.After this changes, any cli that using
readline
would be able to support too.e.g:
The "main" changes is in the
readline
module and it's tested too.I also changed a bit the
repl
module, and add the history support by default.Maybe it should become with flags(
NODE_DISABLE_HISTORY
,NODE_HISTORY_PATH
) like @evanlucas suggested, but this is out of the scope of this PR.Thanks.