Updating outputted text in haskeline
Asked Answered
C

1

9

Haskeline provides the functions outputStr and outputStrLn, which output to stdout, but is there a way to update text that's already been outputted? I'm thinking of, for example, when an installer displays the current percentage installed -- the percentage number updates.

Am I going to need to use a curses binding?

Caseose answered 5/9, 2012 at 0:15 Comment(0)
O
9
delete n = putStr (replicate n '\b')

This is (essentially) how QuickCheck does it and it works reasonably well. I use it in my own code for progress indicators and it gives me good results. Something more sophisticated will requires a curses binding (or equivalent).

Oaken answered 5/9, 2012 at 0:27 Comment(3)
I was really amused and happy by how simple this solution is, but it's not working for me, either with haskeline or with basic putStrCaseose
Oops, I take it back! It only doesn't delete past a newline. Thanks for such a clean solution!Caseose
You might also like putChar '\r'.Swagger

© 2022 - 2024 — McMap. All rights reserved.