packages feed

colorful-monoids 0.1.0.0 → 0.1.0.1

raw patch · 5 files changed

+61/−35 lines, 5 filesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ Data.Monoid.Colorful: (<>) :: Semigroup a => a -> a -> a
+ Data.Monoid.Colorful.Flat: (<>) :: Semigroup a => a -> a -> a

Files

colorful-monoids.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack  name:           colorful-monoids-version:        0.1.0.0+version:        0.1.0.1 synopsis:       Styled console text output using ANSI escape sequences. description:    Styled console text output using ANSI escape sequences. category:       Text, User Interfaces, Monad
example.hs view
@@ -4,7 +4,6 @@ import Data.Monoid.Colorful import Data.Foldable import Text.Printf-import Data.Monoid ((<>))  ansiColors :: [Color] ansiColors = [ DefaultColor@@ -31,14 +30,14 @@   term <- getTerm   printColoredS term $ Style Under $ Style Bold "ANSI Example\n"   for_ ansiColors $ \c -> do-    printColoredIO term $ Bg c $ Value $ printf "%-15s" $ show c-    printColoredIO term $ Fg c $ Value $ printf "%-15s" $ show c-    printColoredIO term $ Bg c $ Style Invert $ Value $ printf " %-15s" $ show c-    printColoredIO term $ Fg c $ Style Invert $ Value $ printf " %-15s" $ show c-    printColoredS term $ Bg c $ Value $ printf "%-15s" $ show c-    printColoredS term $ Fg c $ Value $ printf "%-15s" $ show c-    printColoredS term $ Bg c $ Style Invert $ Value $ printf " %-15s" $ show c-    printColoredS term $ Fg c $ Style Invert $ Value $ printf " %-15s" $ show c+    printColoredIO term $ Bg c (Value $ printf "%-15s" $ show c)+      <> Fg c (Value $ printf "%-15s" $ show c)+      <> Bg c (Style Invert $ Value $ printf " %-15s" $ show c)+      <> Fg c (Style Invert $ Value $ printf " %-15s" $ show c)+    printColoredS term $ Bg c (Value $ printf "%-15s" $ show c)+      <> Fg c (Value $ printf "%-15s" $ show c)+      <> Bg c (Style Invert $ Value $ printf " %-15s" $ show c)+      <> Fg c (Style Invert $ Value $ printf " %-15s" $ show c)     putChar '\n'  colors256Example :: IO ()@@ -46,10 +45,10 @@   term <- getTerm   printColoredS term $ Style Under $ Style Bold "Color256 Example\n"   for_ [0..255] $ \c -> do-    printColoredS term $ Bg (Color256 c) $ Value $ printf "%02x" c-    printColoredS term $ Fg (Color256 c) $ Value $ printf " %02x" c-    printColoredS term $ Bg (Color256 c) $ Style Invert $ Value $ printf " %02x" c-    printColoredS term $ Fg (Color256 c) $ Style Invert $ Value $ printf " %02x" c+    printColoredS term $ Bg (Color256 c) (Value $ printf "%02x" c)+      <> Fg (Color256 c) (Value $ printf " %02x" c)+      <> Bg (Color256 c) (Style Invert $ Value $ printf " %02x" c)+      <> Fg (Color256 c) (Style Invert $ Value $ printf " %02x" c)     putChar '\n'  rgbExample :: IO ()@@ -60,10 +59,10 @@     for_ [0,64..255] $ \g ->       for_ [0,64..255] $ \b -> do         let c = RGB r g b-        printColoredS term $ Bg c $ Value $ printf "%-20s" $ show c-        printColoredS term $ Fg c $ Value $ printf " %-20s" $ show c-        printColoredS term $ Bg c $ Style Invert $ Value $ printf " %-20s" $ show c-        printColoredS term $ Fg c $ Style Invert $ Value $ printf " %-20s" $ show c+        printColoredS term $ Bg c (Value $ printf "%-20s" $ show c)+          <> Fg c (Value $ printf " %-20s" $ show c)+          <> Bg c (Style Invert $ Value $ printf " %-20s" $ show c)+          <> Fg c (Style Invert $ Value $ printf " %-20s" $ show c)         putChar '\n'  specialExample :: IO ()@@ -80,8 +79,7 @@ stackExample :: IO () stackExample = do   term <- getTerm-  printColoredS term $ Style Under $ Style Bold "Stack Example\n"-  printColoredS term $ loop 0+  printColoredS term $ Style Under (Style Bold "Stack Example\n") <> loop 0   putChar '\n'   where     loop 8 = mempty@@ -94,10 +92,10 @@ basicExample :: IO () basicExample = do   term <- getTerm-  printColoredS term $ Style Under $ Style Bold "Basic Example\n"-  printColoredS term $ Style Bold "Bold"-  printColoredS term $ Style Italic $ Bg Red "Italic Red"-  printColoredS term $ Style Under "Under"+  printColoredS term $ Style Under (Style Bold "Basic Example\n")+    <> Style Bold "Bold"+    <> Style Italic (Bg Red "Italic Red")+    <> Style Under "Under"   putChar '\n'  reduceExample :: IO ()
src/Data/Monoid/Colorful.hs view
@@ -21,33 +21,44 @@ -- -- > basicExample :: IO () -- > basicExample = do--- >  term <- getTerm--- >  printColoredS term $ Style Under $ Style Bold "Basic Example\n"--- >  printColoredS term $ Style Bold "Bold"--- >  printColoredS term $ Style Italic $ Bg Red "Italic Red"--- >  printColoredS term $ Style Under "Under"--- >  putChar '\n'+-- >   term <- getTerm+-- >   printColoredS term $ Style Under (Style Bold "Basic Example\n")+-- >     <> Style Bold "Bold"+-- >     <> Style Italic (Bg Red "Italic Red")+-- >     <> Style Under "Under"+-- >   putChar '\n' -- -- For many more examples, see the--- <https://github.com/minad/colored-monoids/blob/master/example.hs example.hs> file.+-- <https://github.com/minad/colorful-monoids/blob/master/example.hs example.hs> file. -----------------------------------------------------------  module Data.Monoid.Colorful (-  Style(..)+  -- * The Monoid+  Colored(..)+  , Style(..)   , Color(..)++  -- * Terminal type   , Term(..)-  , Colored(..)   , hGetTerm   , getTerm++  -- ** Colorful printing to file handle   , hPrintColored   , printColored   , hPrintColoredIO   , printColoredIO   , hPrintColoredS   , printColoredS++  -- ** Show with ANSI escape sequences   , showColored   , showColoredA   , showColoredS++  -- * Reexport from Data.Semigroup+  , (<>) ) where  import Data.Monoid.Colorful.Nested+import Data.Semigroup ((<>))
src/Data/Monoid/Colorful/Flat.hs view
@@ -22,21 +22,31 @@ {-# LANGUAGE DeriveGeneric #-}  module Data.Monoid.Colorful.Flat (-  Style(..)+  -- * Colored datatypes+  Colored(..)+  , Style(..)   , Color(..)++  -- * Terminal type   , Term(..)-  , Colored(..)   , hGetTerm   , getTerm++  -- ** Colorful printing to file handle   , hPrintColored   , printColored   , hPrintColoredIO   , printColoredIO   , hPrintColoredS   , printColoredS++  -- ** Show with ANSI escape sequences   , showColored   , showColoredA   , showColoredS++  -- * Reexport from Data.Semigroup+  , (<>) ) where  import System.IO (Handle, stdout, hPutStr)@@ -47,6 +57,7 @@ import Data.Functor.Identity import Data.Bifunctor (first, second) import GHC.Generics (Generic, Generic1)+import Data.Semigroup ((<>))  data Colored a   = Value a
src/Data/Monoid/Colorful/Nested.hs view
@@ -33,6 +33,7 @@ import qualified Data.Monoid.Colorful.Flat as Flat import Control.Monad (ap) +-- | Colored Monoid data Colored a   = Nil   | Value a@@ -43,10 +44,12 @@   | Pair    (Colored a) (Colored a)   deriving (Eq, Ord, Show, Read, Functor, Foldable, Traversable, Generic, Generic1) +-- | Free monad! instance Applicative Colored where   pure = Value   (<*>) = ap +-- | Free monad! instance Monad Colored where   Nil         >>= _ = Nil   Value     x >>= f = f x@@ -69,6 +72,9 @@   fromList = foldr Pair Nil   toList   = (:[]) -- TODO, invalid +-- | Flatten the Monoid @Colored a@ and return @[Flat.Colored a]@+--+-- This function is used internally for rendering the Colored monoids. flatten :: Colored a -> [Flat.Colored a] flatten s = go s []   where go (Value   a)      = (Flat.Value a:)