From e1e562fe87d6d99fe01d82a48fc259be5ee9867a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 12 May 2015 13:54:16 -0400 Subject: allow building without ascii-progress, since it is not ready yet No progress bars with -J unless built with ascii-progress. --- Messages/Progress.hs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'Messages') diff --git a/Messages/Progress.hs b/Messages/Progress.hs index 9bc335570..25e2e03ae 100644 --- a/Messages/Progress.hs +++ b/Messages/Progress.hs @@ -5,6 +5,8 @@ - Licensed under the GNU GPL version 3 or higher. -} +{-# LANGUAGE CPP #-} + module Messages.Progress where import Common @@ -15,9 +17,15 @@ import Types import Types.Messages import Types.Key +#ifdef WITH_ASCIIPROGRESS import System.Console.AsciiProgress import qualified System.Console.Terminal.Size as Terminal import Control.Concurrent +#else +import Data.Progress.Meter +import Data.Progress.Tracker +import Data.Quantity +#endif {- Shows a progress meter while performing a transfer of a key. - The action is passed a callback to use to update the meter. -} @@ -28,6 +36,7 @@ metered combinemeterupdate key af a = case keySize key of where go _ QuietOutput = nometer go _ JSONOutput = nometer +#ifdef WITH_ASCIIPROGRESS go size _ = do showOutput liftIO $ putStrLn "" @@ -55,20 +64,42 @@ metered combinemeterupdate key af a = case keySize key of complete pg return r +#else + -- Old progress bar code, not suitable for parallel output. + go _ (ParallelOutput _) = do + r <- nometer + liftIO $ putStrLn $ fromMaybe (key2file key) af + return r + go size NormalOutput = do + showOutput + progress <- liftIO $ newProgress "" size + meter <- liftIO $ newMeter progress "B" 25 (renderNums binaryOpts 1) + r <- a $ liftIO . pupdate meter progress + liftIO $ clearMeter stdout meter + return r +#endif +#ifdef WITH_ASCIIPROGRESS pupdate pg n = do let i = fromBytesProcessed n sofar <- stCompleted <$> getProgressStats pg when (i > sofar) $ tickN pg (i - sofar) threadDelay 100 +#else + pupdate meter progress n = do + setP progress $ fromBytesProcessed n + displayMeter stdout meter +#endif maybe noop (\m -> m n) combinemeterupdate nometer = a (const noop) +#ifdef WITH_ASCIIPROGRESS truncatepretty n s | length s > n = take (n-2) s ++ ".." | otherwise = s +#endif {- Use when the progress meter is only desired for parallel - mode; as when a command's own progress output is preferred. -} -- cgit v1.2.3