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

Safe HaskellNone
LanguageHaskell2010

System.Console.AsciiProgress

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

Represents a point in time for the progress bar.

isComplete :: ProgressBar -> IO Bool Source

Returns if the progress bar rendering thread has exited (it has done enough ticks)

newProgressBar :: Options -> IO ProgressBar Source

Creates a new progress bar with the given Options. Multiple progress bars may be created. This package depends on `concurrent-output`, so it's -- necessary that progress-bar usage is wrapped with a call to displayConsoleRegions.

import           Control.Concurrent           (threadDelay)
import           Control.Monad                (unless)
import           System.Console.AsciiProgress

main :: IO ()
main = displayConsoleRegions $ do
   pg <- newProgressBar def { pgWidth = 100
                            , pgOnCompletion = Just "Done :percent after :elapsed seconds"
                            }
   loop pg
 where
   loop pg = do
       b <- isComplete pg
       unless b $ do
           threadDelay $ 200 * 1000
           tick pg
           loop pg

complete :: ProgressBar -> IO () Source

Forces a ProgressBar to finish

tick :: ProgressBar -> IO () Source

Tick the progress bar

tickN :: ProgressBar -> Int -> IO () Source

Tick the progress bar N times

tickNI :: ProgressBar -> Integer -> IO () Source

Tick the progress bar N times

getProgressStrIO :: ProgressBar -> IO String Source

Like getProgressStr but works on the ProgressBar object and uses the IO monad.

getProgressStats :: ProgressBar -> IO Stats Source

Gets the progress bar current Stats 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.

class Default a where

A class for types with a default value.

Methods

def :: a

The default value for this type.

Instances