escape-artist 1.0.0 → 1.1.0
raw patch · 5 files changed
+119/−15 lines, 5 filesdep ~basedep ~bytestringdep ~textPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base, bytestring, text
API changes (from Hackage documentation)
Files
- escape-artist.cabal +33/−12
- src/Text/EscapeArtist.hs +6/−2
- src/Text/EscapeArtist/Internal.hs +13/−1
- test/Text/EscapeArtistSpec/TestData.hs +5/−0
- test/VisualTest.hs +62/−0
escape-artist.cabal view
@@ -1,8 +1,8 @@ name: escape-artist-version: 1.0.0+version: 1.1.0 synopsis: ANSI Escape Sequence Text Decoration Made Easy description:- A library for text decoration with ANSI escape sequences made easy. Decorate your terminal text easily and expressively.+ A library for text decoration with ANSI escape sequences made easy. Decorate your terminal text expressively. Any complex data type, existing or custom, can be simply colorized by implementing the class 'ToEscapable', then output to terminal or converted to 'String' using the provided functions. .@@ -36,6 +36,9 @@   toEscapable a = FgRed $ show a @ .+ NOTE: For GHC < 7.10 you will also need to explicitly derive 'Typeable' for custom data types+ implementing 'ToEscapable'. See the section Explicitly Derived Typeable in the documentation.+ . Comprehensive Documentation . See comprehensive documentation with many examples here:@@ -57,28 +60,46 @@ exposed-modules: Text.EscapeArtist , Text.EscapeArtist.Internal , Text.EscapeArtist.Internal.Constants- default-extensions: ExistentialQuantification, ExtendedDefaultRules, FlexibleInstances, NoMonomorphismRestriction- build-depends: base >= 4.7 && < 5- , bytestring >= 0.10.8.1 && < 0.11- , text >= 1.2.2.1 && < 1.3- ghc-options:+ default-extensions: CPP, ExistentialQuantification, ExtendedDefaultRules, FlexibleInstances, NoMonomorphismRestriction+ if impl(ghc < 7.10.0)+ default-extensions: DeriveDataTypeable, StandaloneDeriving+ build-depends: base >= 4.7.0.2 && < 5+ , bytestring >= 0.10.4.0 && < 0.11+ , text >= 1.2.0.4 && < 1.3+ ghc-options: -Wall default-language: Haskell2010 -test-suite escape-artist-test+test-suite escape-artist-spec-test type: exitcode-stdio-1.0 hs-source-dirs: test other-modules: Text.EscapeArtistSpec , Text.EscapeArtistSpec.TestData main-is: Spec.hs- build-depends: base >= 4.7 && < 5- , bytestring >= 0.10.8.1 && < 0.11+ build-depends: base >= 4.7.0.2 && < 5+ , bytestring >= 0.10.4.0 && < 0.11 , escape-artist , hspec >= 2.2.4 && < 2.3 , silently >= 1.2.5 && < 1.3- , text >= 1.2.2.1 && < 1.3+ , text >= 1.2.0.4 && < 1.3 , QuickCheck >= 2.9.2 && < 2.10 ghc-options: -threaded -rtsopts -with-rtsopts=-N- default-extensions: ExistentialQuantification, ExtendedDefaultRules, FlexibleInstances, NoMonomorphismRestriction+ default-extensions: CPP, ExistentialQuantification, ExtendedDefaultRules, FlexibleInstances, NoMonomorphismRestriction+ if impl(ghc < 7.10.0)+ default-extensions: DeriveDataTypeable, StandaloneDeriving+ default-language: Haskell2010++test-suite escape-artist-visual-test+ type: exitcode-stdio-1.0+ hs-source-dirs: test+ main-is: VisualTest.hs+ build-depends: base >= 4.7.0.2 && < 5+ , bytestring >= 0.10.4.0 && < 0.11+ , escape-artist+ , text >= 1.2.0.4 && < 1.3+ ghc-options: -threaded -rtsopts -with-rtsopts=-N+ default-extensions: CPP, ExtendedDefaultRules, NoMonomorphismRestriction+ if impl(ghc < 7.10.0)+ default-extensions: DeriveDataTypeable, StandaloneDeriving default-language: Haskell2010 source-repository head
src/Text/EscapeArtist.hs view
@@ -7,7 +7,7 @@ Stability : stable Portability : Terminal supporting ANSI escape sequences -A library for text decoration with ANSI escape sequences made easy. Decorate your terminal text easily and expressively.+A library for text decoration with ANSI escape sequences made easy. Decorate your terminal text expressively. Any complex data type, existing or custom, can be simply colorized by implementing the class 'ToEscapable', then output to terminal or converted to 'String' using the provided functions. @@ -45,7 +45,11 @@ See the documentation on 'ToEscapable' below for a more advanced example. -See comprehensive documentation with many examples here:+For GHC < 7.10 you will also need to explicitly derive 'Data.Typeable.Typeable' for custom data types+implementing 'ToEscapable'. See the section __/Explicitly Derived Typeable/__ in the+<https://github.com/EarthCitizen/escape-artist#explicitly-derived-typeable documentation>.++Comprehensive documentation with many examples here: <https://github.com/EarthCitizen/escape-artist#readme> -}
src/Text/EscapeArtist/Internal.hs view
@@ -2,6 +2,10 @@ module Text.EscapeArtist.Internal (Escapable(..), ToEscapable(..), putEscLn, putEsc, escToString, (^$)) where +#if ! MIN_VERSION_base(4,8,0)+import Data.Monoid (Monoid, mappend, mconcat, mempty)+#endif+ import Control.Applicative ((<|>)) import qualified Data.ByteString as BS import qualified Data.ByteString.Char8 as BSC@@ -71,6 +75,10 @@ | Sum [Escapable] | Atom String +#if ! MIN_VERSION_base(4,8,0)+deriving instance Typeable Escapable+#endif+ instance Show Escapable where show (FgBlack a) = "FgBlack (" ++ show a ++ ")" show (FgRed a) = "FgRed (" ++ show a ++ ")"@@ -107,7 +115,7 @@ show (Sum a) = "Sum " ++ show a show (Atom a) = "Atom " ++ show a -tryCast :: forall a b. (Show b, Typeable a, Typeable b) => a -> (b -> String) -> Maybe String+tryCast :: forall a b. (Typeable a, Typeable b) => a -> (b -> String) -> Maybe String tryCast a f = case cast a of (Just s) -> Just $ f s _ -> Nothing@@ -221,6 +229,10 @@ putEscLn $ mkSyntaxError "some/File.hs" 1 23 putEscLn mkStatusOK @++/Note:/ For GHC < 7.10 you will also need to explicitly derive 'Data.Typeable.Typeable' for custom data types+implementing 'ToEscapable'. See the section __/Explicitly Derived Typeable/__ in the+<https://github.com/EarthCitizen/escape-artist#explicitly-derived-typeable documentation>. <<https://raw.githubusercontent.com/EarthCitizen/escape-artist/master/images/either_error.png>> -}
test/Text/EscapeArtistSpec/TestData.hs view
@@ -16,6 +16,7 @@ import qualified Data.ByteString.Lazy.Char8 as BSLC import qualified Data.Text as T import qualified Data.Text.Lazy as TL+import Data.Typeable (Typeable) import Data.Word import Text.EscapeArtist.Internal import Text.EscapeArtist.Internal.Constants@@ -120,6 +121,10 @@ -- Other types of ToEscapable tests data SomeToEscapable = A deriving (Show)++#if ! MIN_VERSION_base(4,8,0)+deriving instance Typeable SomeToEscapable+#endif instance ToEscapable SomeToEscapable where toEscapable (A) = FgRed $ "A"
+ test/VisualTest.hs view
@@ -0,0 +1,62 @@+{-# LANGUAGE ExtendedDefaultRules, NoMonomorphismRestriction #-}++import Data.Monoid ((<>))+import Text.EscapeArtist+import Data.List (intersperse)+-- import Text.Regex++main = do+ putStrLn "Foreground Colors"+ putStrLn "================="+ putEscLn $ BgWhite $ FgBlack "Foreground should be black"+ putEscLn $ BgWhite $ FgRed "Foreground should be red"+ putEscLn $ BgWhite $ FgGreen "Foreground should be green"+ putEscLn $ BgWhite $ FgYellow "Foreground should be yellow"+ putEscLn $ BgWhite $ FgBlue "Foreground should be blue"+ putEscLn $ BgWhite $ FgMagenta "Foreground should be magenta"+ putEscLn $ BgWhite $ FgCyan "Foreground should be cyan"+ putEscLn $ BgBlack $ FgWhite "Foreground should be white"+ putStrLn ""+ putStrLn "Background Colors"+ putStrLn "================="+ putEscLn $ BgBlack $ FgWhite "Background should be black"+ putEscLn $ BgRed $ FgBlack "Background should be red"+ putEscLn $ BgGreen $ FgBlack "Background should be green"+ putEscLn $ BgYellow $ FgBlack "Background should be yellow"+ putEscLn $ BgBlue $ FgBlack "Background should be blue"+ putEscLn $ BgMagenta $ FgBlack "Background should be magenta"+ putEscLn $ BgCyan $ FgBlack "Background should be cyan"+ putEscLn $ BgWhite $ FgBlack "Background should be white"+ putStrLn ""+ putStrLn "FgDefault Colors"+ putStrLn "=============="+ putEscLn $ FgRed "-->" <> FgDefault "Foreground should be the default of the terminal" <> FgRed "<--"+ putEscLn $ (BgBlue $ FgWhite "-->") <> BgDefault "Background should be the default of the terminal" <> (BgBlue $ FgWhite "<--")+ putStrLn ""+ putStrLn "Inherit"+ putStrLn "========="+ putEscLn $ Underline $ BgWhite $ FgBlue $ ((UnderlineOff $ BgBlack $ FgWhite "-->") <> Inherit "This should be underlined, white background and blue foreground" <> (UnderlineOff $ BgBlack $ FgWhite "<---"))+ putStrLn ""+ putStrLn "Default"+ putStrLn "========="+ putEscLn $ Underline $ BgWhite $ FgBlue $ (Inherit "-->" <> Default "This should not have any attributes except for those from the terminal" <> Inherit "<---")+ putStrLn ""+ putStrLn "Blink and Blink Off"+ putStrLn "====================="+ putEscLn $ FgRed "This should not be blinking" <> Default " " <> Blink ^$ FgRed "This should be blinking"+ putEscLn $ Blink $ FgBlue $ BlinkOff "This should be not blinking from blink off" <> Default " " <> Inherit "This should be blinking"+ putStrLn ""+ putStrLn "Bright and Bright Off"+ putStrLn "====================="+ putEscLn $ FgRed "This should be dim" <> Inherit " " <> Bright ^$ FgRed "This should be bright"+ putEscLn $ Bright $ FgBlue $ BrightOff "This should be dim from bright off" <> Inherit " This should be bright"+ putStrLn ""+ putStrLn "Underline and Underline Off"+ putStrLn "==========================="+ putEscLn $ FgRed "This should not be underlined" <> Inherit " " <> Underline ^$ FgRed "This should be underlined"+ putEscLn $ Underline $ FgBlue $ UnderlineOff "This should not be underlined from underline off" <> Default " " <> Inherit "This should be underlined"+ putStrLn ""+ putStrLn "Inverse and Inverse Off"+ putStrLn "==========================="+ putEscLn $ FgRed "This should be inverse" <> Default " " <> Inverse ^$ FgRed "This should be inverse"+ putEscLn $ Inverse $ FgBlue $ InverseOff "This should not be inverse from inverse off" <> Default " " <> Inherit "This should be inverse"