haskell / haskeline

A Haskell library for line input in command-line programs.
https://hackage.haskell.org/package/haskeline
BSD 3-Clause "New" or "Revised" License
223 stars 75 forks source link

Should save history after each command #5

Open nomeata opened 10 years ago

nomeata commented 10 years ago

Programs sometimes terminate badly, especially GHCi when you are hacking GHC, or when testing FFI code, and currently the history is lost, which is annoying.

haskeline should save the history after each entered line, before returning it, to be on the safe side.

nomeata commented 10 years ago

(Also tracked at https://ghc.haskell.org/trac/ghc/ticket/8772)

ulidtko commented 9 years ago

I'd like to see this too for the same reasons.

Though a more flexible approach for Haskeline, I think, would be an API to flush any history lines pending in memory to whatever history file configured.

Then ghci (or whatever other Haskeline user) would be in position to decide whether to flush on each command, or on explicit user request only, or on timer, or configured by an option, etc etc.

lukaszlew commented 6 years ago

+1 bash solution

luntain commented 5 years ago

I propose to append to the history file line by line, as they are entered by the user. Truncate the file on start or exit, but if on exit, we have to read it from the disk in case other processes were appending to it too. It seems easier to do it on startup.

ulidtko commented 5 years ago

@luntain hey, would you please clarify why truncate the history file? You do realize it's for saving user-entered lines between separate runs, don't you.

luntain commented 5 years ago

There is a max size to the history file, so that it does not grow unbounded. I realize the behavior at the moment is to read the history into memory and overwrite the file on exit, regardless if the history file was changed since. I don't like the overwriting on exit from memory because it loses history in case of concurrent uses. I would like to change haskeline so that it appends. This could be line by line, which would eventually cause the file to go over the size limit, hence need truncating, or haskeline could remember the new lines of the session and append everything on exit, taking care to truncate the history file then.

luntain commented 5 years ago

I would like to make that change to haskeline, but would like to get a go ahead first. @judah