-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | A simple progress bar in the terminal
--   
--   A progress bar is used to convey the progress of a task. This package
--   implements a very simple textual progress bar.
--   
--   See the module <a>System.ProgressBar</a> on how to use the progress
--   bar or build the package with the -fexample flag for a small example
--   program.
--   
--   The animated progress bar depends entirely on the interpretation of
--   the carriage return character ('\r'). If your terminal interprets it
--   as something else than "move cursor to beginning of line", the
--   animation won't work.
@package terminal-progress-bar
@version 0.2

module System.ProgressBar.State

-- | Type of functions producing a progress bar.
type ProgressBar s a = 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

-- | Print a progress bar to <a>stderr</a>
--   
--   See <a>hProgressBar</a>.
progressBar :: (HasProgress s) => ProgressBar s (IO ())

-- | Print a progress bar to <a>stderr</a> which takes up all available
--   space.
--   
--   The given width will be used if the width of the terminal can not be
--   determined.
--   
--   See <a>hProgressBar</a>.
autoProgressBar :: (HasProgress s) => ProgressBar s (IO ())

-- | 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.
hProgressBar :: HasProgress s => Handle -> ProgressBar s (IO ())

-- | Renders a progress bar
--   
--   <pre>
--   &gt;&gt;&gt; mkProgressBar (msg "Working") percentage 40 30 100
--   "Working [=======&gt;.................]  30%"
--   </pre>
mkProgressBar :: (HasProgress s) => ProgressBar s String

-- | State of a progress bar.
data Progress
Progress :: !Integer -> !Integer -> Progress

-- | Amount of work completed.
[progressDone] :: Progress -> !Integer

-- | Total amount of work.
[progressTodo] :: Progress -> !Integer

-- | Types that can represent progress.
--   
--   Any progress bar state that implements this class can be used by the
--   default label functions.
class HasProgress a
getProgress :: HasProgress a => a -> Progress

-- | A label that can be pre- or postfixed to a progress bar.
type Label s = s  Current progress bar state. -> String  Resulting label.

-- | The empty label.
--   
--   <pre>
--   &gt;&gt;&gt; noLabel st
--   ""
--   </pre>
noLabel :: Label s

-- | A label consisting of a static string.
--   
--   <pre>
--   &gt;&gt;&gt; msg "foo" st
--   "foo"
--   </pre>
msg :: String -> Label s

-- | A label which displays the progress as a percentage.
--   
--   Constant width property: ∀ d t : ℕ. d ≤ t → length (percentage d t) ≡
--   4
--   
--   <pre>
--   &gt;&gt;&gt; percentage 30 100
--   " 30%"
--   </pre>
--   
--   <b>Note</b>: if no work is to be done (todo == 0) the percentage will
--   always be 100%.
percentage :: HasProgress s => Label s

-- | 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)
--   
--   <pre>
--   &gt;&gt;&gt; exact (30, 100)
--   " 30/100"
--   </pre>
exact :: HasProgress s => Label s
data ProgressRef s

-- | Start a thread to automatically display progress. Use incProgress to
--   step the progress bar.
startProgress :: (HasProgress s) => Label s -> Label s -> Integer -> s -> IO (ProgressRef s, Async ())

-- | Increment the progress bar. Negative values will reverse the progress.
--   Progress will never be negative and will silently stop taking data
--   when it completes.
incProgress :: ProgressRef s -> (s -> s) -> IO ()
instance System.ProgressBar.State.HasProgress System.ProgressBar.State.Progress

module System.ProgressBar

-- | Type of functions producing a progress bar.
type ProgressBar a = 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

-- | Print a progress bar to <a>stderr</a>
--   
--   See <a>hProgressBar</a>.
progressBar :: ProgressBar (IO ())

-- | Print a progress bar to <a>stderr</a> which takes up all available
--   space.
--   
--   The given width will be used if the width of the terminal can not be
--   determined.
--   
--   See <a>hProgressBar</a>.
autoProgressBar :: ProgressBar (IO ())

-- | 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.
hProgressBar :: Handle -> ProgressBar (IO ())

-- | Renders a progress bar
--   
--   <pre>
--   &gt;&gt;&gt; mkProgressBar (msg "Working") percentage 40 30 100
--   "Working [=======&gt;.................]  30%"
--   </pre>
mkProgressBar :: ProgressBar String

-- | State of a progress bar.
data Progress
Progress :: !Integer -> !Integer -> Progress

-- | Amount of work completed.
[progressDone] :: Progress -> !Integer

-- | Total amount of work.
[progressTodo] :: Progress -> !Integer

-- | A label that can be pre- or postfixed to a progress bar.
type Label = Progress  Current progress. -> String  Resulting label.

-- | The empty label.
--   
--   <pre>
--   &gt;&gt;&gt; noLabel 30 100
--   ""
--   </pre>
noLabel :: Label

-- | A label consisting of a static string.
--   
--   <pre>
--   &gt;&gt;&gt; msg "foo" 30 100
--   "foo"
--   </pre>
msg :: String -> Label

-- | A label which displays the progress as a percentage.
--   
--   Constant width property: ∀ d t : ℕ. d ≤ t → length (percentage d t) ≡
--   4
--   
--   <pre>
--   &gt;&gt;&gt; percentage 30 100
--   " 30%"
--   </pre>
--   
--   <b>Note</b>: if no work is to be done (todo == 0) the percentage will
--   always be 100%.
percentage :: Label

-- | 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)
--   
--   <pre>
--   &gt;&gt;&gt; exact 30 100
--   " 30/100"
--   </pre>
exact :: Label
type ProgressRef = ProgressRef Progress

-- | Start a thread to automatically display progress. Use incProgress to
--   step the progress bar.
startProgress :: Label -> Label -> Integer -> Progress -> IO (ProgressRef, Async ())

-- | Increment the progress bar. Negative values will reverse the progress.
--   Progress will never be negative and will silently stop taking data
--   when it completes.
incProgress :: ProgressRef -> Integer -> IO ()
