1 module Network.Services.TSN.Terminal (
9 import Control.Monad.IO.Class (MonadIO(..))
10 import System.Console.ANSI (
13 ColorIntensity( Vivid ),
14 ConsoleLayer( Foreground ),
16 import System.IO ( Handle, hPutStr, stderr, stdout )
18 -- | Perform a computation (anything in MonadIO) with the given
19 -- graphics mode(s) enabled. Revert to the previous graphics mode
20 -- after the computation has finished.
21 with_sgr :: (MonadIO m) => Handle -> [SGR] -> m a -> m a
22 with_sgr h sgrs computation = do
23 liftIO $ hSetSGR h sgrs
28 -- | Perform a computation (anything in MonadIO) with the output set
29 -- to a certain color. Reset to the default color after the
30 -- computation has finished.
31 with_color :: (MonadIO m) => Handle -> Color -> m a -> m a
33 with_sgr h [SetColor Foreground Vivid color]
36 -- | Write the given String to a handle in color. The funnyCaps are
37 -- for synergy with putstrLn and friends.
39 hPutStrColor :: Handle -> Color -> String -> IO ()
40 hPutStrColor h c = with_color h c . hPutStr h
43 -- | Write the given line to a handle in color. The funnyCaps are for
44 -- synergy with putstrLn and friends.
46 hPutStrColorLn :: Handle -> Color -> String -> IO ()
47 hPutStrColorLn h c s = hPutStrColor h c (s ++ "\n")
50 -- | Display text sent to the feed on the console. Don't automatically
53 display_sent :: String -> IO ()
54 display_sent = hPutStrColor stdout Green
57 -- | Display debug text on the console. Don't automatically append a
58 -- newline in case the raw text is needed for, uh, debugging.
60 display_debug :: String -> IO ()
61 display_debug = putStr
64 -- | Display an informational message on the console.
66 display_info :: String -> IO ()
67 display_info = hPutStrColorLn stdout Cyan
70 -- | Display a warning on the console. Uses stderr instead of stdout.
72 display_warning :: String -> IO ()
73 display_warning = hPutStrColorLn stderr Yellow
76 -- | Display an error on the console. Uses stderr instead of stdout.
78 display_error :: String -> IO ()
79 display_error = hPutStrColorLn stderr Red