Skip to content
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

Make file format compatible with Node's #6

Open
eush77 opened this issue May 31, 2015 · 2 comments
Open

Make file format compatible with Node's #6

eush77 opened this issue May 31, 2015 · 2 comments

Comments

@eush77
Copy link
Collaborator

eush77 commented May 31, 2015

repl.history's file format is not compatible with Node's history file format. nodejs/node#1513

After pointing NODE_REPL_HISTORY_FILE to my old history file I get the following error:

Error: Could not parse history data in .../.node_history.

It would be nice to have one file format be used both from native repls and repls built on top of this module.

@tmpvar
Copy link
Owner

tmpvar commented May 31, 2015

just gave you the commit bit since I don't have time to maintain this project at the moment and you seem eager.

borisdiakur pushed a commit to borisdiakur/n_ that referenced this issue Mar 18, 2016
For now the history is stored in a file named “.n_repl_history” in the user’s home directory. If some day in the future a sharable default emerges, this may be changed.

References:

    tmpvar/repl.history#6
    closes #16
@harrysarson
Copy link
Contributor

harrysarson commented Jul 17, 2017

I have had a look into how the node repl handles history.

The file format is very similar to the format used by repl.history but the entries are stored in the opposite order. repl.history puts newest lines at the bottom of the file where as node puts newest lines first.

The meaty code is:
https://github.com/nodejs/node/blob/master/lib/internal/repl.js#L72-L234

On line 211:

function flushHistory() {
    timer = null;
    if (writing) {
      pending = true;
      return;
    }
    writing = true;
    const historyData = repl.history.join(os.EOL);
    fs.write(repl._historyHandle, historyData, 0, 'utf8', onwritten);
  }

Nothing any fancier than completely rewriting the file every time something happens.

It wouldn't be too hard to do the same for repl.history I do think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants