Skip to content

Commit

Permalink
[#26] Ability to disable and enable colouring
Browse files Browse the repository at this point in the history
Resolves #26
  • Loading branch information
chshersh committed Aug 21, 2020
1 parent 69af0b3 commit 03841ca
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 145 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
`colourista` uses [PVP Versioning][1].
The changelog is available [on GitHub][2].

## 0.2.0.0

* [#26](https://github.com/kowainik/colourista/issues/26):
Support enabling and disable of colouring with implicit parameters.

## 0.1.0.0 — May 2, 2020 🌈

* [#22](https://github.com/kowainik/colourista/issues/22):
Expand Down
3 changes: 2 additions & 1 deletion colourista.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.4
name: colourista
version: 0.1.0.0
version: 0.2.0.0
synopsis: Convenient interface for printing colourful messages
description: Convenient interface for printing colourful messages based on the @ansi-terminal@ library.
homepage: https://github.com/kowainik/colourista
Expand Down Expand Up @@ -34,6 +34,7 @@ library
build-depends: base >= 4.10.1.0 && < 4.15
, ansi-terminal ^>= 0.10
, bytestring ^>= 0.10
, ghc-prim >= 0.5 && < 0.7
, text ^>= 1.2.3.0

ghc-options: -Wall
Expand Down
34 changes: 18 additions & 16 deletions src/Colourista/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import Data.Semigroup (Semigroup (..))
#endif
import Data.Text (Text)

import Colourista.Pure (HasColourMode)

import qualified Data.Text.IO as TIO

import qualified Colourista.Pure as Colourista
Expand All @@ -46,42 +48,42 @@ import qualified Colourista.Pure as Colourista
----------------------------------------------------------------------------

-- | Print 'Text' coloured in 'Colourista.red'.
redMessage :: Text -> IO ()
redMessage :: HasColourMode => Text -> IO ()
redMessage = formattedMessage [Colourista.red]
{-# INLINE redMessage #-}

-- | Print 'Text' coloured in 'Colourista.green'.
greenMessage :: Text -> IO ()
greenMessage :: HasColourMode => Text -> IO ()
greenMessage = formattedMessage [Colourista.green]
{-# INLINE greenMessage #-}

-- | Print 'Text' coloured in 'Colourista.blue'.
blueMessage :: Text -> IO ()
blueMessage :: HasColourMode => Text -> IO ()
blueMessage = formattedMessage [Colourista.blue]
{-# INLINE blueMessage #-}

-- | Print 'Text' coloured in 'Colourista.yellow'.
yellowMessage :: Text -> IO ()
yellowMessage :: HasColourMode => Text -> IO ()
yellowMessage = formattedMessage [Colourista.yellow]
{-# INLINE yellowMessage #-}

-- | Print 'Text' coloured in 'Colourista.black'.
blackMessage :: Text -> IO ()
blackMessage :: HasColourMode => Text -> IO ()
blackMessage = formattedMessage [Colourista.black]
{-# INLINE blackMessage #-}

-- | Print 'Text' coloured in 'Colourista.white'.
whiteMessage :: Text -> IO ()
whiteMessage :: HasColourMode => Text -> IO ()
whiteMessage = formattedMessage [Colourista.white]
{-# INLINE whiteMessage #-}

-- | Print 'Text' coloured in 'Colourista.magenta'.
magentaMessage :: Text -> IO ()
magentaMessage :: HasColourMode => Text -> IO ()
magentaMessage = formattedMessage [Colourista.magenta]
{-# INLINE magentaMessage #-}

-- | Print 'Text' coloured in 'Colourista.cyan'.
cyanMessage :: Text -> IO ()
cyanMessage :: HasColourMode => Text -> IO ()
cyanMessage = formattedMessage [Colourista.cyan]
{-# INLINE cyanMessage #-}

Expand All @@ -93,39 +95,39 @@ cyanMessage = formattedMessage [Colourista.cyan]
<<https://user-images.githubusercontent.com/4276606/80867598-dbd99000-8c8c-11ea-9fac-81a1a606d8d8.png Success message>>
-}
successMessage :: Text -> IO ()
successMessage :: HasColourMode => Text -> IO ()
successMessage t = greenMessage $ "" <> t
{-# INLINE successMessage #-}

{- | Similar to 'blueMessage', but add unicode indicator.
<<https://user-images.githubusercontent.com/4276606/80867597-db40f980-8c8c-11ea-9775-e8a3c4a7aaa2.png Information message>>
-}
infoMessage :: Text -> IO ()
infoMessage :: HasColourMode => Text -> IO ()
infoMessage t = blueMessage $ "" <> t
{-# INLINE infoMessage #-}

{- | Similar to 'cyanMessage', but add unicode indicator.
<<https://user-images.githubusercontent.com/4276606/80867596-db40f980-8c8c-11ea-8131-9c7cba32a4fd.png Skip message>>
-}
skipMessage :: Text -> IO ()
skipMessage :: HasColourMode => Text -> IO ()
skipMessage t = cyanMessage $ "" <> t
{-# INLINE skipMessage #-}

{- | Similar to 'yellowMessage', but add unicode indicator.
<<https://user-images.githubusercontent.com/4276606/80867594-daa86300-8c8c-11ea-9c6a-a42b634a1e4b.png Warning message>>
-}
warningMessage :: Text -> IO ()
warningMessage :: HasColourMode => Text -> IO ()
warningMessage t = yellowMessage $ "" <> t
{-# INLINE warningMessage #-}

{- | Similar to 'redMessage', but add unicode indicator.
<<https://user-images.githubusercontent.com/4276606/80867592-da0fcc80-8c8c-11ea-90e0-42aae8770c18.png Error message>>
-}
errorMessage :: Text -> IO ()
errorMessage :: HasColourMode => Text -> IO ()
errorMessage t = redMessage $ " \128721 " <> t
{-# INLINE errorMessage #-}

Expand All @@ -134,12 +136,12 @@ errorMessage t = redMessage $ " \128721 " <> t
----------------------------------------------------------------------------

-- | Print 'Text' emphasized with 'Colourista.bold'.
boldMessage :: Text -> IO ()
boldMessage :: HasColourMode => Text -> IO ()
boldMessage = formattedMessage [Colourista.bold]
{-# INLINE boldMessage #-}

-- | Print 'Text' emphasized with 'Colourista.italic'.
italicMessage :: Text -> IO ()
italicMessage :: HasColourMode => Text -> IO ()
italicMessage = formattedMessage [Colourista.italic]
{-# INLINE italicMessage #-}

Expand All @@ -153,6 +155,6 @@ list, no formatting is applied.
![formattedMessage-example](https://user-images.githubusercontent.com/4276606/74608898-e6987600-50dc-11ea-9a93-bda701fd3c43.png)
-}
formattedMessage :: [Text] -> Text -> IO ()
formattedMessage :: HasColourMode => [Text] -> Text -> IO ()
formattedMessage formatting = TIO.putStrLn . Colourista.formatWith formatting
{-# INLINE formattedMessage #-}
Loading

0 comments on commit 03841ca

Please sign in to comment.