Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#34] Write errorMessage to stderr #35

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 #-}