packages feed

bytestring-progress 1.2 → 1.4

raw patch · 2 files changed

+31/−18 lines, 2 filesdep +textdep ~terminal-progress-barPVP ok

version bump matches the API change (PVP)

Dependencies added: text

Dependency ranges changed: terminal-progress-bar

API changes (from Hackage documentation)

- System.ProgressBar.ByteString: fileReadProgressBar :: FilePath -> (String -> IO ()) -> ℤ -> Label -> Label -> IO ByteString
+ System.ProgressBar.ByteString: fileReadProgressBar :: FilePath -> (Text -> IO ()) -> ℤ -> Label () -> Label () -> IO ByteString
- System.ProgressBar.ByteString: fileReadProgressWriter :: FilePath -> Handle -> ℤ -> Label -> Label -> IO ByteString
+ System.ProgressBar.ByteString: fileReadProgressWriter :: FilePath -> Handle -> ℤ -> Label () -> Label () -> IO ByteString
- System.ProgressBar.ByteString: mkByteStringProgressBar :: ByteString -> (String -> IO ()) -> ℤ -> ℤ -> Label -> Label -> IO ByteString
+ System.ProgressBar.ByteString: mkByteStringProgressBar :: ByteString -> (Text -> IO ()) -> ℤ -> ℤ -> Label () -> Label () -> IO ByteString
- System.ProgressBar.ByteString: mkByteStringProgressWriter :: ByteString -> Handle -> ℤ -> ℤ -> Label -> Label -> IO ByteString
+ System.ProgressBar.ByteString: mkByteStringProgressWriter :: ByteString -> Handle -> ℤ -> ℤ -> Label () -> Label () -> IO ByteString

Files

System/ProgressBar/ByteString.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE OverloadedStrings #-} module System.ProgressBar.ByteString(          mkByteStringProgressBar        , mkByteStringProgressWriter@@ -8,9 +9,14 @@  import Data.ByteString.Lazy(ByteString,hGetContents) import Data.ByteString.Lazy.Progress+import Data.Text.Lazy(Text)+import qualified Data.Text.Lazy.IO as T+import Data.Time.Clock(getCurrentTime) import System.IO(Handle,hSetBuffering,hPutChar,hPutStr,BufferMode(..)) import System.IO(openFile,hFileSize,IOMode(..))-import System.ProgressBar(Label, Progress(Progress), mkProgressBar)+import System.ProgressBar(Label, Progress(Progress), ProgressBarWidth(..),+                          Style(..), Timing(..))+import System.ProgressBar(defStyle, renderProgressBar)  type ℤ = Integer @@ -19,21 +25,27 @@ -- string and pass it to the given function. See other functions for interacting -- with fixed-size files, the console, or generic Handles. mkByteStringProgressBar :: ByteString {- The ByteString to track. -} ->-                           (String -> IO ()) {- ^Function to call on update.-}->+                           (Text -> IO ()) {- ^Function to call on update.-}->                            ℤ     {- ^ Progress bar width -}         ->                            ℤ     {- ^ The size of the ByteString -} ->-                           Label {- ^ Prefixed label -}             ->-                           Label {- ^ Postfixed label -}            ->+                           Label () {- ^ Prefixed label -}           ->+                           Label () {- ^ Postfixed label -}          ->                            IO ByteString mkByteStringProgressBar input tracker width size prefix postfix =-  trackProgressWithChunkSize bestSize updateFunction input+  do start <- getCurrentTime+     trackProgressWithChunkSize bestSize (updateFunction start) input  where+  style = defStyle{ stylePrefix  = prefix+                  , stylePostfix = postfix+                  , styleWidth   = ConstantWidth (fromIntegral width) }   bestSize | size `div` 100 < 4096  = fromIntegral $ size `div` 100            | size `div` 100 < 16384 = 4096            | otherwise              = 16384-  updateProgressBar                 = mkProgressBar prefix postfix width-  updateFunction _ now              =-    tracker $ updateProgressBar (Progress (fromIntegral now) size)+  updateFunction start _ newAmt           =+    do now <- getCurrentTime+       let progress = Progress (fromIntegral newAmt) (fromIntegral size) ()+           timing = Timing start now+       tracker $ renderProgressBar style progress timing  -- |As mkByteStringProgressBar, but simply print the output to the given -- Handle instead of using a callback.@@ -41,23 +53,23 @@                               Handle {- ^ Handle to write to -} ->                               ℤ {- ^ Progress bar width -} ->                               ℤ {- ^ The size of the ByteString -} ->-                              Label {- ^ Prefixed label -} ->-                              Label {- ^ Postfixed label -} ->+                              Label () {- ^ Prefixed label -} ->+                              Label () {- ^ Postfixed label -} ->                               IO ByteString mkByteStringProgressWriter input handle width size prefix postfix = do   hSetBuffering handle NoBuffering   mkByteStringProgressBar input tracker width size prefix postfix  where-  tracker str = hPutChar handle '\r' >> hPutStr handle str+  tracker str = T.hPutStr handle "\r" >> T.hPutStr handle str  -- |Track the loading of a file as it is consumed by some computation. The -- use of this function should be essentially similar to ByteString's -- readFile, but with a lot more arguments and side effects. fileReadProgressBar :: FilePath {- ^ The file to load. -} ->-                       (String -> IO ()) {- ^ Function to call on update. -} ->+                       (Text -> IO ()) {- ^ Function to call on update. -} ->                        ℤ {- ^ Progress bar width -} ->-                       Label {- ^ Prefixed label -} ->-                       Label {- ^ Postfixed label -} ->+                       Label () {- ^ Prefixed label -} ->+                       Label () {- ^ Postfixed label -} ->                        IO ByteString fileReadProgressBar path tracker width prefix postfix = do   inHandle   <- openFile path ReadMode@@ -70,8 +82,8 @@ fileReadProgressWriter :: FilePath {- ^ The file to load. -} ->                           Handle {- ^ Handle to write to -} ->                           ℤ {- ^ Progress bar width -} ->-                          Label {- ^ Prefixed label -} ->-                          Label {- ^ Postfixed label -} ->+                          Label () {- ^ Prefixed label -} ->+                          Label () {- ^ Postfixed label -} ->                           IO ByteString fileReadProgressWriter path handle width prefix postfix = do   inHandle   <- openFile path ReadMode
bytestring-progress.cabal view
@@ -1,5 +1,5 @@ Name: bytestring-progress-Version: 1.2+Version: 1.4 Build-Type: Simple Cabal-Version: >= 1.6 License: BSD3@@ -29,7 +29,8 @@   Exposed-Modules: Data.ByteString.Lazy.Progress    if flag(use-system-progressbar)-    Build-Depends: terminal-progress-bar >= 0.2 && < 0.3+    Build-Depends: terminal-progress-bar >= 0.4 && < 0.5,+                   text >= 1.2.3.1 && < 1.3     Exposed-Modules: System.ProgressBar.ByteString