WIP use ascii-progress

A bit flickery due to
https://github.com/yamadapc/haskell-ascii-progress/issues/12

And, won't handle large files until ascii-progress is changed to use
Integers.
This commit is contained in:
Joey Hess 2015-04-04 15:58:38 -04:00
parent 30aa902174
commit a06f9ff329
2 changed files with 29 additions and 13 deletions

View file

@ -15,9 +15,8 @@ import Types
import Types.Messages import Types.Messages
import Types.Key import Types.Key
import Data.Progress.Meter import System.Console.AsciiProgress
import Data.Progress.Tracker import Control.Concurrent
import Data.Quantity
{- Shows a progress meter while performing a transfer of a key. {- Shows a progress meter while performing a transfer of a key.
- The action is passed a callback to use to update the meter. -} - The action is passed a callback to use to update the meter. -}
@ -32,17 +31,33 @@ metered combinemeterupdate key a = go (keySize key)
meteredBytes :: Maybe MeterUpdate -> Integer -> (MeterUpdate -> Annex a) -> Annex a meteredBytes :: Maybe MeterUpdate -> Integer -> (MeterUpdate -> Annex a) -> Annex a
meteredBytes combinemeterupdate size a = withOutputType go meteredBytes combinemeterupdate size a = withOutputType go
where where
go NormalOutput = do go QuietOutput = nometer
progress <- liftIO $ newProgress "" size go JSONOutput = nometer
meter <- liftIO $ newMeter progress "B" 25 (renderNums binaryOpts 1) go _ = do
showOutput showOutput
r <- a $ \n -> liftIO $ do liftIO $ putStrLn ""
setP progress $ fromBytesProcessed n pg <- liftIO $ newProgressBar def
displayMeter stdout meter { pgWidth = 79
maybe noop (\m -> m n) combinemeterupdate , pgFormat = ":percent :bar ETA :eta"
liftIO $ clearMeter stdout meter , pgTotal = fromInteger size
}
r <- a $ liftIO . pupdate pg
-- may not be actually complete if the action failed,
-- but this just clears the progress bar
liftIO $ complete pg
return r return r
go _ = a (const noop)
pupdate pg n = do
let i = fromBytesProcessed n
sofar <- stCompleted <$> getProgressStats pg
when (i > sofar) $
tickN pg (i - sofar)
threadDelay 100
maybe noop (\m -> m n) combinemeterupdate
nometer = a (const noop)
{- Progress dots. -} {- Progress dots. -}
showProgressDots :: Annex () showProgressDots :: Annex ()

View file

@ -112,7 +112,8 @@ Executable git-annex
data-default, case-insensitive, http-conduit, http-types, data-default, case-insensitive, http-conduit, http-types,
cryptohash (>= 0.10.0), cryptohash (>= 0.10.0),
esqueleto, persistent-sqlite, persistent, persistent-template, esqueleto, persistent-sqlite, persistent, persistent-template,
monad-logger, resourcet monad-logger, resourcet,
ascii-progress
CC-Options: -Wall CC-Options: -Wall
GHC-Options: -Wall GHC-Options: -Wall
Extensions: PackageImports Extensions: PackageImports