FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

readline: persistent history + repl changes by a8m · Pull Request #596 · nodejs/node · GitHub

/ node Public

readline: persistent history + repl changes - #596

Closed
a8m wants to merge 1 commit into
nodejs:v1.xfrom
a8m:feature/readline-history
Closed

readline: persistent history + repl changes#596
a8m wants to merge 1 commit into
nodejs:v1.xfrom
a8m:feature/readline-history

Conversation

a8m commented Jan 24, 2015

Copy link
Copy Markdown

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:

var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  history: 'path/to/history'
});

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.

Copy link
Copy Markdown
Contributor

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).

a8m commented Jan 24, 2015

Copy link
Copy Markdown
Author

Sorry, I didn't get your point.
I try to explain the process:
first, if there's an history support, fetch from the file, and store in-memory.
so, the previous history is available at the start.
then, on each line, store the current history in the file.

Copy link
Copy Markdown
Contributor

@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 fs.appendFileSync(). This would also avoid using lots of RAM by loading the file into memory.

Edit: this would also allow for two readline's to be run at once with the same history file.

a8m commented Jan 24, 2015

Copy link
Copy Markdown
Author

I agree with you @brendanashworth, it really more sense.
But, because the limit for lines-history(for some reason) it's 30 rows, it's really doesn't matter.
What we can do, it's making it configurable too(make the 30 the default), then append to a file and trim it when it exceeds a particular size.
e.g:

var rl = readline.createInterface({
  //...
  history: 'path/to/history'
});
rl.setHistorySize(100);

what are your thoughts?

Copy link
Copy Markdown
Contributor

@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?

a8m force-pushed the feature/readline-history branch from f5ee0c9 to dff142f Compare January 25, 2015 21:49

a8m commented Jan 25, 2015

Copy link
Copy Markdown
Author

Update:
I've change a bit the previous commit.
Currently, on each line, it's appending to the history file.
Then, when the close function is fired, test if the in-memory history is greater than or equal to _hisotrySize. if so, call writeFileSync and copy the in-memory history to ensure the file is not exceeding the _hisotrySize.(Can you think about more elegant/cheap way to trim the file?).

Also, I've updated the docs and the tests too.
Cheers.

a8m changed the title feat(readline): persistent history + repl changes readline: persistent history + repl changes Jan 25, 2015
Comment thread lib/repl.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This change should not be made to the REPL module, it should be specific to iojs command line repl.

a8m force-pushed the feature/readline-history branch from dff142f to 62b629b Compare January 26, 2015 22:05

a8m commented Jan 26, 2015

Copy link
Copy Markdown
Author

/cc @chrisdickinson

Copy link
Copy Markdown
Contributor

I don't think readline should do any io. The user can just pass history array and retrieve it later

rvagg commented Jan 27, 2015

Copy link
Copy Markdown
Member

+1 to @vkurchatkin's comment above

a8m commented Jan 27, 2015

Copy link
Copy Markdown
Author

@vkurchatkin writing to the terminal is also io, but I get your point.
so, if the load and the save operations will move to the user land, it will look something like that:

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.
Thx.

Copy link
Copy Markdown
Contributor

@a8m it is, but readline doesn't write directly, you provide a stream. This way you can use it with any kind of stream. The same principle applies to history, so that user can store history in memory or database.

a8m force-pushed the feature/readline-history branch 4 times, most recently from 86fb5d8 to 3755b30 Compare January 28, 2015 06:55

Copy link
Copy Markdown
Contributor

What @vkurchatkin said.

a8m commented Jan 29, 2015

Copy link
Copy Markdown
Author

@piscisaureus this PR was updated after @vkurchatkin comments.
Thx

Comment thread doc/api/readline.markdown Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

it's not clear from the example what is the result of loadHistorySync(). It's better to use array literal

a8m force-pushed the feature/readline-history branch from 3755b30 to b577268 Compare January 29, 2015 17:21
Comment thread lib/readline.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

history should be passed here as well

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Right! (I'm usually using it with option object)
changed!

a8m force-pushed the feature/readline-history branch from b577268 to 761826c Compare January 30, 2015 19:51
a8m force-pushed the feature/readline-history branch from 761826c to b5e62c9 Compare January 31, 2015 13:03
brendanashworth added the semver-minor PRs that contain new features and should be released in the next minor version. label Feb 3, 2015
mscdex added the readline Issues and PRs related to the built-in readline module. label Mar 22, 2015
Comment thread src/node.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

style: missing semicolon here

Copy link
Copy Markdown
Contributor

Is there an update on this? It hasn't been touched in a while.

a8m commented Apr 14, 2015

Copy link
Copy Markdown
Author

It's up to you guys.

Copy link
Copy Markdown
Contributor

With 0450ce7 landed, I think this may be obsolete now.

Copy link
Copy Markdown
Contributor

Yep, seems like it.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

readline Issues and PRs related to the built-in readline module. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants


Back | FazBrowse Home | New Git URL