text-ansi 0.1.0.1 → 0.1.0.2
raw patch · 6 files changed
+293/−191 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGELOG.md +4/−0
- Data/Text/ANSI.hs +284/−178
- README.md +3/−0
- cabal.project +0/−4
- cabal.project.freeze +0/−6
- text-ansi.cabal +2/−3
CHANGELOG.md view
@@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to the [Haskell Package Versioning Policy](https://pvp.haskell.org/). +## [0.1.0.2] - 2020-12-26+### Changed+- Fix bug in `italic`+ ## [0.1.0.1] - 2020-06-14 ### Changed
Data/Text/ANSI.hs view
@@ -5,66 +5,67 @@ ( -- $intro -- * Foreground color- black- , red- , green- , yellow- , blue- , magenta- , cyan- , white- , brightBlack- , brightRed- , brightGreen- , brightYellow- , brightBlue- , brightMagenta- , brightCyan- , brightWhite- , rgb+ black,+ red,+ green,+ yellow,+ blue,+ magenta,+ cyan,+ white,+ brightBlack,+ brightRed,+ brightGreen,+ brightYellow,+ brightBlue,+ brightMagenta,+ brightCyan,+ brightWhite,+ rgb, -- * Background color- , blackBg- , redBg- , greenBg- , yellowBg- , blueBg- , magentaBg- , cyanBg- , whiteBg- , brightBlackBg- , brightRedBg- , brightGreenBg- , brightYellowBg- , brightBlueBg- , brightMagentaBg- , brightCyanBg- , brightWhiteBg- , rgbBg+ blackBg,+ redBg,+ greenBg,+ yellowBg,+ blueBg,+ magentaBg,+ cyanBg,+ whiteBg,+ brightBlackBg,+ brightRedBg,+ brightGreenBg,+ brightYellowBg,+ brightBlueBg,+ brightMagentaBg,+ brightCyanBg,+ brightWhiteBg,+ rgbBg, -- * Style- , bold- , faint- , italic- , underline- , doubleUnderline- , strikethrough- , frame- , encircle- , overline- ) where+ bold,+ faint,+ italic,+ underline,+ doubleUnderline,+ strikethrough,+ frame,+ encircle,+ overline,+ )+where #if !MIN_VERSION_base(4,13,0) import Data.Semigroup ((<>)) #endif import Data.Text-import Data.Text.Lazy.Builder (Builder)-import Data.Word (Word8)-import Foreign.C (CInt(CInt))-import System.IO.Unsafe (unsafePerformIO) import qualified Data.Text.Lazy as Text.Lazy+import Data.Text.Lazy.Builder (Builder) import qualified Data.Text.Lazy.Builder as Builder import qualified Data.Text.Lazy.Builder.Int as Builder+import Data.Word (Word8)+import Foreign.C (CInt (CInt))+import System.IO.Unsafe (unsafePerformIO) -- $intro --@@ -79,201 +80,306 @@ -- Also features terminal detection, so redirecting styled output to a file will -- automatically strip the ANSI escape sequences. -{-# INLINABLE black #-}-{-# INLINABLE red #-}-{-# INLINABLE green #-}-{-# INLINABLE yellow #-}-{-# INLINABLE blue #-}-{-# INLINABLE magenta #-}-{-# INLINABLE cyan #-}-{-# INLINABLE white #-}-{-# INLINABLE brightBlack #-}-{-# INLINABLE brightRed #-}-{-# INLINABLE brightGreen #-}-{-# INLINABLE brightYellow #-}-{-# INLINABLE brightBlue #-}-{-# INLINABLE brightMagenta #-}-{-# INLINABLE brightCyan #-}-{-# INLINABLE brightWhite #-}-{-# INLINABLE blackBg #-}-{-# INLINABLE redBg #-}-{-# INLINABLE greenBg #-}-{-# INLINABLE yellowBg #-}-{-# INLINABLE blueBg #-}-{-# INLINABLE magentaBg #-}-{-# INLINABLE cyanBg #-}-{-# INLINABLE whiteBg #-}-{-# INLINABLE brightBlackBg #-}-{-# INLINABLE brightRedBg #-}-{-# INLINABLE brightGreenBg #-}-{-# INLINABLE brightYellowBg #-}-{-# INLINABLE brightBlueBg #-}-{-# INLINABLE brightMagentaBg #-}-{-# INLINABLE brightCyanBg #-}-{-# INLINABLE brightWhiteBg #-}--black, red, green, yellow, blue, magenta, cyan, white, brightBlack, brightRed,- brightGreen, brightYellow, brightBlue, brightMagenta, brightCyan,- brightWhite, blackBg, redBg, greenBg,- yellowBg, blueBg, magentaBg, cyanBg,- whiteBg, brightBlackBg, brightRedBg,- brightGreenBg, brightYellowBg, brightBlueBg,- brightMagentaBg, brightCyanBg,- brightWhiteBg :: Text -> Text- -- | Black foreground.-black = surround "30" "39"+black :: Text -> Text+black =+ foreground "30"+{-# INLINEABLE black #-}+ -- | Red foreground.-red = surround "31" "39"+red :: Text -> Text+red =+ foreground "31"+{-# INLINEABLE red #-}+ -- | Green foreground.-green = surround "32" "39"+green :: Text -> Text+green =+ foreground "32"+{-# INLINEABLE green #-}+ -- | Yellow foreground.-yellow = surround "33" "39"+yellow :: Text -> Text+yellow =+ foreground "33"+{-# INLINEABLE yellow #-}+ -- | Blue foreground.-blue = surround "34" "39"+blue :: Text -> Text+blue =+ foreground "34"+{-# INLINEABLE blue #-}+ -- | Magenta foreground.-magenta = surround "35" "39"+magenta :: Text -> Text+magenta =+ foreground "35"+{-# INLINEABLE magenta #-}+ -- | Cyan foreground.-cyan = surround "36" "39"+cyan :: Text -> Text+cyan =+ foreground "36"+{-# INLINEABLE cyan #-}+ -- | White foreground.-white = surround "37" "39"+white :: Text -> Text+white =+ foreground "37"+{-# INLINEABLE white #-}+ -- | Bright black foreground.-brightBlack = surround "90" "39"+brightBlack :: Text -> Text+brightBlack =+ foreground "90"+{-# INLINEABLE brightBlack #-}+ -- | Bright red foreground.-brightRed = surround "91" "39"+brightRed :: Text -> Text+brightRed =+ foreground "91"+{-# INLINEABLE brightRed #-}+ -- | Bright green foreground.-brightGreen = surround "92" "39"+brightGreen :: Text -> Text+brightGreen =+ foreground "92"+{-# INLINEABLE brightGreen #-}+ -- | Bright yellow foreground.-brightYellow = surround "93" "39"+brightYellow :: Text -> Text+brightYellow =+ foreground "93"+{-# INLINEABLE brightYellow #-}+ -- | Bright blue foreground.-brightBlue = surround "94" "39"+brightBlue :: Text -> Text+brightBlue =+ foreground "94"+{-# INLINEABLE brightBlue #-}+ -- | Bright magenta foreground.-brightMagenta = surround "95" "39"+brightMagenta :: Text -> Text+brightMagenta =+ foreground "95"+{-# INLINEABLE brightMagenta #-}+ -- | Bright cyan foreground.-brightCyan = surround "96" "39"+brightCyan :: Text -> Text+brightCyan =+ foreground "96"+{-# INLINEABLE brightCyan #-}+ -- | Bright white foreground.-brightWhite = surround "97" "39"+brightWhite :: Text -> Text+brightWhite =+ foreground "97"+{-# INLINEABLE brightWhite #-}++-- | RGB foreground.+rgb :: Word8 -> Word8 -> Word8 -> Text -> Text+rgb r g b =+ foreground ("38;2;" <> Builder.decimal r <> semi <> Builder.decimal g <> semi <> Builder.decimal b)+{-# INLINEABLE rgb #-}++foreground :: Builder -> Text -> Text+foreground s =+ surround s "39"+{-# INLINE foreground #-}+ -- | Black background.-blackBg = surround "40" "49"+blackBg :: Text -> Text+blackBg =+ background "40"+{-# INLINEABLE blackBg #-}+ -- | Red background.-redBg = surround "41" "49"+redBg :: Text -> Text+redBg =+ background "41"+{-# INLINEABLE redBg #-}+ -- | Green background.-greenBg = surround "42" "49"+greenBg :: Text -> Text+greenBg =+ background "42"+{-# INLINEABLE greenBg #-}+ -- | Yellow background.-yellowBg = surround "43" "49"+yellowBg :: Text -> Text+yellowBg =+ background "43"+{-# INLINEABLE yellowBg #-}+ -- | Blue background.-blueBg = surround "44" "49"+blueBg :: Text -> Text+blueBg =+ background "44"+{-# INLINEABLE blueBg #-}+ -- | Magenta background.-magentaBg = surround "45" "49"+magentaBg :: Text -> Text+magentaBg =+ background "45"+{-# INLINEABLE magentaBg #-}+ -- | Cyan background.-cyanBg = surround "46" "49"+cyanBg :: Text -> Text+cyanBg =+ background "46"+{-# INLINEABLE cyanBg #-}+ -- | White background.-whiteBg = surround "47" "49"+whiteBg :: Text -> Text+whiteBg =+ background "47"+{-# INLINEABLE whiteBg #-}+ -- | Bright black background.-brightBlackBg = surround "100" "49"+brightBlackBg :: Text -> Text+brightBlackBg =+ background "100"+{-# INLINEABLE brightBlackBg #-}+ -- | Bright red background.-brightRedBg = surround "101" "49"+brightRedBg :: Text -> Text+brightRedBg =+ background "101"+{-# INLINEABLE brightRedBg #-}+ -- | Bright green background.-brightGreenBg = surround "102" "49"+brightGreenBg :: Text -> Text+brightGreenBg =+ background "102"+{-# INLINEABLE brightGreenBg #-}+ -- | Bright yellow background.-brightYellowBg = surround "103" "49"+brightYellowBg :: Text -> Text+brightYellowBg =+ background "103"+{-# INLINEABLE brightYellowBg #-}+ -- | Bright blue background.-brightBlueBg = surround "104" "49"+brightBlueBg :: Text -> Text+brightBlueBg =+ background "104"+{-# INLINEABLE brightBlueBg #-}+ -- | Bright magenta background.-brightMagentaBg = surround "105" "49"+brightMagentaBg :: Text -> Text+brightMagentaBg =+ background "105"+{-# INLINEABLE brightMagentaBg #-}+ -- | Bright cyan background.-brightCyanBg = surround "106" "49"+brightCyanBg :: Text -> Text+brightCyanBg =+ background "106"+{-# INLINEABLE brightCyanBg #-}+ -- | Bright white background.-brightWhiteBg = surround "107" "49"+brightWhiteBg :: Text -> Text+brightWhiteBg =+ background "107"+{-# INLINEABLE brightWhiteBg #-} --- | RGB foreground.-{-# INLINABLE rgb #-}-rgb :: Word8 -> Word8 -> Word8 -> Text -> Text-rgb r g b =- surround- ("38;2;" <>- Builder.decimal r <>- semi <>- Builder.decimal g <>- semi <>- Builder.decimal b)- "39"+background :: Builder -> Text -> Text+background s =+ surround s "49"+{-# INLINE background #-} -- | RGB background.-{-# INLINABLE rgbBg #-} rgbBg :: Word8 -> Word8 -> Word8 -> Text -> Text rgbBg r g b =- surround- ("48;2;" <>- Builder.decimal r <>- semi <>- Builder.decimal g <>- semi <>- Builder.decimal b)- "49"--{-# INLINABLE bold #-}-{-# INLINABLE faint #-}-{-# INLINABLE italic #-}-{-# INLINABLE underline #-}-{-# INLINABLE doubleUnderline #-}-{-# INLINABLE strikethrough #-}-{-# INLINABLE frame #-}-{-# INLINABLE encircle #-}-{-# INLINABLE overline #-}--bold, faint, italic, underline, doubleUnderline, strikethrough, frame,- encircle, overline :: Text -> Text+ background ("48;2;" <> Builder.decimal r <> semi <> Builder.decimal g <> semi <> Builder.decimal b)+{-# INLINEABLE rgbBg #-} -- | __Bold__ style (high intensity).-bold = surround "1" "22"+bold :: Text -> Text+bold =+ surround "1" "22"+{-# INLINEABLE bold #-}+ -- | Faint style (low intensity).-faint = surround "2" "22"+faint :: Text -> Text+faint =+ surround "2" "22"+{-# INLINEABLE faint #-}+ -- | /Italic/ style.-italic = surround "3" "32"+italic :: Text -> Text+italic =+ surround "3" "23"+{-# INLINEABLE italic #-}+ -- | U̲n̲d̲e̲r̲l̲i̲n̲e̲ style.-underline = surround "4" "24"+underline :: Text -> Text+underline =+ surround "4" "24"+{-# INLINEABLE underline #-}+ -- | D̳o̳u̳b̳l̳e̳ ̳u̳n̳d̳e̳r̳l̳i̳n̳e̳ style.-doubleUnderline = surround "21" "24"+doubleUnderline :: Text -> Text+doubleUnderline =+ surround "21" "24"+{-# INLINEABLE doubleUnderline #-}+ -- | S̶t̶r̶i̶k̶e̶t̶h̶r̶o̶u̶g̶h̶ style.-strikethrough = surround "9" "29"+strikethrough :: Text -> Text+strikethrough =+ surround "9" "29"+{-# INLINEABLE strikethrough #-}+ -- | Frame style.-frame = surround "51" "54"--- | Encircle style.-encircle = surround "52" "54"--- | O̅v̅e̅r̅l̅i̅n̅e̅ style.-overline = surround "53" "55"+frame :: Text -> Text+frame =+ surround "51" "54"+{-# INLINEABLE frame #-} +-- | Encircle style.+encircle :: Text -> Text+encircle =+ surround "52" "54"+{-# INLINEABLE encircle #-} +-- | O̅v̅e̅r̅l̅i̅n̅e̅ style.+overline :: Text -> Text+overline =+ surround "53" "55"+{-# INLINEABLE overline #-} -------------------------------------------------------------------------------- --- Don't inline before phase 1-{-# NOINLINE [1] surround #-} surround :: Builder -> Builder -> Text -> Text surround open close text | isatty = Text.Lazy.toStrict (Builder.toLazyText (esc <> open <> m <> Builder.fromText text <> esc <> close <> m)) | otherwise = text+-- Don't inline before phase 1+{-# NOINLINE [1] surround #-} esc :: Builder-esc = "\ESC["+esc =+ "\ESC[" -m, semi :: Builder-m = Builder.singleton 'm'-semi = Builder.singleton ';'+m :: Builder+m =+ Builder.singleton 'm' -{-# NOINLINE isatty #-}+semi :: Builder+semi =+ Builder.singleton ';'+ isatty :: Bool isatty = unsafePerformIO (c_isatty 1) == 1+{-# NOINLINE isatty #-} foreign import ccall unsafe "isatty" c_isatty :: CInt -> IO CInt -- Collapse surround/surround to a single surround before phase 1 {-# RULES- "surround/surround" [~1]- forall a b c d s.+"surround/surround" [~1] forall a b c d s. surround a b (surround c d s) =- surround (a <> semi <> c) (b <> semi <> d) s-#-}+ surround (a <> semi <> c) (b <> semi <> d) s+ #-}
README.md view
@@ -1,2 +1,5 @@ [](https://github.com/mitchellwrosen/text-ansi/actions) [](https://hackage.haskell.org/package/text-ansi)+[](https://www.stackage.org/lts/package/text-ansi)+[](https://www.stackage.org/nightly/package/text-ansi)+[](https://packdeps.haskellers.com/reverse/text-ansi)
cabal.project view
@@ -1,5 +1,1 @@ packages: .-index-state: 2020-06-14T23:29:31Z--package text-ansi- ghc-options: -Werror
− cabal.project.freeze
@@ -1,6 +0,0 @@-constraints: any.array ==0.5.4.0,- any.binary ==0.8.8.0,- any.bytestring ==0.10.10.0,- any.containers ==0.6.2.1,- any.deepseq ==1.4.4.0,- any.rts ==1.0
text-ansi.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.2 name: text-ansi-version: 0.1.0.1+version: 0.1.0.2 category: Data synopsis: Text styling for ANSI terminals. description:@@ -19,14 +19,13 @@ maintainer: Mitchell Rosen <mitchellwrosen@gmail.com> homepage: https://github.com/mitchellwrosen/text-ansi bug-reports: https://github.com/mitchellwrosen/text-ansi/issues-copyright: (c) 2018, Mitchell Rosen+copyright: (c) 2018-2020, Mitchell Rosen license: BSD-3-Clause license-file: LICENSE build-type: Simple extra-source-files: cabal.project- cabal.project.freeze CHANGELOG.md README.md