packages feed

rainbow 0.30.0.2 → 0.32.0.0

raw patch · 9 files changed

+136/−118 lines, 9 files

Files

LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2013-2014, Omari Norman+Copyright (c) 2013-2019 Omari Norman  All rights reserved. 
lib/Rainbow.hs view
@@ -136,7 +136,9 @@   -- colors, use 'T.chunksToByteStrings' with 'T.toByteStringsColors0',   -- 'T.toByteStringsColors8', or 'T.toByteStringsColors256' as the first   -- argument.  'T.chunksToByteStrings' has an example.-  , T.Renderable+  --+  -- For output to handles or to standard output, just use+  -- 'T.hPutChunks' or 'T.putChunks'.   , T.toByteStringsColors0   , T.toByteStringsColors8   , T.toByteStringsColors256@@ -144,6 +146,10 @@   , T.byteStringMakerFromHandle   , T.chunksToByteStrings +  -- * Writing 'Y.Chunk' to a handle or to standard output+  , T.putChunks+  , T.hPutChunks+   -- * Quick and dirty functions for IO    -- | For efficiency reasons you probably don't want to use these@@ -152,13 +158,6 @@   , T.putChunk   , T.putChunkLn -  -- * Re-exports-  -- $reexports-  , module Data.Function-  , module Data.Word-  , module Data.ByteString-  , module Data.Monoid-   -- * Notes on terminals   -- $termNotes @@ -167,13 +166,12 @@ import qualified Rainbow.Translate as T import qualified Rainbow.Types as Y import Data.Word (Word8)-import Data.ByteString (ByteString) import Data.Function ((&)) import qualified Lens.Simple as Lens import Lens.Simple ((.~))-import Data.Monoid (Monoid(mempty), (<>))+import Data.Monoid (Monoid(mempty)) -formatBoth :: Lens.Setter' Y.Format Bool -> Y.Chunk a -> Y.Chunk a+formatBoth :: Lens.Setter' Y.Format Bool -> Y.Chunk -> Y.Chunk formatBoth get c = c & Y.scheme . Y.style8 . Y.format . get .~ True   & Y.scheme . Y.style256 . Y.format . get .~ True @@ -186,37 +184,37 @@ -- -- If your terminal uses a different color for bold, this allows an -- 8-color terminal to really have 16 colors.-bold :: Y.Chunk a -> Y.Chunk a+bold :: Y.Chunk -> Y.Chunk bold = formatBoth Y.bold -faint :: Y.Chunk a -> Y.Chunk a+faint :: Y.Chunk -> Y.Chunk faint = formatBoth Y.faint -italic :: Y.Chunk a -> Y.Chunk a+italic :: Y.Chunk -> Y.Chunk italic = formatBoth Y.italic -underline :: Y.Chunk a -> Y.Chunk a+underline :: Y.Chunk -> Y.Chunk underline = formatBoth Y.underline -blink :: Y.Chunk a -> Y.Chunk a+blink :: Y.Chunk -> Y.Chunk blink = formatBoth Y.blink -inverse :: Y.Chunk a -> Y.Chunk a+inverse :: Y.Chunk -> Y.Chunk inverse = formatBoth Y.inverse -invisible :: Y.Chunk a -> Y.Chunk a+invisible :: Y.Chunk -> Y.Chunk invisible = formatBoth Y.invisible -strikeout :: Y.Chunk a -> Y.Chunk a+strikeout :: Y.Chunk -> Y.Chunk strikeout = formatBoth Y.strikeout  -- | Change the foreground color for both 8- and 256-color terminals.-fore :: Y.Radiant -> Y.Chunk a -> Y.Chunk a+fore :: Y.Radiant -> Y.Chunk -> Y.Chunk fore (Y.Radiant c8 c256) c = c & Y.scheme . Y.style8 . Y.fore .~ c8   & Y.scheme . Y.style256 . Y.fore .~ c256  -- | Change the background color for both 8- and 256-color terminals.-back :: Y.Radiant -> Y.Chunk a -> Y.Chunk a+back :: Y.Radiant -> Y.Chunk -> Y.Chunk back (Y.Radiant c8 c256) c = c & Y.scheme . Y.style8 . Y.back .~ c8   & Y.scheme . Y.style256 . Y.back .~ c256 @@ -282,18 +280,6 @@ color256 :: Word8 -> Y.Radiant color256 x = Y.Radiant (Y.Color Nothing) (Y.Color (Just x)) --{- $reexports--   * "Data.Function" re-exports '&'--   * "Data.Monoid" re-exports 'Monoid', '<>' and 'mempty'--   * "Data.ByteString" re-exports 'ByteString'--   * "Data.Word" re-exports 'Word8'---}  {- $termNotes 
lib/Rainbow/Translate.hs view
@@ -7,10 +7,8 @@  import qualified Data.ByteString.Char8 as BS8 import qualified Data.ByteString as BS-import qualified Data.ByteString.Lazy as BSL-import qualified Data.Text as X+import Data.Text (Text) import qualified Data.Text.Encoding as X-import qualified Data.Text.Lazy as XL import Data.ByteString (ByteString) import Data.Word (Word8) import Data.List (intersperse)@@ -23,31 +21,6 @@ import qualified System.IO as IO  --- | Items that can be rendered.  'render' returns a difference list.-class Renderable a where-  render :: a -> [ByteString] -> [ByteString]---- | Converts a strict Text to a UTF-8 ByteString.-instance Renderable X.Text where-  render x = (X.encodeUtf8 x :)---- | Converts a lazy Text to UTF-8 ByteStrings.-instance Renderable XL.Text where-  render = foldr (.) id . map render . XL.toChunks---- | Strict ByteString is left as-is.-instance Renderable BS.ByteString where-  render x = (x :)---- | Lazy ByteString is converted to strict chunks.-instance Renderable BSL.ByteString where-  render x = (BSL.toChunks x ++)---- | Strings are converted first to a strict Text and then to a strict--- ByteString.-instance Renderable String where-  render x = ((X.encodeUtf8 . X.pack $ x):)- single :: Char -> [ByteString] -> [ByteString] single c = ((BS8.singleton c):) @@ -216,16 +189,17 @@   where     effect on (T.Color may) = maybe id on may +render :: Text -> [ByteString] -> [ByteString]+render x = (X.encodeUtf8 x :)+ toByteStringsColors0-  :: Renderable a-  => T.Chunk a+  :: T.Chunk   -> [ByteString]   -> [ByteString] toByteStringsColors0 (T.Chunk _ yn) = render yn  toByteStringsColors8-  :: Renderable a-  => T.Chunk a+  :: T.Chunk   -> [ByteString]   -> [ByteString] toByteStringsColors8 (T.Chunk (T.Scheme s8 _) yn)@@ -235,8 +209,7 @@   . normalDefault  toByteStringsColors256-  :: Renderable a-  => T.Chunk a+  :: T.Chunk   -> [ByteString]   -> [ByteString] toByteStringsColors256 (T.Chunk (T.Scheme _ s256) yn)@@ -246,7 +219,6 @@   . normalDefault  - -- | Spawns a subprocess to read the output of @tput colors@.  If this -- says there are at least 256 colors are available, returns -- 'toByteStringsColors256'.  Otherwise, if there are at least 8@@ -256,8 +228,7 @@ -- If any IO exceptions arise during this process, they are discarded -- and 'toByteStringsColors0' is returned. byteStringMakerFromEnvironment-  :: Renderable a-  => IO (T.Chunk a -> [ByteString] -> [ByteString])+  :: IO (T.Chunk -> [ByteString] -> [ByteString]) byteStringMakerFromEnvironment   = catcher (fmap f $ readProcessWithExitCode "tput" ["colors"] "")   where@@ -279,13 +250,12 @@         g (Right good) = good  -- | Like 'byteStringMakerFromEnvironment' but also consults a--- provided 'Handle'.  If the 'Handle' is not a terminal,+-- provided 'IO.Handle'.  If the 'IO.Handle' is not a terminal, -- 'toByteStringsColors0' is returned.  Otherwise, the value of -- 'byteStringMakerFromEnvironment' is returned. byteStringMakerFromHandle-  :: Renderable a-  => IO.Handle-  -> IO (T.Chunk a -> [ByteString] -> [ByteString])+  :: IO.Handle+  -> IO (T.Chunk -> [ByteString] -> [ByteString]) byteStringMakerFromHandle h = IO.hIsTerminalDevice h >>= f   where     f isTerm | isTerm = byteStringMakerFromEnvironment@@ -323,13 +293,32 @@ -- >     $ myChunks  chunksToByteStrings-  :: (T.Chunk a -> [ByteString] -> [ByteString])+  :: (T.Chunk -> [ByteString] -> [ByteString])   -- ^ Function that converts 'T.Chunk' to 'ByteString'.  This   -- function, when applied to a 'T.Chunk', returns a difference list.-  -> [T.Chunk a]+  -> [T.Chunk]   -> [ByteString] chunksToByteStrings mk = ($ []) . foldr (.) id . map mk +-- | Writes a list of chunks to the given 'IO.Handle'.+--+-- First uses 'byteStringMakerFromEnvironment' to determine how many+-- colors to use.  Then creates a list of 'ByteString' using+-- 'chunksToByteStrings' and then writes them to the given 'IO.Handle'.+hPutChunks :: IO.Handle -> [T.Chunk] -> IO ()+hPutChunks h cks = do+  maker <- byteStringMakerFromEnvironment+  let bsList = chunksToByteStrings maker cks+  mapM_ (BS.hPut h) bsList++-- | Writes a list of chunks to standard output.+--+-- First uses 'byteStringMakerFromEnvironment' to determine how many+-- colors to use.  Then creates a list of 'ByteString' using+-- 'chunksToByteStrings' and then writes them to standard output.+putChunks :: [T.Chunk] -> IO ()+putChunks = hPutChunks IO.stdout+ -- Quick and dirty I/O functions  -- | Writes a 'T.Chunk' to standard output.  Spawns a child process to@@ -338,7 +327,7 @@ -- any speed awards.  You are better off using 'chunksToByteStrings' -- and the functions in "Data.ByteString" to print your 'T.Chunk's if -- you are printing a lot of them.-putChunk :: Renderable a => T.Chunk a -> IO ()+putChunk :: T.Chunk -> IO () putChunk ck = do   mkr <- byteStringMakerFromEnvironment   mapM_ BS.putStr . chunksToByteStrings mkr $ [ck]@@ -350,5 +339,5 @@ -- better off using 'chunksToByteStrings' and the functions in -- "Data.ByteString" to print your 'T.Chunk's if you are printing a lot -- of them.-putChunkLn :: Renderable a => T.Chunk a -> IO ()+putChunkLn :: T.Chunk -> IO () putChunkLn ck = putChunk ck >> putStrLn ""
lib/Rainbow/Types.hs view
@@ -13,6 +13,9 @@ -- # Imports  import Lens.Simple (makeLenses)+import Data.String+import Data.Text (Text)+import qualified Data.Text as X import Data.Traversable () import Data.Typeable (Typeable) import Data.Word (Word8)@@ -186,26 +189,29 @@ -- colors and what attributes to use for both an 8 color terminal and -- a 256 color terminal. -data Chunk a = Chunk+data Chunk = Chunk   { _scheme :: Scheme-  , _yarn :: a-  } deriving (Eq, Show, Ord, Generic, Typeable, Functor,-              Foldable, Traversable)+  , _yarn :: Text+  } deriving (Eq, Show, Ord, Generic, Typeable) -instance Semigroup a => Semigroup (Chunk a) where+instance Semigroup Chunk where   (Chunk x0 x1) <> (Chunk y0 y1)     = Chunk (x0 <> y0) (x1 <> y1) --- | Uses the underlying 'Monoid' instances for the 'Style' and for+-- | Creates a 'Chunk' with no formatting and with the given text.+instance IsString Chunk where+  fromString = chunk . X.pack++-- | Uses the underlying 'Monoid' instances for the 'Scheme' and for -- the particular '_yarn'.  Therefore 'mempty' will have no formatting -- and no colors and will generally have no text, though whether or -- not there is any text depends on the 'mempty' for the type of the -- '_yarn'.-instance Monoid a => Monoid (Chunk a) where+instance Monoid Chunk where   mempty = Chunk mempty mempty  -- | Creates a 'Chunk' with no formatting and with the given text.-chunk :: a -> Chunk a+chunk :: Text -> Chunk chunk = Chunk mempty  makeLenses ''Chunk
rainbow.cabal view
@@ -1,11 +1,13 @@--- This file has been generated from package.yaml by hpack version 0.28.2.+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.31.2. -- -- see: https://github.com/sol/hpack ----- hash: 19c04a9948206d114b8a7bf305dcf3dbf8f4bbf8af474470ab5c37c4e23a1342+-- hash: a4425c1ecc287bdb359eb7e61890b889835d22f685b0da1e2379a4387dc5bb56  name:           rainbow-version:        0.30.0.2+version:        0.32.0.0 synopsis:       Print text to terminal with colors and effects description:    Please see README.md category:       System@@ -18,15 +20,21 @@ license:        BSD3 license-file:   LICENSE build-type:     Simple-cabal-version:  >= 1.10 extra-source-files:     README.md+    stack.yaml  source-repository head   type: git   location: https://github.com/massysett/rainbow  library+  exposed-modules:+      Rainbow+      Rainbow.Translate+      Rainbow.Types+  other-modules:+      Paths_rainbow   hs-source-dirs:       lib   other-extensions: TemplateHaskell@@ -37,17 +45,17 @@     , lens-simple     , process     , text-  exposed-modules:-      Rainbow-      Rainbow.Translate-      Rainbow.Types-  other-modules:-      Paths_rainbow   default-language: Haskell2010  test-suite colorTest   type: exitcode-stdio-1.0   main-is: colorTest.hs+  other-modules:+      Rainbow+      Rainbow.Translate+      Rainbow.Types+      Rainbow.QuickCheck+      Paths_rainbow   hs-source-dirs:       lib       tests@@ -60,17 +68,17 @@     , lens-simple     , process     , text+  default-language: Haskell2010++test-suite rainbow-instances+  type: exitcode-stdio-1.0+  main-is: rainbow-instances.hs   other-modules:       Rainbow       Rainbow.Translate       Rainbow.Types       Rainbow.QuickCheck       Paths_rainbow-  default-language: Haskell2010--test-suite rainbow-instances-  type: exitcode-stdio-1.0-  main-is: rainbow-instances.hs   hs-source-dirs:       lib       tests@@ -83,17 +91,17 @@     , lens-simple     , process     , text+  default-language: Haskell2010++test-suite test256color+  type: exitcode-stdio-1.0+  main-is: test256color.hs   other-modules:       Rainbow       Rainbow.Translate       Rainbow.Types       Rainbow.QuickCheck       Paths_rainbow-  default-language: Haskell2010--test-suite test256color-  type: exitcode-stdio-1.0-  main-is: test256color.hs   hs-source-dirs:       lib       tests@@ -106,17 +114,17 @@     , lens-simple     , process     , text+  default-language: Haskell2010++test-suite test8color+  type: exitcode-stdio-1.0+  main-is: test8color.hs   other-modules:       Rainbow       Rainbow.Translate       Rainbow.Types       Rainbow.QuickCheck       Paths_rainbow-  default-language: Haskell2010--test-suite test8color-  type: exitcode-stdio-1.0-  main-is: test8color.hs   hs-source-dirs:       lib       tests@@ -129,10 +137,4 @@     , lens-simple     , process     , text-  other-modules:-      Rainbow-      Rainbow.Translate-      Rainbow.Types-      Rainbow.QuickCheck-      Paths_rainbow   default-language: Haskell2010
+ stack.yaml view
@@ -0,0 +1,32 @@+# For more information, see: https://github.com/commercialhaskell/stack/blob/release/doc/yaml_configuration.md++# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2)+resolver: lts-14.14++# Local packages, usually specified by relative directory name+packages:+- '.'++# Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3)+extra-deps: []++# Override default flag values for local packages and extra-deps+flags: {}++# Extra package databases containing global packages+extra-package-dbs: []++# Control whether we use the GHC we find on the path+# system-ghc: true++# Require a specific version of stack, using version ranges+# require-stack-version: -any # Default+# require-stack-version: >= 0.1.4.0++# Override the architecture used by stack, especially useful on Windows+# arch: i386+# arch: x86_64++# Extra directories used by stack for building+# extra-include-dirs: [/path/to/dir]+# extra-lib-dirs: [/path/to/dir]
tests/colorTest.hs view
@@ -2,6 +2,7 @@  import Rainbow import qualified Data.ByteString as BS+import Data.Function ((&))  colors8 :: [(String, Radiant)] colors8 =
tests/test256color.hs view
@@ -1,6 +1,7 @@ module Main where  import Control.Arrow (second)+import Data.Function ((&)) import Rainbow import qualified Data.ByteString as BS 
tests/test8color.hs view
@@ -1,6 +1,7 @@ module Main where  import Control.Arrow (second)+import Data.Function ((&)) import Rainbow import qualified Data.ByteString as BS