summaryrefslogtreecommitdiffhomepage
path: root/UI.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-08-19 14:10:15 -0400
committerJoey Hess <joeyh@joeyh.name>2016-08-19 14:10:15 -0400
commitfdc80b7a2416782d3208acf154fb8afb7fb2279b (patch)
tree503526f7333ec7ee6f20a68334f0dd586747e2b4 /UI.hs
parent6261f7e58b764ae48293bee3b1863b518e9f0442 (diff)
downloadkeysafe-fdc80b7a2416782d3208acf154fb8afb7fb2279b.tar.gz
easier to use progress display
Diffstat (limited to 'UI.hs')
-rw-r--r--UI.hs17
1 files changed, 17 insertions, 0 deletions
diff --git a/UI.hs b/UI.hs
index 279f6b9..c025bb3 100644
--- a/UI.hs
+++ b/UI.hs
@@ -3,12 +3,15 @@
- Licensed under the GNU AGPL version 3 or higher.
-}
+{-# LANGUAGE BangPatterns #-}
+
module UI (module UI, module Types.UI) where
import Types.UI
import Control.Monad
import UI.Zenity
import UI.Readline
+import Control.Concurrent.MVar
availableUIs :: IO [UI]
availableUIs = filterM isAvailable [readlineUI, zenityUI]
@@ -25,3 +28,17 @@ selectUI needgui
case l of
(u:_) -> return u
[] -> error "Neither zenity nor the readline UI are available"
+
+-- Adds a percent to whatever amount the progress bar is at.
+type AddPercent = Percent -> IO ()
+
+withProgressIncremental :: UI -> Title -> Desc -> (AddPercent -> IO a) -> IO a
+withProgressIncremental ui title desc a =
+ withProgress ui title desc $ \setpercent -> do
+ v <- newMVar 0
+ let addpercent = \p -> do
+ oldp <- takeMVar v
+ let !newp = oldp + p
+ putMVar v newp
+ setpercent newp
+ a addpercent