blob: f0010eb9044aa5bf3a7fb95346eeeb79d240973e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
{- Copyright 2016 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
module UI.NonInteractive (noninteractiveUI) where
import Types.UI
import System.IO
import Control.Exception
noninteractiveUI :: UI
noninteractiveUI = UI
{ isAvailable = return True
, showError = myShowError
, showInfo = myShowInfo
, promptQuestion = myPrompt
, promptName = \t d _ -> myPrompt t d
, promptPassword = \b t d -> myPrompt t d b
, promptKeyId = myPrompt
, withProgress = myWithProgress
}
myShowError :: Desc -> IO ()
myShowError desc = hPutStrLn stderr $ "Error: " ++ desc
myShowInfo :: Title -> Desc -> IO ()
myShowInfo _title desc = putStrLn desc
myPrompt :: Title -> Desc -> x -> IO a
myPrompt _title desc _ = do
putStrLn desc
error "Not running at a terminal and zenity is not installed; cannot interact with user."
myWithProgress :: Title -> Desc -> ((Percent -> IO ()) -> IO a) -> IO a
myWithProgress _title desc a = bracket_ setup cleanup (a sendpercent)
where
setup = putStrLn desc
sendpercent p = do
putStr (show p ++ "% ")
hFlush stdout
cleanup = putStrLn "done"
|