module Summoner.Ansi
( Color (..)
, putStrFlush
, beautyPrint
, boldCode
, blueCode
, bold
, boldText
, boldDefault
, italic
, redCode
, reset
, resetCode
, prompt
, setColor
, successMessage
, warningMessage
, errorMessage
, infoMessage
, skipMessage
) where
import Relude
import System.Console.ANSI (Color (..), ColorIntensity (Vivid), ConsoleIntensity (BoldIntensity),
ConsoleLayer (Foreground), SGR (..), setSGR, setSGRCode)
import System.IO (hFlush)
putStrFlush :: Text -> IO ()
putStrFlush msg = do
putText msg
hFlush stdout
setColor :: Color -> IO ()
setColor color = setSGR [SetColor Foreground Vivid color]
bold :: IO ()
bold = setSGR [SetConsoleIntensity BoldIntensity]
italic :: IO ()
italic = setSGR [SetItalicized True]
reset :: IO ()
reset = do
setSGR [Reset]
hFlush stdout
beautyPrint :: [IO ()] -> Text -> IO ()
beautyPrint formats msg = do
sequence_ formats
putText msg
reset
prompt :: IO Text
prompt = do
setColor Blue
putStrFlush " -> "
reset
getLine
boldText :: Text -> IO ()
boldText message = bold >> putStrFlush message >> reset
boldDefault :: Text -> IO ()
boldDefault message = boldText (" [" <> message <> "]")
colorMessage :: Color -> Text -> IO ()
colorMessage color message = do
setColor color
putTextLn $ " " <> message
reset
errorMessage, warningMessage, successMessage, infoMessage, skipMessage :: Text -> IO ()
errorMessage = colorMessage Red
warningMessage = colorMessage Yellow
successMessage = colorMessage Green
infoMessage = colorMessage Blue
skipMessage = colorMessage Cyan
blueCode, boldCode, redCode, resetCode :: String
redCode = setSGRCode [SetColor Foreground Vivid Red]
blueCode = setSGRCode [SetColor Foreground Vivid Blue]
boldCode = setSGRCode [SetConsoleIntensity BoldIntensity]
resetCode = setSGRCode [Reset]