GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — readline: persistent history + repl changes by a8m · Pull Request #596 · nodejs/node

Conversation

@a8m

@a8m 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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@brendanashworth

brendanashworth commented Jan 24, 2015

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@a8m

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brendanashworth

brendanashworth commented Jan 24, 2015

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@a8m

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?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brendanashworth

brendanashworth commented Jan 24, 2015

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?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

@chrisdickinson chrisdickinson Jan 26, 2015

Copy link
Copy Markdown
Contributor

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

a8m commented Jan 26, 2015

Copy link
Copy Markdown
Author

/cc @chrisdickinson

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vkurchatkin

vkurchatkin commented Jan 27, 2015

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rvagg

rvagg commented Jan 27, 2015

Copy link
Copy Markdown
Member

+1 to @vkurchatkin's comment above

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@a8m

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vkurchatkin

vkurchatkin commented Jan 27, 2015

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

piscisaureus commented Jan 29, 2015

Copy link
Copy Markdown
Contributor

What @vkurchatkin said.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@a8m

a8m commented Jan 29, 2015

Copy link
Copy Markdown
Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vkurchatkin
vkurchatkin reviewed Jan 29, 2015
View reviewed changes
Comment thread doc/api/readline.markdown Outdated

@vkurchatkin vkurchatkin Jan 29, 2015

Copy link
Copy Markdown
Contributor

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@a8m
a8m force-pushed the feature/readline-history branch from 3755b30 to b577268 Compare January 29, 2015 17:21
evanlucas
evanlucas reviewed Jan 30, 2015
View reviewed changes
Comment thread lib/readline.js Outdated

@evanlucas evanlucas Jan 30, 2015

Copy link
Copy Markdown
Contributor

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@a8m a8m Jan 30, 2015

Copy link
Copy Markdown
Author

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!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@a8m
a8m force-pushed the feature/readline-history branch from b577268 to 761826c Compare January 30, 2015 19:51
@a8m
readline: support history + repl changes
b5e62c9
@a8m
a8m force-pushed the feature/readline-history branch from 761826c to b5e62c9 Compare January 31, 2015 13:03
@vkurchatkin vkurchatkin mentioned this pull request Jan 31, 2015
repl: save repl session in file #442
Closed
@rvagg rvagg mentioned this pull request Jan 31, 2015
Pull in sindresorhus/user-home as os.homedir() #682
Closed
@brendanashworth brendanashworth added the semver-minor PRs that contain new features and should be released in the next minor version. label Feb 3, 2015
@mscdex mscdex added the readline Issues and PRs related to the built-in readline module. label Mar 22, 2015
brendanashworth
brendanashworth reviewed Apr 13, 2015
View reviewed changes
Comment thread src/node.js Outdated

@brendanashworth brendanashworth Apr 13, 2015

Copy link
Copy Markdown
Contributor

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@brendanashworth

brendanashworth commented Apr 13, 2015

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@a8m

a8m commented Apr 14, 2015

Copy link
Copy Markdown
Author

It's up to you guys.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chrisdickinson chrisdickinson added the land-on-master label Apr 17, 2015
@brendanashworth brendanashworth mentioned this pull request Apr 24, 2015
REPL – Add "magic" mode detection, persistent history support #1513
Closed
@silverwind

silverwind commented May 1, 2015

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fishrock123

Fishrock123 commented May 1, 2015

Copy link
Copy Markdown
Contributor

Yep, seems like it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fishrock123 Fishrock123 closed this May 1, 2015
This was referenced Jun 22, 2023
[Snyk] Fix for 1 vulnerabilities aliscco/alisco-node#506
Open
[Snyk] Fix for 1 vulnerabilities aliscco/alisco-node#543
Open
[Snyk] Fix for 1 vulnerabilities aliscco/alisco-node#574
Open
@leonardoadame leonardoadame mentioned this pull request Jul 7, 2023
[Snyk] Fix for 4 vulnerabilities leonardoadame/node#63
Open
This was referenced Nov 17, 2026
Report event dispatches to the dependency graph as emitEvent replayio/node#242
Merged
Report process.nextTick() as a microtask to the dependency graph replayio/node#243
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

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

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

10 participants

@a8m @brendanashworth @vkurchatkin @rvagg @piscisaureus @silverwind @Fishrock123 @chrisdickinson @evanlucas @mscdex
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.