| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
System.ProgressBar.State
- type ProgressBar s a = Label s -> Label s -> Integer -> s -> a
- progressBar :: HasProgress s => ProgressBar s (IO ())
- autoProgressBar :: HasProgress s => ProgressBar s (IO ())
- hProgressBar :: HasProgress s => Handle -> ProgressBar s (IO ())
- mkProgressBar :: HasProgress s => ProgressBar s String
- data Progress = Progress {
- progressDone :: !Integer
- progressTodo :: !Integer
- class HasProgress a where
- type Label s = s -> String
- noLabel :: Label s
- msg :: String -> Label s
- percentage :: HasProgress s => Label s
- exact :: HasProgress s => Label s
- data ProgressRef s
- startProgress :: HasProgress s => Label s -> Label s -> Integer -> s -> IO (ProgressRef s, Async ())
- incProgress :: ProgressRef s -> (s -> s) -> IO ()
Progress bars
type ProgressBar s a Source #
Arguments
| = Label s | Prefixed label. |
| -> Label s | 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 |
| -> s | Progress bar state. |
| -> a |
Type of functions producing a progress bar.
progressBar :: HasProgress s => ProgressBar s (IO ()) Source #
Print a progress bar to stderr
See hProgressBar.
autoProgressBar :: HasProgress s => ProgressBar s (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 :: HasProgress s => Handle -> ProgressBar s (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 :: HasProgress s => ProgressBar s String Source #
Renders a progress bar
>>>mkProgressBar (msg "Working") percentage 40 30 100"Working [=======>.................] 30%"
Progress state
State of a progress bar.
Constructors
| Progress | |
Fields
| |
Instances
class HasProgress a where Source #
Types that can represent progress.
Any progress bar state that implements this class can be used by the default label functions.
Minimal complete definition
Methods
getProgress :: a -> Progress Source #
Instances
Labels
Arguments
| = s | Current progress bar state. |
| -> String | Resulting label. |
A label that can be pre- or postfixed to a progress bar.
percentage :: HasProgress s => Label s 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%.
exact :: HasProgress s => Label s Source #
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 s Source #
Arguments
| :: HasProgress s | |
| => Label s | Prefixed label. |
| -> Label s | Postfixed label. |
| -> Integer | Total progress bar width in characters. |
| -> s | Init state |
| -> IO (ProgressRef s, Async ()) |
Start a thread to automatically display progress. Use incProgress to step the progress bar.
incProgress :: ProgressRef s -> (s -> s) -> 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.