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

Safe HaskellSafe
LanguageHaskell2010

System.ProgressBar.State

Contents

Synopsis

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

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

data Progress Source #

State of a progress bar.

Constructors

Progress 

Fields

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

getProgress

Methods

getProgress :: a -> Progress Source #

Labels

type Label s Source #

Arguments

 = s

Current progress bar state.

-> String

Resulting label.

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

noLabel :: Label s Source #

The empty label.

>>> noLabel st
""

msg :: String -> Label s Source #

A label consisting of a static string.

>>> msg "foo" st
"foo"

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

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