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

RFE: clearInput? #178

Open juhp opened 1 year ago

juhp commented 1 year ago

I was looking for an easy way to clear stdin before getInputLine.

So I was wondering if it would make sense to add a clearInput function to haskeline. I don't know how portable that would be or how easy to implement: perusing the code made me think it could be possible, but complicated for me at least.

For now I did a workaround (which will probably be in simple-prompt-0.1.1) which checks how little time passed since getInputLine: if it is less that 5ms then I repeat the prompt hence causing any buffered stdin to be ignored effectively. Another approach might be not to accept empty input (ie containing only a buffered newline).

On the other hand maybe there is a more natural library for prompt input, which allows editting? (For my actual current use-case I only need Posix/Linux support, though a portable solution would be best.)

Any thoughts?