module HashAddressed.App.Verbosity.Printing
  (
    putNormalLn,
    putVerboseLn,
  )
  where

import Essentials
import HashAddressed.App.Verbosity.Type

import Control.Monad.IO.Class (MonadIO, liftIO)
import Prelude (String)

import qualified Control.Monad as Monad
import qualified System.IO as IO

{-| For output that one might want to use programmatically

    Goes to stdout.

    Can be suppressed with the @--quiet@ flag. -}
putNormalLn :: MonadIO m => Verbosity -> String -> m ()
putNormalLn :: forall (m :: * -> *). MonadIO m => Verbosity -> String -> m ()
putNormalLn Verbosity{ Bool
quiet :: Verbosity -> Bool
quiet :: Bool
quiet } String
x =
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
Monad.unless Bool
quiet forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ Handle -> String -> IO ()
IO.hPutStrLn Handle
IO.stdout String
x

{-| For extra chatty messages

    Goes to stderr so that the output that one might want to use
    programmatically can be captured separately.

    Does not print unless the @--verbose@ flag is used. -}
putVerboseLn :: MonadIO m => Verbosity -> String -> m ()
putVerboseLn :: forall (m :: * -> *). MonadIO m => Verbosity -> String -> m ()
putVerboseLn Verbosity{ Bool
verbose :: Verbosity -> Bool
verbose :: Bool
verbose } String
x =
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
Monad.when Bool
verbose forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ Handle -> String -> IO ()
IO.hPutStrLn Handle
IO.stderr String
x