From ba689434d2047d2d7b2dad9080bfde258394338a Mon Sep 17 00:00:00 2001 From: Dmitrii Kovanikov Date: Fri, 24 Mar 2023 09:23:55 +0000 Subject: [PATCH] Replace 'colourista' with 'pretty-terminal' (#118) --- examples/simple-grep/README.md | 10 +++++----- examples/simple-grep/simple-grep.cabal | 2 +- src/Iris/Colour/Formatting.hs | 16 ++++++++-------- stack.yaml | 3 --- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/examples/simple-grep/README.md b/examples/simple-grep/README.md index d5458a3..4ea7a0c 100644 --- a/examples/simple-grep/README.md +++ b/examples/simple-grep/README.md @@ -23,7 +23,7 @@ When run, you can expect to see output similar to the following: Our simple example uses the following Haskell packages: * `base`: the Haskell standard library -* `colourista`: a terminal output colouring library +* `pretty-terminal`: a terminal output colouring library * `iris`: a Haskell CLI framework * `mtl`: a library with monad transformers * `text`: a library with the efficient `Text` type @@ -69,13 +69,13 @@ import Control.Monad.Reader (MonadReader) import Data.Foldable (traverse_) import Data.Text (Text) -import qualified Colourista import qualified Data.Text as Text import qualified Data.Text.IO as Text import qualified Options.Applicative as Opt +import qualified System.Console.Pretty as Pretty ``` -> We're writing a simple grep utility, we need here the `colourista` library for +> We're writing a simple grep utility, we need here the `pretty-terminal` library for > printing colored messages. Other libraries such as `text` are standard for any > CLI tool. `optparse-applicative` is needed here for defining the set of > commands that Iris will consume. @@ -282,7 +282,7 @@ add a few more requirements to our output: `stderr`. 2. Line numbers should be coloured and bold. -We're going to use `colourista` for colouring. Iris provides helper functions +We're going to use `pretty-terminal` for colouring. Iris provides helper functions for handling terminal colouring support and printing coloured output. Writing this in the code: @@ -298,7 +298,7 @@ output = traverse_ outputLine outputLineNumber :: Int -> App () outputLineNumber i = Iris.putStderrColoured - (Colourista.formatWith [Colourista.yellow, Colourista.bold]) + (Pretty.color Pretty.Yellow . Pretty.style Pretty.Bold) (Text.pack (show i) <> ": ") ``` diff --git a/examples/simple-grep/simple-grep.cabal b/examples/simple-grep/simple-grep.cabal index 1a1fc59..db573d3 100644 --- a/examples/simple-grep/simple-grep.cabal +++ b/examples/simple-grep/simple-grep.cabal @@ -46,10 +46,10 @@ executable simple-grep build-depends: , base - , colourista , iris , mtl , optparse-applicative + , pretty-terminal , text build-tool-depends: markdown-unlit:markdown-unlit diff --git a/src/Iris/Colour/Formatting.hs b/src/Iris/Colour/Formatting.hs index 0f873d7..db36016 100644 --- a/src/Iris/Colour/Formatting.hs +++ b/src/Iris/Colour/Formatting.hs @@ -33,11 +33,11 @@ import qualified Data.Text.IO as TIO {- | Print 'Text' to 'System.IO.stdout' by providing a custom formatting function. -This works especially well with the @colourista@ package: +This works especially well with the @pretty-terminal@ package: @ 'putStdoutColouredLn' - (Colourista.formatWith [Colourista.bold, Colourista.green]) + (style Bold . color Green) "my message" @ @@ -59,11 +59,11 @@ putStdoutColouredLn formatWithColour str = do {- | Print 'Text' to 'System.IO.stderr' by providing a custom formatting function. -This works especially well with the @colourista@ package: +This works especially well with the @pretty-terminal@ package: @ 'putStderrColouredLn' - (Colourista.formatWith [Colourista.bold, Colourista.green]) + (style Bold . color Green) "my message" @ @@ -86,11 +86,11 @@ putStderrColouredLn formatWithColour str = do formatting function. Doesn't breaks output line that differs from `putStdoutColouredLn` -This works especially well with the @colourista@ package: +This works especially well with the @pretty-terminal@ package: @ 'putStdoutColoured' - (Colourista.formatWith [Colourista.bold, Colourista.green]) + (style Bold . color Green) "my message" @ @@ -113,11 +113,11 @@ putStdoutColoured formatWithColour str = do formatting function. Doesn't breaks output line that differs from `putStderrColouredLn` -This works especially well with the @colourista@ package: +This works especially well with the @pretty-terminal@ package: @ 'putStderrColoured' - (Colourista.formatWith [Colourista.bold, Colourista.green]) + (style Bold . color Green) "my message" @ diff --git a/stack.yaml b/stack.yaml index f4e23c1..6c9b67d 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,4 +1 @@ resolver: lts-20.5 - -extra-deps: - - colourista-0.1.0.2