I have simple command line interface with insertion records in DB and now it writes a lot of info to stdout, like this:
...
record 856/1000: 85%
record 857/1000: 85%
record 858/1000: 85%
...
but I want to have 1 dynamic line with updating current string parameters
status |T | C | A | E
---------------------------------------
inserting |1000 | 857 | 85% | 96
How can I achieve that?
If it's just one row, you can use \r
to rewind the cursor to the beginning of the line.
Here's an example:
import Control.Concurrent
import Control.Monad
import Text.Printf
main :: IO ()
main = do
forM_ [10, 9 .. 1] $ \seconds -> do
printf "\rLaunching missiles in %2d..." (seconds :: Int)
threadDelay $ 1 * 1000 * 1000
putStrLn "\nBlastoff!"
Joey Hess's concurrent-output
library is designed for progress output like this (and more complex variations).
http://hackage.haskell.org/package/concurrent-output
https://joeyh.name/blog/entry/a_tiling_region_manager_for_the_console/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With