7 import Control.Monad.IO.Class (MonadIO(..))
8 import System.Console.ANSI (
11 ColorIntensity( Vivid ),
12 ConsoleLayer( Foreground ),
14 import System.IO ( Handle, hPutStr )
16 -- | Perform a computation (anything in MonadIO) with the given
17 -- graphics mode(s) enabled. Revert to the previous graphics mode
18 -- after the computation has finished.
19 with_sgr :: (MonadIO m) => [SGR] -> m a -> m a
20 with_sgr sgrs computation = do
26 -- | Perform a computation (anything in MonadIO) with the terminal
27 -- output set to a certain color. Reset to the default color after
28 -- the computation has finished.
29 with_color :: (MonadIO m) => Color -> m a -> m a
31 with_sgr [SetColor Foreground Vivid color]
34 -- | Output the given line to the given handle, in red. The silly
35 -- camelCase name is for consistency with e.g. hPutStrLn.
36 hPutRedStr :: Handle -> String -> IO ()
37 hPutRedStr h = with_color Red . hPutStr h
39 -- | Output the given line to the given handle, in blue. The silly
40 -- camelCase name is for consistency with e.g. hPutStrLn.
41 hPutBlueStr :: Handle -> String -> IO ()
42 hPutBlueStr h = with_color Blue . hPutStr h
44 -- | Output the given line to stdout, in green. The silly camelCase
45 -- name is for consistency with e.g. putStrLn.
46 putGreenLn :: String -> IO ()
47 putGreenLn = with_color Green . putStrLn