Haskell 中的动态标准输出

Dynamic stdout in Haskell

我有一个简单的命令行界面,在数据库中插入记录,并且 现在它向 stdout 写入大量信息,如下所示:

...    
record 856/1000: 85%
record 857/1000: 85%
record 858/1000: 85%
...

但我想要 1 个更新当前字符串参数的动态行

 status         |T    | C   | A   | E
 ---------------------------------------
   inserting    |1000 | 857 | 85% | 96  

我怎样才能做到这一点?

如果只有一行,您可以使用\r将光标后退到行首。

这是一个例子:

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 的 concurrent-output 库专为这样的进度输出(以及更复杂的变体)而设计。

http://hackage.haskell.org/package/concurrent-output

https://joeyh.name/blog/entry/a_tiling_region_manager_for_the_console/