on 6a96e21 help sign in
43 lines 654 B history raw
1{-# OPTIONS_GHC -Wall #-}
2module Reporting.Progress.Bar
3 ( render
4 , clear
5 )
6 where
10-- PROGRESS BAR
13width :: Float
14width =
15 50.0
18render :: Int -> Int -> Int -> String
19render successes failures total =
20 let
21 numDone =
22 successes + failures
24 fraction =
25 fromIntegral numDone / fromIntegral total
27 unitsDone =
28 truncate (fraction * width)
30 unitsLeft =
31 truncate width - unitsDone
32 in
33 "\r["
34 ++ replicate unitsDone '='
35 ++ replicate unitsLeft ' '
36 ++ "] - "
37 ++ show numDone ++ " / " ++ show total
40clear :: String
41clear =
42 '\r' : replicate (length (render 49999 50000 99999)) ' ' ++ "\r"