Skip to content

Commit

Permalink
[kowainik#34] Write errorMessage to stderr
Browse files Browse the repository at this point in the history
Adds a variant of formattedMessage that writes to stderr and use it in
the implementation of errorMessage function

Resolves kowainik#34
  • Loading branch information
sras committed Jun 19, 2020
1 parent 69af0b3 commit f2f8851
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Colourista/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
<<https://user-images.githubusercontent.com/4276606/80867592-da0fcc80-8c8c-11ea-90e0-42aae8770c18.png Error message>>
-}
errorMessage :: Text -> IO ()
errorMessage t = redMessage $ " \128721 " <> t
errorMessage t = formattedErrorMessage [Colourista.red] $ " \128721 " <> t
{-# INLINE errorMessage #-}

----------------------------------------------------------------------------
Expand Down Expand Up @@ -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 #-}

0 comments on commit f2f8851

Please sign in to comment.