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

Safe HaskellNone
LanguageHaskell2010

System.Console.AsciiProgress.Internal

Synopsis

Documentation

data Options Source

The progress bar's options.

Constructors

Options 

Fields

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

Total amount of ticks expected

pgWidth :: Int

The progress bar's width

pgOnCompletion :: Maybe String

What to output when the progress bar is done. The same format placeholders used in pgFormat may be used.

pgGetProgressStr :: Options -> Stats -> String
 

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 :: Integer -> Integer -> Double -> Double Source

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

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

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"
"foobar"
>>> replaceMany [("bar", "biz")] "foobar"
"foobiz"
>>> replaceMany [("foo", "baz"), ("bar", "biz")] "foobar"
"bazbiz"

replace :: Eq a => [a] -> [a] -> [a] -> [a] Source

Replaces a subsequence by another in a sequence

Taken from http://bluebones.net/2007/01/replace-in-haskell/

>>> replace "foo" "baz" "foobar"
"bazbar"
>>> replace "some" "thing" "something something"
"thingthing thingthing"
>>> replace "not" "" "something"
"something"
>>> replace "" "here" "something"
"heresomething"

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.