Safe Haskell | Safe-Inferred |
---|
- progressBar :: Label -> Label -> ℤ -> ℤ -> ℤ -> IO ()
- mkProgressBar :: Label -> Label -> ℤ -> ℤ -> ℤ -> String
- type Label = ℤ -> ℤ -> String
- noLabel :: Label
- msg :: String -> Label
- percentage :: Label
- exact :: Label
- data ProgressRef
- startProgress :: Label -> Label -> ℤ -> ℤ -> IO (ProgressRef, ThreadId)
- incProgress :: ProgressRef -> ℤ -> IO ()
Progress bars
:: Label | Prefixed label. |
-> Label | Postfixed label. |
-> ℤ | Total progress bar width in characters. |
-> ℤ | Amount of work completed. |
-> ℤ | Total amount of work. |
-> IO () |
Print a progress bar
Erases the current line! (by outputting '\r') Does not print a newline '\n'. Subsequent invocations will overwrite the previous output.
Remember to set the correct buffering mode for stdout:
import System.IO ( hSetBuffering, BufferMode(NoBuffering), stdout ) hSetBuffering stdout NoBuffering
:: Label | Prefixed label. |
-> Label | Postfixed label. |
-> ℤ | Total progress bar width in characters. |
-> ℤ | Amount of work completed. |
-> ℤ | Total amount of work. |
-> String |
Renders a progress bar
>>>
mkProgressBar (msg "Working") percentage 40 30 100
"Working [=======>.................] 30%"
Labels
A label which displays the progress as a percentage.
Constant width property: ∀ d t : ℕ. d ≤ t → length (percentage d t) ≡ 4
>>>
percentage 30 100
" 30%"
A label which displays the progress as a fraction of the total amount of work.
Equal width property: ∀ d₁ d₂ t : ℕ. d₁ ≤ d₂ ≤ t → length (exact d₁ t) ≡ length (exact d₂ t)
>>>
exact 30 100
" 30/100"
auto-printing
data ProgressRef Source
:: Label | Prefixed label. |
-> Label | Postfixed label. |
-> ℤ | Total progress bar width in characters. |
-> ℤ | Total amount of work. |
-> IO (ProgressRef, ThreadId) |
Start a thread to automatically display progress. Use incProgress to step the progress bar.
incProgress :: ProgressRef -> ℤ -> IO ()Source
Increment the progress bar. Negative values will reverse the progress. Progress will never be negative and will silently stop taking data when it completes.