ascii-progress- A simple progress bar for the console.

Safe HaskellNone




data Options Source

The progress bar's options.




pgFormat :: String

A format string for the progress bar. Currently the following format strings are supported: - ":eta" (ETA displayed in seconds) - ":current" (current tick) - ":total" (total number of ticks) - ":percent" (percentage completed) - ":elapsed" (elapsed time in seconds) - ":bar" (the actual progress bar)

pgCompletedChar :: Char

Character to be used on the completed part of the bar

pgPendingChar :: Char

Character to be used on the pending part of the bar

pgTotal :: Int

Total amount of ticks expected

pgWidth :: Int

The progress bar's width

data ProgressBarInfo Source

The progress bar's state object. Contains all but the printing thread's Async object.


data Stats Source

Represents a point in time for the progress bar.



newProgressBarInfo :: Options -> IO ProgressBarInfo Source

Creates a new empty progress bar info object.

getProgressStr :: Options -> Stats -> String Source

Gets the string to be printed given the options object and a certain stats object representing the rendering moment.

getInfoStats :: ProgressBarInfo -> IO Stats Source

Creates a stats object for a given ProgressBarInfo node. This is the core logic, isolated, and may be used to make the same analysis code to be used by different progress renderers.

getBar :: Char -> Char -> Int -> Double -> String Source

Generates the actual progress bar string, with its completed/pending characters, width and a completeness percentage.

getElapsed :: UTCTime -> UTCTime -> Double Source

Gets the amount of seconds elapsed between two UTCTimes as a double.

getEta :: Int -> Int -> Double -> Double Source

Gets the ETA, given the elapsed time and the amount of completed and remaining ticks.

>>> getEta 50 50 10.0
>>> getEta 30 70 23.3

replaceMany :: Eq a => [([a], [a])] -> [a] -> [a] Source

Replaces each pair in a list of replacement pairs in a list with replace. The idea is to call ((old, new) target -> replace old new target) on each of the pairs, accumulating the resulting modified list.

>>> replaceMany [] "foobar"
>>> replaceMany [("bar", "biz")] "foobar"
>>> replaceMany [("foo", "baz"), ("bar", "biz")] "foobar"

forceReadMVar :: MVar a -> a -> IO a Source

Forces an MVar's contents to be read or swaped by a default value, even if it's currently empty. Will discard the default value write to the MVar if it becomes full in the middle of the operation and return its value. It's assumed that once the MVar becomes full, it won't ever be left emptied. This code may deadlock if that's the case.