terminal-progress-bar-0.2: A simple progress bar in the terminal

Safe HaskellSafe
LanguageHaskell2010

System.ProgressBar

Contents

Synopsis

Progress bars

type ProgressBar a Source #

Arguments

 = 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 autoProgressBar.

-> 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

data Progress Source #

State of a progress bar.

Constructors

Progress 

Fields

Labels

type Label Source #

Arguments

 = Progress

Current progress.

-> String

Resulting label.

A label that can be pre- or postfixed to a progress bar.

noLabel :: Label Source #

The empty label.

>>> noLabel 30 100
""

msg :: String -> Label Source #

A label consisting of a static string.

>>> msg "foo" 30 100
"foo"

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%.

exact :: Label 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

startProgress Source #

Arguments

:: 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.