summaryrefslogtreecommitdiff
path: root/Messages
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-05-12 13:54:16 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-05-12 13:54:16 -0400
commite1e562fe87d6d99fe01d82a48fc259be5ee9867a (patch)
tree66607afdd9a81047b378ec1a9c76c29ee50a2241 /Messages
parent4d49342612dd441cdc503b5294035fc05a9a5a77 (diff)
allow building without ascii-progress, since it is not ready yet
No progress bars with -J unless built with ascii-progress.
Diffstat (limited to 'Messages')
-rw-r--r--Messages/Progress.hs31
1 files changed, 31 insertions, 0 deletions
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. -}