From 3100ed23049f264e2fc43a02b8b65e7ce4578609 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 1 Sep 2016 11:43:01 -0400 Subject: Fix bug that prevented keysafe --server from running when there was no controlling terminal and zenity was not installed. --- UI/NonInteractive.hs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 UI/NonInteractive.hs (limited to 'UI') diff --git a/UI/NonInteractive.hs b/UI/NonInteractive.hs new file mode 100644 index 0000000..f0010eb --- /dev/null +++ b/UI/NonInteractive.hs @@ -0,0 +1,42 @@ +{- Copyright 2016 Joey Hess + - + - 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" -- cgit v1.2.3