Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
- type ProgressBar a = Label -> Label -> Integer -> Progress -> a
- progressBar :: ProgressBar (IO ())
- autoProgressBar :: ProgressBar (IO ())
- hProgressBar :: Handle -> ProgressBar (IO ())
- mkProgressBar :: ProgressBar String
- data Progress = Progress {
- progressDone :: !Integer
- progressTodo :: !Integer
- type Label = Progress -> String
- noLabel :: Label
- msg :: String -> Label
- percentage :: Label
- exact :: Label
- type ProgressRef = ProgressRef Progress
- startProgress :: Label -> Label -> Integer -> Progress -> IO (ProgressRef, Async ())
- incProgress :: ProgressRef -> Integer -> IO ()
Progress bars
type ProgressBar a Source #
= Label | Prefixed label. |
-> Label | Postfixed label. |
-> Integer | Total progress bar width in characters. Either used as given or as a default when the width of the terminal can not be determined. See |
-> Progress | Current progress. |
-> a |
Type of functions producing a progress bar.
progressBar :: ProgressBar (IO ()) Source #
Print a progress bar to stderr
See hProgressBar
.
autoProgressBar :: ProgressBar (IO ()) Source #
Print a progress bar to stderr
which takes up all available space.
The given width will be used if the width of the terminal can not be determined.
See hProgressBar
.
hProgressBar :: Handle -> ProgressBar (IO ()) Source #
Print a progress bar to a file handle.
Erases the current line! (by outputting '\r') Does not print a newline '\n'. Subsequent invocations will overwrite the previous output.
mkProgressBar :: ProgressBar String Source #
Renders a progress bar
>>>
mkProgressBar (msg "Working") percentage 40 30 100
"Working [=======>.................] 30%"
Progress state
State of a progress bar.
Progress | |
|
Labels
A label that can be pre- or postfixed to a progress bar.
percentage :: Label Source #
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%"
Note: if no work is to be done (todo == 0) the percentage will always be 100%.
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
type ProgressRef = ProgressRef Progress Source #
:: Label | Prefixed label. |
-> Label | Postfixed label. |
-> Integer | Total progress bar width in characters. Only used if the width can not be automatically determined. |
-> Progress | Initial progress state. |
-> IO (ProgressRef, Async ()) |
Start a thread to automatically display progress. Use incProgress to step the progress bar.
incProgress :: ProgressRef -> Integer -> 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.