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

Safe HaskellSafe-Inferred

System.ProgressBar

Contents

Synopsis

Progress bars

progressBarSource

Arguments

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

mkProgressBarSource

Arguments

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

type Label = -> -> StringSource

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

noLabel :: LabelSource

The empty label.

>>> noLabel 30 100
""

msg :: String -> LabelSource

A label consisting of a static string.

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

percentage :: LabelSource

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

exact :: LabelSource

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

startProgressSource

Arguments

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