-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathOutput.hs
61 lines (53 loc) · 1.69 KB
/
Output.hs
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{- |
Module : Main
Description : The haskell-updater executable
License : GPL-2 or later
Fancy output facility.
-}
module Output (
pkgListPrintLn
, printList
, say
, vsay
, Verbosity(..)
) where
import qualified Data.Set as Set
import System.IO (hPutStrLn, stderr)
import Distribution.Gentoo.Packages
-- output mode (chattiness)
data Verbosity = Quiet
| Normal
| Verbose
deriving (Eq, Ord, Show, Read)
say :: Verbosity -> String -> IO ()
say verb_l msg =
case verb_l of
Quiet -> return ()
Normal -> hPutStrLn stderr msg
Verbose -> hPutStrLn stderr msg
vsay :: Verbosity -> String -> IO ()
vsay verb_l msg =
case verb_l of
Quiet -> return ()
Normal -> return ()
Verbose -> hPutStrLn stderr msg
-- Print a bullet list of values with one value per line.
printList :: Verbosity -> (a -> String) -> [a] -> IO ()
printList v f = mapM_ (say v . (++) " * " . f)
-- Print a list of packages, with a description of what they are.
pkgListPrintLn :: Verbosity -> String -> Set.Set Package -> IO ()
pkgListPrintLn v desc pkgs
| null pkgs = do
say v $ unwords ["No", desc, "packages found!"]
say v ""
| otherwise = case v of
Quiet -> pure ()
Normal -> do
hPutStrLn stderr $ unwords
["Found", show (Set.size pkgs), desc, "packages."]
hPutStrLn stderr ""
Verbose -> do
hPutStrLn stderr $ unwords
["Found the following", desc, "packages:"]
printList v printPkg (Set.toList pkgs)
hPutStrLn stderr ""