ascii-progress 0.3.0.1 → 0.3.1.0
raw patch · 3 files changed
+41/−31 lines, 3 filesdep ~timePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: time
API changes (from Hackage documentation)
+ System.Console.AsciiProgress: [pgGetProgressStr] :: Options -> Options -> Stats -> String
+ System.Console.AsciiProgress: [pgRegion] :: ProgressBar -> ConsoleRegion
+ System.Console.AsciiProgress: tickNI :: ProgressBar -> Integer -> IO ()
+ System.Console.AsciiProgress.Internal: [pgGetProgressStr] :: Options -> Options -> Stats -> String
- System.Console.AsciiProgress: Options :: String -> Char -> Char -> Int -> Int -> Maybe String -> Options
+ System.Console.AsciiProgress: Options :: String -> Char -> Char -> Integer -> Int -> Maybe String -> (Options -> Stats -> String) -> Options
- System.Console.AsciiProgress: ProgressBar :: ProgressBarInfo -> Async () -> ProgressBar
+ System.Console.AsciiProgress: ProgressBar :: ProgressBarInfo -> Async () -> ConsoleRegion -> ProgressBar
- System.Console.AsciiProgress: Stats :: Int -> Int -> Int -> Double -> Double -> Double -> Stats
+ System.Console.AsciiProgress: Stats :: Integer -> Integer -> Integer -> Double -> Double -> Double -> Stats
- System.Console.AsciiProgress: [pgTotal] :: Options -> Int
+ System.Console.AsciiProgress: [pgTotal] :: Options -> Integer
- System.Console.AsciiProgress: [stCompleted] :: Stats -> Int
+ System.Console.AsciiProgress: [stCompleted] :: Stats -> Integer
- System.Console.AsciiProgress: [stRemaining] :: Stats -> Int
+ System.Console.AsciiProgress: [stRemaining] :: Stats -> Integer
- System.Console.AsciiProgress: [stTotal] :: Stats -> Int
+ System.Console.AsciiProgress: [stTotal] :: Stats -> Integer
- System.Console.AsciiProgress.Internal: Options :: String -> Char -> Char -> Int -> Int -> Maybe String -> Options
+ System.Console.AsciiProgress.Internal: Options :: String -> Char -> Char -> Integer -> Int -> Maybe String -> (Options -> Stats -> String) -> Options
- System.Console.AsciiProgress.Internal: ProgressBarInfo :: Options -> Chan Int -> MVar Int -> MVar UTCTime -> ProgressBarInfo
+ System.Console.AsciiProgress.Internal: ProgressBarInfo :: Options -> Chan Integer -> MVar Integer -> MVar UTCTime -> ProgressBarInfo
- System.Console.AsciiProgress.Internal: Stats :: Int -> Int -> Int -> Double -> Double -> Double -> Stats
+ System.Console.AsciiProgress.Internal: Stats :: Integer -> Integer -> Integer -> Double -> Double -> Double -> Stats
- System.Console.AsciiProgress.Internal: [pgChannel] :: ProgressBarInfo -> Chan Int
+ System.Console.AsciiProgress.Internal: [pgChannel] :: ProgressBarInfo -> Chan Integer
- System.Console.AsciiProgress.Internal: [pgCompleted] :: ProgressBarInfo -> MVar Int
+ System.Console.AsciiProgress.Internal: [pgCompleted] :: ProgressBarInfo -> MVar Integer
- System.Console.AsciiProgress.Internal: [pgTotal] :: Options -> Int
+ System.Console.AsciiProgress.Internal: [pgTotal] :: Options -> Integer
- System.Console.AsciiProgress.Internal: [stCompleted] :: Stats -> Int
+ System.Console.AsciiProgress.Internal: [stCompleted] :: Stats -> Integer
- System.Console.AsciiProgress.Internal: [stRemaining] :: Stats -> Int
+ System.Console.AsciiProgress.Internal: [stRemaining] :: Stats -> Integer
- System.Console.AsciiProgress.Internal: [stTotal] :: Stats -> Int
+ System.Console.AsciiProgress.Internal: [stTotal] :: Stats -> Integer
- System.Console.AsciiProgress.Internal: getEta :: Int -> Int -> Double -> Double
+ System.Console.AsciiProgress.Internal: getEta :: Integer -> Integer -> Double -> Double
Files
- ascii-progress.cabal +7/−7
- lib/System/Console/AsciiProgress.hs +18/−11
- lib/System/Console/AsciiProgress/Internal.hs +16/−13
ascii-progress.cabal view
@@ -1,5 +1,5 @@ name: ascii-progress-version: 0.3.0.1+version: 0.3.1.0 synopsis: A simple progress bar for the console. description: A simple Haskell progress bar for the console. Heavily borrows from TJ@@ -32,7 +32,7 @@ , async >= 2.0.1.5 , base >=4 && <5 , data-default >= 0.5.3- , time >= 1.4.2+ , time >= 1.4.0.1 hs-source-dirs: lib default-language: Haskell2010 @@ -48,7 +48,7 @@ , async >= 2.0.1.5 , base >=4 && <5 , data-default >= 0.5.3- , time >= 1.4.2+ , time >= 1.4.0.1 hs-source-dirs: lib , bin @@ -66,7 +66,7 @@ , base >=4 && <5 , bytestring , data-default >= 0.5.3- , time >= 1.4.2+ , time >= 1.4.0.1 , conduit >= 1.2 , http-conduit >= 2.1 , http-types >= 0.8@@ -86,7 +86,7 @@ , async >= 2.0.1.5 , base >=4 && <5 , data-default >= 0.5.3- , time >= 1.4.2+ , time >= 1.4.0.1 hs-source-dirs: lib , bin @@ -103,7 +103,7 @@ , base >=4 && <5 , data-default >= 0.5.3 , random- , time >= 1.4.2+ , time >= 1.4.0.1 hs-source-dirs: lib , bin @@ -115,7 +115,7 @@ , base >=4 && <5 , data-default >= 0.5.3 , hspec >=2.1 && <3- , time >= 1.4.2+ , time >= 1.4.0.1 , QuickCheck >= 2.6 hs-source-dirs: lib , test
lib/System/Console/AsciiProgress.hs view
@@ -8,6 +8,7 @@ , complete , tick , tickN+ , tickNI , getProgressStrIO , getProgressStats , getProgressStr@@ -29,6 +30,7 @@ data ProgressBar = ProgressBar { pgInfo :: ProgressBarInfo , pgFuture :: Async ()+ , pgRegion :: ConsoleRegion } -- |@@ -42,7 +44,7 @@ -- > import System.Console.AsciiProgress -- > -- > main :: IO ()--- > main = do+-- > main = displayConsoleRegions $ do -- > pg <- newProgressBar def { pgWidth = 100 -- > , pgOnCompletion = Just "Done :percent after :elapsed seconds" -- > }@@ -60,11 +62,11 @@ info <- newProgressBarInfo opts -- Display initial progress-bar- pgStr <- getProgressStr opts <$> getInfoStats info+ pgStr <- pgGetProgressStr opts opts <$> getInfoStats info setConsoleRegion region pgStr future <- async $ start info region- return $ ProgressBar info future+ return $ ProgressBar info future region where start info@ProgressBarInfo{..} region = do c <- readMVar pgCompleted@@ -76,7 +78,7 @@ unlessDone c action | c < pgTotal opts = action unlessDone _ _ = do let fmt = fromMaybe (pgFormat opts) (pgOnCompletion opts)- onCompletion <- getProgressStr opts { pgFormat = fmt } <$> getInfoStats info+ onCompletion <- pgGetProgressStr opts opts { pgFormat = fmt } <$> getInfoStats info setConsoleRegion region onCompletion handleMessage info region n = do@@ -84,7 +86,7 @@ modifyMVar_ (pgCompleted info) (\c -> return (c + n)) -- Find and update the current and first tick times: stats <- getInfoStats info- let progressStr = getProgressStr opts stats+ let progressStr = pgGetProgressStr opts opts stats setConsoleRegion region progressStr -- |@@ -95,30 +97,35 @@ -- | -- Tick the progress bar N times tickN :: ProgressBar -> Int -> IO ()-tickN (ProgressBar info _) = writeChan (pgChannel info)+tickN (ProgressBar info _ _) = writeChan (pgChannel info) . fromIntegral -- |+-- Tick the progress bar N times+tickNI :: ProgressBar -> Integer -> IO ()+tickNI (ProgressBar info _ _) = writeChan (pgChannel info)++-- | -- Returns if the progress bar rendering thread has exited (it has done enough -- ticks) isComplete :: ProgressBar -> IO Bool-isComplete (ProgressBar _ future) = isJust <$> poll future+isComplete (ProgressBar _ future _) = isJust <$> poll future -- | -- Forces a 'ProgressBar' to finish complete :: ProgressBar -> IO ()-complete pg@(ProgressBar info future) = do+complete pg@(ProgressBar info future _) = do let total = pgTotal (pgOptions info)- tickN pg total+ tickNI pg total wait future -- | -- Gets the progress bar current @Stats @object getProgressStats :: ProgressBar -> IO Stats-getProgressStats (ProgressBar info _) = getInfoStats info+getProgressStats (ProgressBar info _ _) = getInfoStats info -- | -- Like @getProgressStr@ but works on the @ProgressBar@ object and uses the IO -- monad. getProgressStrIO :: ProgressBar -> IO String-getProgressStrIO (ProgressBar info _) =+getProgressStrIO (ProgressBar info _ _) = getProgressStr (pgOptions info) <$> getInfoStats info
lib/System/Console/AsciiProgress/Internal.hs view
@@ -14,7 +14,7 @@ -- | -- The progress bar's options.-data Options = Options { pgFormat :: String+data Options = Options { pgFormat :: String -- ^ A format string for the progress bar. Currently the -- following format strings are supported: -- - ":eta" (ETA displayed in seconds)@@ -23,17 +23,19 @@ -- - ":percent" (percentage completed) -- - ":elapsed" (elapsed time in seconds) -- - ":bar" (the actual progress bar)- , pgCompletedChar :: Char+ , pgCompletedChar :: Char -- ^ Character to be used on the completed part of the -- bar- , pgPendingChar :: Char+ , pgPendingChar :: Char -- ^ Character to be used on the pending part of the bar- , pgTotal :: Int+ , pgTotal :: Integer -- ^ Total amount of ticks expected- , pgWidth :: Int+ , pgWidth :: Int -- ^ The progress bar's width- , pgOnCompletion :: Maybe String- -- ^ What to output when the progress bar is done+ , 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 } instance Default Options where@@ -44,22 +46,23 @@ , pgTotal = 20 , pgWidth = 80 , pgOnCompletion = Nothing+ , pgGetProgressStr = getProgressStr } -- | -- The progress bar's state object. Contains all but the printing thread's -- @Async@ object. data ProgressBarInfo = ProgressBarInfo { pgOptions :: Options- , pgChannel :: Chan Int- , pgCompleted :: MVar Int+ , pgChannel :: Chan Integer+ , pgCompleted :: MVar Integer , pgFirstTick :: MVar UTCTime } -- | -- Represents a point in time for the progress bar.-data Stats = Stats { stTotal :: Int- , stCompleted :: Int- , stRemaining :: Int+data Stats = Stats { stTotal :: Integer+ , stCompleted :: Integer+ , stRemaining :: Integer , stElapsed :: Double , stPercent :: Double , stEta :: Double@@ -131,7 +134,7 @@ -- 10.0 -- >>> getEta 30 70 23.3 -- 54.366666666666674-getEta :: Int -> Int -> Double -> Double+getEta :: Integer -> Integer -> Double -> Double getEta 0 _ _ = 0 getEta completed remaining elapsed = averageSecsPerTick * fromIntegral remaining where