{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}

-----------------------------------------------------------------------------

-- Verbosity for Cabal functions.

-- |
-- Module      :  Distribution.Verbosity
-- Copyright   :  Ian Lynagh 2007
-- License     :  BSD3
--
-- Maintainer  :  cabal-devel@haskell.org
-- Portability :  portable
--
-- A 'Verbosity' type with associated utilities.
--
-- There are 4 standard verbosity levels from 'silent', 'normal',
-- 'verbose' up to 'deafening'. This is used for deciding what logging
-- messages to print.
--
-- Verbosity also is equipped with some internal settings which can be
-- used to control at a fine granularity the verbosity of specific
-- settings (e.g., so that you can trace only particular things you
-- are interested in.)  It's important to note that the instances
-- for 'Verbosity' assume that this does not exist.
module Distribution.Verbosity
  ( -- * Verbosity
    Verbosity
  , silent
  , normal
  , verbose
  , deafening
  , moreVerbose
  , lessVerbose
  , isVerboseQuiet
  , intToVerbosity
  , flagToVerbosity
  , showForCabal
  , showForGHC
  , verboseNoFlags
  , verboseHasFlags
  , modifyVerbosity

    -- * Call stacks
  , verboseCallSite
  , verboseCallStack
  , isVerboseCallSite
  , isVerboseCallStack

    -- * Output markets
  , verboseMarkOutput
  , isVerboseMarkOutput
  , verboseUnmarkOutput

    -- * Line wrapping
  , verboseNoWrap
  , isVerboseNoWrap

    -- * Time stamps
  , verboseTimestamp
  , isVerboseTimestamp
  , verboseNoTimestamp

    -- * Stderr
  , verboseStderr
  , isVerboseStderr
  , verboseNoStderr

    -- * No warnings
  , verboseNoWarn
  , isVerboseNoWarn
  ) where

import Distribution.Compat.Prelude
import Prelude ()

import Distribution.ReadE

import Data.List (elemIndex)
import Distribution.Parsec
import Distribution.Pretty
import Distribution.Utils.Generic (isAsciiAlpha)
import Distribution.Verbosity.Internal

import qualified Data.Set as Set
import qualified Distribution.Compat.CharParsing as P
import qualified Text.PrettyPrint as PP

data Verbosity = Verbosity
  { Verbosity -> VerbosityLevel
vLevel :: VerbosityLevel
  , Verbosity -> Set VerbosityFlag
vFlags :: Set VerbosityFlag
  , Verbosity -> Bool
vQuiet :: Bool
  }
  deriving ((forall x. Verbosity -> Rep Verbosity x)
-> (forall x. Rep Verbosity x -> Verbosity) -> Generic Verbosity
forall x. Rep Verbosity x -> Verbosity
forall x. Verbosity -> Rep Verbosity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Verbosity -> Rep Verbosity x
from :: forall x. Verbosity -> Rep Verbosity x
$cto :: forall x. Rep Verbosity x -> Verbosity
to :: forall x. Rep Verbosity x -> Verbosity
Generic, Int -> Verbosity -> ShowS
[Verbosity] -> ShowS
Verbosity -> String
(Int -> Verbosity -> ShowS)
-> (Verbosity -> String)
-> ([Verbosity] -> ShowS)
-> Show Verbosity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Verbosity -> ShowS
showsPrec :: Int -> Verbosity -> ShowS
$cshow :: Verbosity -> String
show :: Verbosity -> String
$cshowList :: [Verbosity] -> ShowS
showList :: [Verbosity] -> ShowS
Show, ReadPrec [Verbosity]
ReadPrec Verbosity
Int -> ReadS Verbosity
ReadS [Verbosity]
(Int -> ReadS Verbosity)
-> ReadS [Verbosity]
-> ReadPrec Verbosity
-> ReadPrec [Verbosity]
-> Read Verbosity
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Verbosity
readsPrec :: Int -> ReadS Verbosity
$creadList :: ReadS [Verbosity]
readList :: ReadS [Verbosity]
$creadPrec :: ReadPrec Verbosity
readPrec :: ReadPrec Verbosity
$creadListPrec :: ReadPrec [Verbosity]
readListPrec :: ReadPrec [Verbosity]
Read, Typeable)

mkVerbosity :: VerbosityLevel -> Verbosity
mkVerbosity :: VerbosityLevel -> Verbosity
mkVerbosity VerbosityLevel
l = Verbosity{vLevel :: VerbosityLevel
vLevel = VerbosityLevel
l, vFlags :: Set VerbosityFlag
vFlags = Set VerbosityFlag
forall a. Set a
Set.empty, vQuiet :: Bool
vQuiet = Bool
False}

instance Eq Verbosity where
  Verbosity
x == :: Verbosity -> Verbosity -> Bool
== Verbosity
y = Verbosity -> VerbosityLevel
vLevel Verbosity
x VerbosityLevel -> VerbosityLevel -> Bool
forall a. Eq a => a -> a -> Bool
== Verbosity -> VerbosityLevel
vLevel Verbosity
y

instance Ord Verbosity where
  compare :: Verbosity -> Verbosity -> Ordering
compare Verbosity
x Verbosity
y = VerbosityLevel -> VerbosityLevel -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (Verbosity -> VerbosityLevel
vLevel Verbosity
x) (Verbosity -> VerbosityLevel
vLevel Verbosity
y)

instance Enum Verbosity where
  toEnum :: Int -> Verbosity
toEnum = VerbosityLevel -> Verbosity
mkVerbosity (VerbosityLevel -> Verbosity)
-> (Int -> VerbosityLevel) -> Int -> Verbosity
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> VerbosityLevel
forall a. Enum a => Int -> a
toEnum
  fromEnum :: Verbosity -> Int
fromEnum = VerbosityLevel -> Int
forall a. Enum a => a -> Int
fromEnum (VerbosityLevel -> Int)
-> (Verbosity -> VerbosityLevel) -> Verbosity -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Verbosity -> VerbosityLevel
vLevel

instance Bounded Verbosity where
  minBound :: Verbosity
minBound = VerbosityLevel -> Verbosity
mkVerbosity VerbosityLevel
forall a. Bounded a => a
minBound
  maxBound :: Verbosity
maxBound = VerbosityLevel -> Verbosity
mkVerbosity VerbosityLevel
forall a. Bounded a => a
maxBound

instance Binary Verbosity
instance Structured Verbosity

-- | In 'silent' mode, we should not print /anything/ unless an error occurs.
silent :: Verbosity
silent :: Verbosity
silent = VerbosityLevel -> Verbosity
mkVerbosity VerbosityLevel
Silent

-- | Print stuff we want to see by default.
normal :: Verbosity
normal :: Verbosity
normal = VerbosityLevel -> Verbosity
mkVerbosity VerbosityLevel
Normal

-- | Be more verbose about what's going on.
verbose :: Verbosity
verbose :: Verbosity
verbose = VerbosityLevel -> Verbosity
mkVerbosity VerbosityLevel
Verbose

-- | Not only are we verbose ourselves (perhaps even noisier than when
-- being 'verbose'), but we tell everything we run to be verbose too.
deafening :: Verbosity
deafening :: Verbosity
deafening = VerbosityLevel -> Verbosity
mkVerbosity VerbosityLevel
Deafening

-- | Increase verbosity level, but stay 'silent' if we are.
moreVerbose :: Verbosity -> Verbosity
moreVerbose :: Verbosity -> Verbosity
moreVerbose Verbosity
v =
  case Verbosity -> VerbosityLevel
vLevel Verbosity
v of
    VerbosityLevel
Silent -> Verbosity
v -- silent should stay silent
    VerbosityLevel
Normal -> Verbosity
v{vLevel = Verbose}
    VerbosityLevel
Verbose -> Verbosity
v{vLevel = Deafening}
    VerbosityLevel
Deafening -> Verbosity
v

-- | Decrease verbosity level, but stay 'deafening' if we are.
lessVerbose :: Verbosity -> Verbosity
lessVerbose :: Verbosity -> Verbosity
lessVerbose Verbosity
v =
  Verbosity -> Verbosity
verboseQuiet (Verbosity -> Verbosity) -> Verbosity -> Verbosity
forall a b. (a -> b) -> a -> b
$
    case Verbosity -> VerbosityLevel
vLevel Verbosity
v of
      VerbosityLevel
Deafening -> Verbosity
v -- deafening stays deafening
      VerbosityLevel
Verbose -> Verbosity
v{vLevel = Normal}
      VerbosityLevel
Normal -> Verbosity
v{vLevel = Silent}
      VerbosityLevel
Silent -> Verbosity
v

-- | Combinator for transforming verbosity level while retaining the
-- original hidden state.
--
-- For instance, the following property holds
--
-- prop> isVerboseNoWrap (modifyVerbosity (max verbose) v) == isVerboseNoWrap v
--
-- __Note__: you can use @modifyVerbosity (const v1) v0@ to overwrite
-- @v1@'s flags with @v0@'s flags.
--
-- @since 2.0.1.0
modifyVerbosity :: (Verbosity -> Verbosity) -> Verbosity -> Verbosity
modifyVerbosity :: (Verbosity -> Verbosity) -> Verbosity -> Verbosity
modifyVerbosity Verbosity -> Verbosity
f Verbosity
v = Verbosity
v{vLevel = vLevel (f v)}

-- | Numeric verbosity level @0..3@: @0@ is 'silent', @3@ is 'deafening'.
intToVerbosity :: Int -> Maybe Verbosity
intToVerbosity :: Int -> Maybe Verbosity
intToVerbosity Int
0 = Verbosity -> Maybe Verbosity
forall a. a -> Maybe a
Just (VerbosityLevel -> Verbosity
mkVerbosity VerbosityLevel
Silent)
intToVerbosity Int
1 = Verbosity -> Maybe Verbosity
forall a. a -> Maybe a
Just (VerbosityLevel -> Verbosity
mkVerbosity VerbosityLevel
Normal)
intToVerbosity Int
2 = Verbosity -> Maybe Verbosity
forall a. a -> Maybe a
Just (VerbosityLevel -> Verbosity
mkVerbosity VerbosityLevel
Verbose)
intToVerbosity Int
3 = Verbosity -> Maybe Verbosity
forall a. a -> Maybe a
Just (VerbosityLevel -> Verbosity
mkVerbosity VerbosityLevel
Deafening)
intToVerbosity Int
_ = Maybe Verbosity
forall a. Maybe a
Nothing

-- | Parser verbosity
--
-- >>> explicitEitherParsec parsecVerbosity "normal"
-- Right (Verbosity {vLevel = Normal, vFlags = fromList [], vQuiet = False})
--
-- >>> explicitEitherParsec parsecVerbosity "normal+nowrap  "
-- Right (Verbosity {vLevel = Normal, vFlags = fromList [VNoWrap], vQuiet = False})
--
-- >>> explicitEitherParsec parsecVerbosity "normal+nowrap +markoutput"
-- Right (Verbosity {vLevel = Normal, vFlags = fromList [VNoWrap,VMarkOutput], vQuiet = False})
--
-- >>> explicitEitherParsec parsecVerbosity "normal +nowrap +markoutput"
-- Right (Verbosity {vLevel = Normal, vFlags = fromList [VNoWrap,VMarkOutput], vQuiet = False})
--
-- >>> explicitEitherParsec parsecVerbosity "normal+nowrap+markoutput"
-- Right (Verbosity {vLevel = Normal, vFlags = fromList [VNoWrap,VMarkOutput], vQuiet = False})
--
-- >>> explicitEitherParsec parsecVerbosity "deafening+nowrap+stdout+stderr+callsite+callstack"
-- Right (Verbosity {vLevel = Deafening, vFlags = fromList [VCallStack,VCallSite,VNoWrap,VStderr], vQuiet = False})
--
-- /Note:/ this parser will eat trailing spaces.
instance Parsec Verbosity where
  parsec :: forall (m :: * -> *). CabalParsing m => m Verbosity
parsec = m Verbosity
forall (m :: * -> *). CabalParsing m => m Verbosity
parsecVerbosity

instance Pretty Verbosity where
  pretty :: Verbosity -> Doc
pretty = String -> Doc
PP.text (String -> Doc) -> (Verbosity -> String) -> Verbosity -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Verbosity -> String
showForCabal

parsecVerbosity :: CabalParsing m => m Verbosity
parsecVerbosity :: forall (m :: * -> *). CabalParsing m => m Verbosity
parsecVerbosity = m Verbosity
parseIntVerbosity m Verbosity -> m Verbosity -> m Verbosity
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m Verbosity
parseStringVerbosity
  where
    parseIntVerbosity :: m Verbosity
parseIntVerbosity = do
      Int
i <- m Int
forall (m :: * -> *) a. (CharParsing m, Integral a) => m a
P.integral
      case Int -> Maybe Verbosity
intToVerbosity Int
i of
        Just Verbosity
v -> Verbosity -> m Verbosity
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Verbosity
v
        Maybe Verbosity
Nothing -> String -> m Verbosity
forall a. String -> m a
forall (m :: * -> *) a. Parsing m => String -> m a
P.unexpected (String -> m Verbosity) -> String -> m Verbosity
forall a b. (a -> b) -> a -> b
$ String
"Bad integral verbosity: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
". Valid values are 0..3"

    parseStringVerbosity :: m Verbosity
parseStringVerbosity = do
      VerbosityLevel
level <- m VerbosityLevel
parseVerbosityLevel
      ()
_ <- m ()
forall (m :: * -> *). CharParsing m => m ()
P.spaces
      [Verbosity -> Verbosity]
flags <- m (Verbosity -> Verbosity) -> m [Verbosity -> Verbosity]
forall a. m a -> m [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (m (Verbosity -> Verbosity)
parseFlag m (Verbosity -> Verbosity) -> m () -> m (Verbosity -> Verbosity)
forall a b. m a -> m b -> m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* m ()
forall (m :: * -> *). CharParsing m => m ()
P.spaces)
      Verbosity -> m Verbosity
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Verbosity -> m Verbosity) -> Verbosity -> m Verbosity
forall a b. (a -> b) -> a -> b
$ (Verbosity -> (Verbosity -> Verbosity) -> Verbosity)
-> Verbosity -> [Verbosity -> Verbosity] -> Verbosity
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (((Verbosity -> Verbosity) -> Verbosity -> Verbosity)
-> Verbosity -> (Verbosity -> Verbosity) -> Verbosity
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Verbosity -> Verbosity) -> Verbosity -> Verbosity
forall a b. (a -> b) -> a -> b
($)) (VerbosityLevel -> Verbosity
mkVerbosity VerbosityLevel
level) [Verbosity -> Verbosity]
flags

    parseVerbosityLevel :: m VerbosityLevel
parseVerbosityLevel = do
      String
token <- (Char -> Bool) -> m String
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m String
P.munch1 Char -> Bool
isAsciiAlpha
      case String
token of
        String
"silent" -> VerbosityLevel -> m VerbosityLevel
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return VerbosityLevel
Silent
        String
"normal" -> VerbosityLevel -> m VerbosityLevel
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return VerbosityLevel
Normal
        String
"verbose" -> VerbosityLevel -> m VerbosityLevel
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return VerbosityLevel
Verbose
        String
"debug" -> VerbosityLevel -> m VerbosityLevel
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return VerbosityLevel
Deafening
        String
"deafening" -> VerbosityLevel -> m VerbosityLevel
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return VerbosityLevel
Deafening
        String
_ -> String -> m VerbosityLevel
forall a. String -> m a
forall (m :: * -> *) a. Parsing m => String -> m a
P.unexpected (String -> m VerbosityLevel) -> String -> m VerbosityLevel
forall a b. (a -> b) -> a -> b
$ String
"Bad verbosity level: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
token
    parseFlag :: m (Verbosity -> Verbosity)
parseFlag = do
      Char
_ <- Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
P.char Char
'+'
      String
token <- (Char -> Bool) -> m String
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m String
P.munch1 Char -> Bool
isAsciiAlpha
      case String
token of
        String
"callsite" -> (Verbosity -> Verbosity) -> m (Verbosity -> Verbosity)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Verbosity -> Verbosity
verboseCallSite
        String
"callstack" -> (Verbosity -> Verbosity) -> m (Verbosity -> Verbosity)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Verbosity -> Verbosity
verboseCallStack
        String
"nowrap" -> (Verbosity -> Verbosity) -> m (Verbosity -> Verbosity)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Verbosity -> Verbosity
verboseNoWrap
        String
"markoutput" -> (Verbosity -> Verbosity) -> m (Verbosity -> Verbosity)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Verbosity -> Verbosity
verboseMarkOutput
        String
"timestamp" -> (Verbosity -> Verbosity) -> m (Verbosity -> Verbosity)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Verbosity -> Verbosity
verboseTimestamp
        String
"stderr" -> (Verbosity -> Verbosity) -> m (Verbosity -> Verbosity)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Verbosity -> Verbosity
verboseStderr
        String
"stdout" -> (Verbosity -> Verbosity) -> m (Verbosity -> Verbosity)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Verbosity -> Verbosity
verboseNoStderr
        String
"nowarn" -> (Verbosity -> Verbosity) -> m (Verbosity -> Verbosity)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Verbosity -> Verbosity
verboseNoWarn
        String
_ -> String -> m (Verbosity -> Verbosity)
forall a. String -> m a
forall (m :: * -> *) a. Parsing m => String -> m a
P.unexpected (String -> m (Verbosity -> Verbosity))
-> String -> m (Verbosity -> Verbosity)
forall a b. (a -> b) -> a -> b
$ String
"Bad verbosity flag: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
token

flagToVerbosity :: ReadE Verbosity
flagToVerbosity :: ReadE Verbosity
flagToVerbosity = ShowS -> ParsecParser Verbosity -> ReadE Verbosity
forall a. ShowS -> ParsecParser a -> ReadE a
parsecToReadE ShowS
forall a. a -> a
id ParsecParser Verbosity
forall (m :: * -> *). CabalParsing m => m Verbosity
parsecVerbosity

showForCabal :: Verbosity -> String
showForCabal :: Verbosity -> String
showForCabal Verbosity
v
  | Set VerbosityFlag -> Bool
forall a. Set a -> Bool
Set.null (Verbosity -> Set VerbosityFlag
vFlags Verbosity
v) =
      String -> (Int -> String) -> Maybe Int -> String
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (ShowS
forall a. HasCallStack => String -> a
error String
"unknown verbosity") Int -> String
forall a. Show a => a -> String
show (Maybe Int -> String) -> Maybe Int -> String
forall a b. (a -> b) -> a -> b
$
        Verbosity -> [Verbosity] -> Maybe Int
forall a. Eq a => a -> [a] -> Maybe Int
elemIndex Verbosity
v [Verbosity
silent, Verbosity
normal, Verbosity
verbose, Verbosity
deafening]
  | Bool
otherwise =
      [String] -> String
unwords ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$
        VerbosityLevel -> String
showLevel (Verbosity -> VerbosityLevel
vLevel Verbosity
v)
          String -> [String] -> [String]
forall a. a -> [a] -> [a]
: (VerbosityFlag -> [String]) -> [VerbosityFlag] -> [String]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap VerbosityFlag -> [String]
showFlag (Set VerbosityFlag -> [VerbosityFlag]
forall a. Set a -> [a]
Set.toList (Verbosity -> Set VerbosityFlag
vFlags Verbosity
v))
  where
    showLevel :: VerbosityLevel -> String
showLevel VerbosityLevel
Silent = String
"silent"
    showLevel VerbosityLevel
Normal = String
"normal"
    showLevel VerbosityLevel
Verbose = String
"verbose"
    showLevel VerbosityLevel
Deafening = String
"debug"

    showFlag :: VerbosityFlag -> [String]
showFlag VerbosityFlag
VCallSite = [String
"+callsite"]
    showFlag VerbosityFlag
VCallStack = [String
"+callstack"]
    showFlag VerbosityFlag
VNoWrap = [String
"+nowrap"]
    showFlag VerbosityFlag
VMarkOutput = [String
"+markoutput"]
    showFlag VerbosityFlag
VTimestamp = [String
"+timestamp"]
    showFlag VerbosityFlag
VStderr = [String
"+stderr"]
    showFlag VerbosityFlag
VNoWarn = [String
"+nowarn"]

showForGHC :: Verbosity -> String
showForGHC :: Verbosity -> String
showForGHC Verbosity
v =
  String -> (Int -> String) -> Maybe Int -> String
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (ShowS
forall a. HasCallStack => String -> a
error String
"unknown verbosity") Int -> String
forall a. Show a => a -> String
show (Maybe Int -> String) -> Maybe Int -> String
forall a b. (a -> b) -> a -> b
$
    Verbosity -> [Verbosity] -> Maybe Int
forall a. Eq a => a -> [a] -> Maybe Int
elemIndex Verbosity
v [Verbosity
silent, Verbosity
normal, Verbosity
__, Verbosity
verbose, Verbosity
deafening]
  where
    __ :: Verbosity
__ = Verbosity
silent -- this will be always ignored by elemIndex

-- | Turn on verbose call-site printing when we log.
verboseCallSite :: Verbosity -> Verbosity
verboseCallSite :: Verbosity -> Verbosity
verboseCallSite = VerbosityFlag -> Verbosity -> Verbosity
verboseFlag VerbosityFlag
VCallSite

-- | Turn on verbose call-stack printing when we log.
verboseCallStack :: Verbosity -> Verbosity
verboseCallStack :: Verbosity -> Verbosity
verboseCallStack = VerbosityFlag -> Verbosity -> Verbosity
verboseFlag VerbosityFlag
VCallStack

-- | Turn on @-----BEGIN CABAL OUTPUT-----@ markers for output
-- from Cabal (as opposed to GHC, or system dependent).
verboseMarkOutput :: Verbosity -> Verbosity
verboseMarkOutput :: Verbosity -> Verbosity
verboseMarkOutput = VerbosityFlag -> Verbosity -> Verbosity
verboseFlag VerbosityFlag
VMarkOutput

-- | Turn off marking; useful for suppressing nondeterministic output.
verboseUnmarkOutput :: Verbosity -> Verbosity
verboseUnmarkOutput :: Verbosity -> Verbosity
verboseUnmarkOutput = VerbosityFlag -> Verbosity -> Verbosity
verboseNoFlag VerbosityFlag
VMarkOutput

-- | Disable line-wrapping for log messages.
verboseNoWrap :: Verbosity -> Verbosity
verboseNoWrap :: Verbosity -> Verbosity
verboseNoWrap = VerbosityFlag -> Verbosity -> Verbosity
verboseFlag VerbosityFlag
VNoWrap

-- | Mark the verbosity as quiet.
verboseQuiet :: Verbosity -> Verbosity
verboseQuiet :: Verbosity -> Verbosity
verboseQuiet Verbosity
v = Verbosity
v{vQuiet = True}

-- | Turn on timestamps for log messages.
verboseTimestamp :: Verbosity -> Verbosity
verboseTimestamp :: Verbosity -> Verbosity
verboseTimestamp = VerbosityFlag -> Verbosity -> Verbosity
verboseFlag VerbosityFlag
VTimestamp

-- | Turn off timestamps for log messages.
verboseNoTimestamp :: Verbosity -> Verbosity
verboseNoTimestamp :: Verbosity -> Verbosity
verboseNoTimestamp = VerbosityFlag -> Verbosity -> Verbosity
verboseNoFlag VerbosityFlag
VTimestamp

-- | Switch logging to 'stderr'.
--
-- @since 3.4.0.0
verboseStderr :: Verbosity -> Verbosity
verboseStderr :: Verbosity -> Verbosity
verboseStderr = VerbosityFlag -> Verbosity -> Verbosity
verboseFlag VerbosityFlag
VStderr

-- | Switch logging to 'stdout'.
--
-- @since 3.4.0.0
verboseNoStderr :: Verbosity -> Verbosity
verboseNoStderr :: Verbosity -> Verbosity
verboseNoStderr = VerbosityFlag -> Verbosity -> Verbosity
verboseNoFlag VerbosityFlag
VStderr

-- | Turn off warnings for log messages.
verboseNoWarn :: Verbosity -> Verbosity
verboseNoWarn :: Verbosity -> Verbosity
verboseNoWarn = VerbosityFlag -> Verbosity -> Verbosity
verboseFlag VerbosityFlag
VNoWarn

-- | Helper function for flag enabling functions.
verboseFlag :: VerbosityFlag -> (Verbosity -> Verbosity)
verboseFlag :: VerbosityFlag -> Verbosity -> Verbosity
verboseFlag VerbosityFlag
flag Verbosity
v = Verbosity
v{vFlags = Set.insert flag (vFlags v)}

-- | Helper function for flag disabling functions.
verboseNoFlag :: VerbosityFlag -> (Verbosity -> Verbosity)
verboseNoFlag :: VerbosityFlag -> Verbosity -> Verbosity
verboseNoFlag VerbosityFlag
flag Verbosity
v = Verbosity
v{vFlags = Set.delete flag (vFlags v)}

-- | Turn off all flags.
verboseNoFlags :: Verbosity -> Verbosity
verboseNoFlags :: Verbosity -> Verbosity
verboseNoFlags Verbosity
v = Verbosity
v{vFlags = Set.empty}

verboseHasFlags :: Verbosity -> Bool
verboseHasFlags :: Verbosity -> Bool
verboseHasFlags = Bool -> Bool
not (Bool -> Bool) -> (Verbosity -> Bool) -> Verbosity -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set VerbosityFlag -> Bool
forall a. Set a -> Bool
Set.null (Set VerbosityFlag -> Bool)
-> (Verbosity -> Set VerbosityFlag) -> Verbosity -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Verbosity -> Set VerbosityFlag
vFlags

-- | Test if we should output call sites when we log.
isVerboseCallSite :: Verbosity -> Bool
isVerboseCallSite :: Verbosity -> Bool
isVerboseCallSite = VerbosityFlag -> Verbosity -> Bool
isVerboseFlag VerbosityFlag
VCallSite

-- | Test if we should output call stacks when we log.
isVerboseCallStack :: Verbosity -> Bool
isVerboseCallStack :: Verbosity -> Bool
isVerboseCallStack = VerbosityFlag -> Verbosity -> Bool
isVerboseFlag VerbosityFlag
VCallStack

-- | Test if we should output markets.
isVerboseMarkOutput :: Verbosity -> Bool
isVerboseMarkOutput :: Verbosity -> Bool
isVerboseMarkOutput = VerbosityFlag -> Verbosity -> Bool
isVerboseFlag VerbosityFlag
VMarkOutput

-- | Test if line-wrapping is disabled for log messages.
isVerboseNoWrap :: Verbosity -> Bool
isVerboseNoWrap :: Verbosity -> Bool
isVerboseNoWrap = VerbosityFlag -> Verbosity -> Bool
isVerboseFlag VerbosityFlag
VNoWrap

-- | Test if we had called 'lessVerbose' on the verbosity.
isVerboseQuiet :: Verbosity -> Bool
isVerboseQuiet :: Verbosity -> Bool
isVerboseQuiet = Verbosity -> Bool
vQuiet

-- | Test if we should output timestamps when we log.
isVerboseTimestamp :: Verbosity -> Bool
isVerboseTimestamp :: Verbosity -> Bool
isVerboseTimestamp = VerbosityFlag -> Verbosity -> Bool
isVerboseFlag VerbosityFlag
VTimestamp

-- | Test if we should output to 'stderr' when we log.
--
-- @since 3.4.0.0
isVerboseStderr :: Verbosity -> Bool
isVerboseStderr :: Verbosity -> Bool
isVerboseStderr = VerbosityFlag -> Verbosity -> Bool
isVerboseFlag VerbosityFlag
VStderr

-- | Test if we should output warnings when we log.
isVerboseNoWarn :: Verbosity -> Bool
isVerboseNoWarn :: Verbosity -> Bool
isVerboseNoWarn = VerbosityFlag -> Verbosity -> Bool
isVerboseFlag VerbosityFlag
VNoWarn

-- | Helper function for flag testing functions.
isVerboseFlag :: VerbosityFlag -> Verbosity -> Bool
isVerboseFlag :: VerbosityFlag -> Verbosity -> Bool
isVerboseFlag VerbosityFlag
flag = (VerbosityFlag -> Set VerbosityFlag -> Bool
forall a. Ord a => a -> Set a -> Bool
Set.member VerbosityFlag
flag) (Set VerbosityFlag -> Bool)
-> (Verbosity -> Set VerbosityFlag) -> Verbosity -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Verbosity -> Set VerbosityFlag
vFlags

-- $setup
-- >>> import Test.QuickCheck (Arbitrary (..), arbitraryBoundedEnum)
-- >>> instance Arbitrary VerbosityLevel where arbitrary = arbitraryBoundedEnum
-- >>> instance Arbitrary Verbosity where arbitrary = fmap mkVerbosity arbitrary