From f2f885134a6cf6dd40efe88612e846b69df0d4cd Mon Sep 17 00:00:00 2001 From: "Sandeep.C.R" Date: Fri, 19 Jun 2020 09:49:46 +0530 Subject: [PATCH] [#34] Write errorMessage to stderr Adds a variant of formattedMessage that writes to stderr and use it in the implementation of errorMessage function Resolves #34 --- src/Colourista/IO.hs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Colourista/IO.hs b/src/Colourista/IO.hs index 7160cf5..803d92e 100644 --- a/src/Colourista/IO.hs +++ b/src/Colourista/IO.hs @@ -30,12 +30,14 @@ module Colourista.IO , italicMessage -- * General purpose , formattedMessage + , formattedErrorMessage ) where #if __GLASGOW_HASKELL__ < 804 import Data.Semigroup (Semigroup (..)) #endif import Data.Text (Text) +import System.IO (stderr) import qualified Data.Text.IO as TIO @@ -121,12 +123,12 @@ warningMessage :: Text -> IO () warningMessage t = yellowMessage $ " ⚠ " <> t {-# INLINE warningMessage #-} -{- | Similar to 'redMessage', but add unicode indicator. +{- | Similar to 'redMessage', but add unicode indicator and writes to stderr. <> -} errorMessage :: Text -> IO () -errorMessage t = redMessage $ " \128721 " <> t +errorMessage t = formattedErrorMessage [Colourista.red] $ " \128721 " <> t {-# INLINE errorMessage #-} ---------------------------------------------------------------------------- @@ -156,3 +158,9 @@ list, no formatting is applied. formattedMessage :: [Text] -> Text -> IO () formattedMessage formatting = TIO.putStrLn . Colourista.formatWith formatting {-# INLINE formattedMessage #-} + +{- | A variant of 'formattedMessage' that writes to 'stderr' +-} +formattedErrorMessage :: [Text] -> Text -> IO () +formattedErrorMessage formatting = TIO.hPutStrLn stderr . Colourista.formatWith formatting +{-# INLINE formattedErrorMessage #-}