colourista 0.0.0.0 → 0.1.0.0
raw patch · 6 files changed
+164/−16 lines, 6 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
+ Colourista.Pure: doubleUnderline :: IsString str => str
+ Colourista.Pure: indent :: (IsString str, Semigroup str) => Int -> str
+ Colourista.Pure: noUnderline :: IsString str => str
+ Colourista.Pure: underline :: IsString str => str
+ Colourista.Short: b :: (IsString str, Semigroup str) => str -> str
+ Colourista.Short: i :: (IsString str, Semigroup str) => str -> str
+ Colourista.Short: u :: (IsString str, Semigroup str) => str -> str
Files
- CHANGELOG.md +14/−0
- README.md +21/−0
- colourista.cabal +8/−3
- src/Colourista/IO.hs +31/−12
- src/Colourista/Pure.hs +44/−1
- src/Colourista/Short.hs +46/−0
CHANGELOG.md view
@@ -3,6 +3,20 @@ `colourista` uses [PVP Versioning][1]. The changelog is available [on GitHub][2]. +## 0.1.0.0 — May 2, 2020 🌈++* [#22](https://github.com/kowainik/colourista/issues/22):+ Support GHC-8.10.+* [#27](https://github.com/kowainik/colourista/issues/27):+ Add unicode indicators to `*Message` functions.+* [#17](https://github.com/kowainik/colourista/issues/17):+ Add `indent` formatting function.+* [#7](https://github.com/kowainik/colourista/issues/7):+ Add `underline`, `doubleUnderline`, `noUnderline` formatting functions.+* [#28](https://github.com/kowainik/colourista/issues/28):+ Add `Colourista.Short` with short aliases for `bold`, `italic` and+ `underline`.+ ## 0.0.0.0 — Feb 16, 2020 🌈 * Initially created.
README.md view
@@ -62,6 +62,27 @@ main :: IO () main = successMessage "All set up!" ```+### Usage with Stack++If `colourista` is not available on your current Stackage resolver yet, fear not! You can still use+it from Hackage by adding the following to the `extra-deps` section of your `stack.yaml`+file:++```yaml+extra-deps:+ - colourista-0.0.0.0+ - ansi-terminal-0.10+```++Then you can add it as a dependency in your `package.yaml` file as usual:++```yaml+library:+ dependencies:+ - colourista+```++Great! ## Acknowledgement
colourista.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: colourista-version: 0.0.0.0+version: 0.1.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@@ -17,7 +17,8 @@ tested-with: GHC == 8.2.2 GHC == 8.4.4 GHC == 8.6.5- GHC == 8.8.2+ GHC == 8.8.3+ GHC == 8.10.1 source-repository head type: git@@ -28,8 +29,9 @@ exposed-modules: Colourista Colourista.IO Colourista.Pure+ Colourista.Short - build-depends: base >= 4.10.1.0 && < 4.14+ build-depends: base >= 4.10.1.0 && < 4.15 , ansi-terminal ^>= 0.10 , bytestring ^>= 0.10 , text ^>= 1.2.3.0@@ -44,10 +46,13 @@ if impl(ghc >= 8.8.1) ghc-options: -Wmissing-deriving-strategies -Werror=missing-deriving-strategies+ if impl(ghc >= 8.10.1)+ ghc-options: -Wunused-packages default-language: Haskell2010 default-extensions: ConstraintKinds DeriveGeneric+ DerivingStrategies GeneralizedNewtypeDeriving InstanceSigs KindSignatures
src/Colourista/IO.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ {- | Copyright: (c) 2020 Kowainik SPDX-License-Identifier: MPL-2.0@@ -17,7 +19,7 @@ , whiteMessage , magentaMessage , cyanMessage- -- ** Aliases+ -- ** Aliases with unicode indicators , successMessage , infoMessage , skipMessage@@ -30,7 +32,9 @@ , formattedMessage ) where -import Data.Semigroup ((<>))+#if __GLASGOW_HASKELL__ < 804+import Data.Semigroup (Semigroup (..))+#endif import Data.Text (Text) import qualified Data.Text.IO as TIO@@ -85,29 +89,44 @@ -- Informative aliases ---------------------------------------------------------------------------- --- | Alias for 'greenMessage' that specifies message severity.+{- | Similar to 'greenMessage', but add unicode indicator.++<<https://user-images.githubusercontent.com/4276606/80867598-dbd99000-8c8c-11ea-9fac-81a1a606d8d8.png Success message>>+-} successMessage :: Text -> IO ()-successMessage = greenMessage+successMessage t = greenMessage $ " ✔ " <> t {-# INLINE successMessage #-} --- | Alias for 'blueMessage' that specifies message severity.+{- | 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 = blueMessage+infoMessage t = blueMessage $ " ⓘ " <> t {-# INLINE infoMessage #-} --- | Alias for 'cyanMessage' that specifies message severity.+{- | 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 = cyanMessage+skipMessage t = cyanMessage $ " ▶ " <> t {-# INLINE skipMessage #-} --- | Alias for 'yellowMessage' that specifies message severity.+{- | 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 = yellowMessage+warningMessage t = yellowMessage $ " ⚠ " <> t {-# INLINE warningMessage #-} --- | Alias for 'redMessage' that specifies message severity.+{- | 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 = redMessage+errorMessage t = redMessage $ " \128721 " <> t {-# INLINE errorMessage #-} ----------------------------------------------------------------------------
src/Colourista/Pure.hs view
@@ -31,6 +31,10 @@ -- * Emphasis , bold , italic+ , underline+ , doubleUnderline+ , noUnderline+ , indent -- * Reset , reset@@ -42,7 +46,8 @@ import Data.String (IsString (..)) import Data.Text (Text) import System.Console.ANSI (Color (..), ColorIntensity (Vivid), ConsoleIntensity (BoldIntensity),- ConsoleLayer (Background, Foreground), SGR (..), setSGRCode)+ ConsoleLayer (Background, Foreground), SGR (..), Underlining (..),+ setSGRCode) {- | General purpose function to format strings with multiple@@ -57,6 +62,10 @@ 4. Italicized yellow on cyan background: @'formatWith' ['italic', 'yellow', 'cyanBg'] myString@ ++__⚠ Caution:__ Double underlining 'doubleUnderline' is not widely supported.+It is also not natively supported on Windows 10.+ -} formatWith :: (IsString str, Semigroup str)@@ -207,6 +216,40 @@ {-# SPECIALIZE italic :: String #-} {-# SPECIALIZE italic :: Text #-} {-# SPECIALIZE italic :: ByteString #-}++-- | Code to apply __underline__ emphasis for the terminal output.+underline :: IsString str => str+underline = fromString $ setSGRCode [SetUnderlining SingleUnderline]+{-# SPECIALIZE underline :: String #-}+{-# SPECIALIZE underline :: Text #-}+{-# SPECIALIZE underline :: ByteString #-}++{- | Code to apply __double underline__ emphasis for the terminal output.++__⚠ Caution:__ This is not widely supported. It is not natively supported on+Windows 10+-}+doubleUnderline :: IsString str => str+doubleUnderline = fromString $ setSGRCode [SetUnderlining DoubleUnderline]+{-# SPECIALIZE doubleUnderline :: String #-}+{-# SPECIALIZE doubleUnderline :: Text #-}+{-# SPECIALIZE doubleUnderline :: ByteString #-}++-- | Code to apply __no underline__ emphasis for the terminal output.+noUnderline :: IsString str => str+noUnderline = fromString $ setSGRCode [SetUnderlining NoUnderline]+{-# SPECIALIZE noUnderline :: String #-}+{-# SPECIALIZE noUnderline :: Text #-}+{-# SPECIALIZE noUnderline :: ByteString #-}++-- | Code to indent the terminal output by the given amount of spaces.+indent :: (IsString str, Semigroup str) => Int -> str+indent n+ | n <= 0 = ""+ | otherwise = stimes n " "+{-# SPECIALIZE indent :: Int -> String #-}+{-# SPECIALIZE indent :: Int -> Text #-}+{-# SPECIALIZE indent :: Int -> ByteString #-} -- | Code to reset all previous code applied for the terminal output. reset :: IsString str => str
+ src/Colourista/Short.hs view
@@ -0,0 +1,46 @@+{-# LANGUAGE CPP #-}++{- |+Copyright: (c) 2020 Kowainik+SPDX-License-Identifier: MPL-2.0+Maintainer: Kowainik <xrom.xkov@gmail.com>++This module contains short aliases for most frequently used pure functions.+-}++module Colourista.Short+ ( b+ , i+ , u+ ) where++import Data.ByteString (ByteString)+#if __GLASGOW_HASKELL__ < 804+import Data.Semigroup (Semigroup)+#endif+import Data.String (IsString)+import Data.Text (Text)++import Colourista.Pure (bold, formatWith, italic, underline)+++-- | Short alias for 'bold'.+b :: (IsString str, Semigroup str) => str -> str+b = formatWith [bold]+{-# SPECIALIZE b :: String -> String #-}+{-# SPECIALIZE b :: Text -> Text #-}+{-# SPECIALIZE b :: ByteString -> ByteString #-}++-- | Short alias for 'italic'.+i :: (IsString str, Semigroup str) => str -> str+i = formatWith [italic]+{-# SPECIALIZE i :: String -> String #-}+{-# SPECIALIZE i :: Text -> Text #-}+{-# SPECIALIZE i :: ByteString -> ByteString #-}++-- | Short alias for 'underline'.+u :: (IsString str, Semigroup str) => str -> str+u = formatWith [underline]+{-# SPECIALIZE u :: String -> String #-}+{-# SPECIALIZE u :: Text -> Text #-}+{-# SPECIALIZE u :: ByteString -> ByteString #-}