packages feed

core-text 0.3.2.0 → 0.3.4.0

raw patch · 5 files changed

+242/−192 lines, 5 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Core.Text.Utilities: bold :: AnsiColour -> AnsiColour
- Core.Text.Utilities: brightBlue :: AnsiColour
- Core.Text.Utilities: brightCyan :: AnsiColour
- Core.Text.Utilities: brightGreen :: AnsiColour
- Core.Text.Utilities: brightGrey :: AnsiColour
- Core.Text.Utilities: brightMagenta :: AnsiColour
- Core.Text.Utilities: brightRed :: AnsiColour
- Core.Text.Utilities: brightWhite :: AnsiColour
- Core.Text.Utilities: brightYellow :: AnsiColour
- Core.Text.Utilities: data AnsiColour
- Core.Text.Utilities: dullBlue :: AnsiColour
- Core.Text.Utilities: dullCyan :: AnsiColour
- Core.Text.Utilities: dullGreen :: AnsiColour
- Core.Text.Utilities: dullGrey :: AnsiColour
- Core.Text.Utilities: dullMagenta :: AnsiColour
- Core.Text.Utilities: dullRed :: AnsiColour
- Core.Text.Utilities: dullWhite :: AnsiColour
- Core.Text.Utilities: dullYellow :: AnsiColour
- Core.Text.Utilities: instance GHC.Base.Monoid Core.Text.Utilities.AnsiColour
- Core.Text.Utilities: instance GHC.Base.Semigroup Core.Text.Utilities.AnsiColour
- Core.Text.Utilities: pureBlack :: AnsiColour
- Core.Text.Utilities: pureBlue :: AnsiColour
- Core.Text.Utilities: pureCyan :: AnsiColour
- Core.Text.Utilities: pureGreen :: AnsiColour
- Core.Text.Utilities: pureGrey :: AnsiColour
- Core.Text.Utilities: pureMagenta :: AnsiColour
- Core.Text.Utilities: pureRed :: AnsiColour
- Core.Text.Utilities: pureWhite :: AnsiColour
- Core.Text.Utilities: pureYellow :: AnsiColour
+ Core.Text.Colour: boldColour :: AnsiColour -> AnsiColour
+ Core.Text.Colour: brightBlue :: AnsiColour
+ Core.Text.Colour: brightCyan :: AnsiColour
+ Core.Text.Colour: brightGreen :: AnsiColour
+ Core.Text.Colour: brightGrey :: AnsiColour
+ Core.Text.Colour: brightMagenta :: AnsiColour
+ Core.Text.Colour: brightRed :: AnsiColour
+ Core.Text.Colour: brightWhite :: AnsiColour
+ Core.Text.Colour: brightYellow :: AnsiColour
+ Core.Text.Colour: data AnsiColour
+ Core.Text.Colour: dullBlue :: AnsiColour
+ Core.Text.Colour: dullCyan :: AnsiColour
+ Core.Text.Colour: dullGreen :: AnsiColour
+ Core.Text.Colour: dullGrey :: AnsiColour
+ Core.Text.Colour: dullMagenta :: AnsiColour
+ Core.Text.Colour: dullRed :: AnsiColour
+ Core.Text.Colour: dullWhite :: AnsiColour
+ Core.Text.Colour: dullYellow :: AnsiColour
+ Core.Text.Colour: instance GHC.Base.Monoid Core.Text.Colour.AnsiColour
+ Core.Text.Colour: instance GHC.Base.Semigroup Core.Text.Colour.AnsiColour
+ Core.Text.Colour: intoEscapes :: AnsiColour -> Rope
+ Core.Text.Colour: pureBlack :: AnsiColour
+ Core.Text.Colour: pureBlue :: AnsiColour
+ Core.Text.Colour: pureCyan :: AnsiColour
+ Core.Text.Colour: pureGreen :: AnsiColour
+ Core.Text.Colour: pureGrey :: AnsiColour
+ Core.Text.Colour: pureMagenta :: AnsiColour
+ Core.Text.Colour: pureRed :: AnsiColour
+ Core.Text.Colour: pureWhite :: AnsiColour
+ Core.Text.Colour: pureYellow :: AnsiColour
+ Core.Text.Colour: resetColour :: AnsiColour
+ Core.Text.Rope: packRope :: String -> Rope

Files

core-text.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 5360f5729fffd35e21f13c06edbd41bdc1ffc7334f3f456b64bb16738bcc742d+-- hash: 530a2649aa827894f3d5d158c255950e6244709a892b3897b521eff3818a21ac  name:           core-text-version:        0.3.2.0+version:        0.3.4.0 synopsis:       A rope type based on a finger tree over UTF-8 fragments description:    A rope data type for text, built as a finger tree over UTF-8 text                 fragments. The package also includes utiltiy functions for breaking and@@ -33,7 +33,7 @@ license:        MIT license-file:   LICENSE tested-with:-    GHC == 8.10.6+    GHC == 8.10.7 build-type:     Simple extra-doc-files:     AnsiColours.png@@ -46,6 +46,7 @@   exposed-modules:       Core.Text       Core.Text.Bytes+      Core.Text.Colour       Core.Text.Rope       Core.Text.Utilities   other-modules:
lib/Core/Text.hs view
@@ -25,10 +25,12 @@      -- |     -- Useful functions for common use cases.+    module Core.Text.Colour,     module Core.Text.Utilities,   ) where  import Core.Text.Bytes+import Core.Text.Colour import Core.Text.Rope import Core.Text.Utilities
+ lib/Core/Text/Colour.hs view
@@ -0,0 +1,210 @@+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE OverloadedStrings #-}++{- |+Support for colour in the terminal.++![ANSI colours](AnsiColours.png)+-}+module Core.Text.Colour (+    AnsiColour,+    intoEscapes,+    boldColour,+    dullRed,+    brightRed,+    pureRed,+    dullGreen,+    brightGreen,+    pureGreen,+    dullBlue,+    brightBlue,+    pureBlue,+    dullCyan,+    brightCyan,+    pureCyan,+    dullMagenta,+    brightMagenta,+    pureMagenta,+    dullYellow,+    brightYellow,+    pureYellow,+    pureBlack,+    dullGrey,+    brightGrey,+    pureGrey,+    pureWhite,+    dullWhite,+    brightWhite,+    resetColour,+) where++import Core.Text.Rope+import Data.Colour.SRGB (sRGB, sRGB24read)+import System.Console.ANSI.Codes (setSGRCode)+import System.Console.ANSI.Types (ConsoleIntensity (..), ConsoleLayer (..), SGR (..))++{- |+An accumulation of ANSI escape codes used to add colour when pretty printing+to console.+-}+newtype AnsiColour = Escapes [SGR]++{-|+Convert an AnsiColour into the ANSI escape sequences which will make that+colour appear in the user's terminal.+-}+intoEscapes :: AnsiColour -> Rope+intoEscapes (Escapes codes) = intoRope (setSGRCode codes)++-- | Medium \"Scarlet Red\" (@#cc0000@ from the Tango color palette).+dullRed :: AnsiColour+dullRed =+    Escapes [SetRGBColor Foreground (sRGB24read "#CC0000")]++-- | Highlighted \"Scarlet Red\" (@#ef2929@ from the Tango color palette).+brightRed :: AnsiColour+brightRed =+    Escapes [SetRGBColor Foreground (sRGB24read "#EF2929")]++-- | Pure \"Red\" (full RGB red channel only).+pureRed :: AnsiColour+pureRed =+    Escapes [SetRGBColor Foreground (sRGB 1 0 0)]++-- | Shadowed \"Chameleon\" (@#4e9a06@ from the Tango color palette).+dullGreen :: AnsiColour+dullGreen =+    Escapes [SetRGBColor Foreground (sRGB24read "#4E9A06")]++-- | Highlighted \"Chameleon\" (@#8ae234@ from the Tango color palette).+brightGreen :: AnsiColour+brightGreen =+    Escapes [SetRGBColor Foreground (sRGB24read "#8AE234")]++-- | Pure \"Green\" (full RGB green channel only).+pureGreen :: AnsiColour+pureGreen =+    Escapes [SetRGBColor Foreground (sRGB 0 1 0)]++-- | Medium \"Sky Blue\" (@#3465a4@ from the Tango color palette).+dullBlue :: AnsiColour+dullBlue =+    Escapes [SetRGBColor Foreground (sRGB24read "#3465A4")]++-- | Highlighted \"Sky Blue\" (@#729fcf@ from the Tango color palette).+brightBlue :: AnsiColour+brightBlue =+    Escapes [SetRGBColor Foreground (sRGB24read "#729FCF")]++-- | Pure \"Blue\" (full RGB blue channel only).+pureBlue :: AnsiColour+pureBlue =+    Escapes [SetRGBColor Foreground (sRGB 0 0 1)]++-- | Dull \"Cyan\" (from the __gnome-terminal__ console theme).+dullCyan :: AnsiColour+dullCyan =+    Escapes [SetRGBColor Foreground (sRGB24read "#06989A")]++-- | Bright \"Cyan\" (from the __gnome-terminal__ console theme).+brightCyan :: AnsiColour+brightCyan =+    Escapes [SetRGBColor Foreground (sRGB24read "#34E2E2")]++-- | Pure \"Cyan\" (full RGB blue + green channels).+pureCyan :: AnsiColour+pureCyan =+    Escapes [SetRGBColor Foreground (sRGB 0 1 1)]++-- | Medium \"Plum\" (@#75507b@ from the Tango color palette).+dullMagenta :: AnsiColour+dullMagenta =+    Escapes [SetRGBColor Foreground (sRGB24read "#75507B")]++-- | Highlighted \"Plum\" (@#ad7fa8@ from the Tango color palette).+brightMagenta :: AnsiColour+brightMagenta =+    Escapes [SetRGBColor Foreground (sRGB24read "#AD7FA8")]++-- | Pure \"Magenta\" (full RGB red + blue channels).+pureMagenta :: AnsiColour+pureMagenta =+    Escapes [SetRGBColor Foreground (sRGB 1 0 1)]++-- | Shadowed \"Butter\" (@#c4a000@ from the Tango color palette).+dullYellow :: AnsiColour+dullYellow =+    Escapes [SetRGBColor Foreground (sRGB24read "#C4A000")]++-- | Highlighted \"Butter\" (@#fce94f@ from the Tango color palette).+brightYellow :: AnsiColour+brightYellow =+    Escapes [SetRGBColor Foreground (sRGB24read "#FCE94F")]++-- | Pure \"Yellow\" (full RGB red + green channels).+pureYellow :: AnsiColour+pureYellow =+    Escapes [SetRGBColor Foreground (sRGB 1 1 0)]++-- | Pure \"Black\" (zero in all RGB channels).+pureBlack :: AnsiColour+pureBlack =+    Escapes [SetRGBColor Foreground (sRGB 0 0 0)]++-- | Shadowed \"Deep Aluminium\" (@#2e3436@ from the Tango color palette).+dullGrey :: AnsiColour+dullGrey =+    Escapes [SetRGBColor Foreground (sRGB24read "#2E3436")]++-- | Medium \"Dark Aluminium\" (from the Tango color palette).+brightGrey :: AnsiColour+brightGrey =+    Escapes [SetRGBColor Foreground (sRGB24read "#555753")]++-- | Pure \"Grey\" (set at @#999999@, being just over half in all RGB channels).+pureGrey :: AnsiColour+pureGrey =+    Escapes [SetRGBColor Foreground (sRGB24read "#999999")]++-- | Pure \"White\" (fully on in all RGB channels).+pureWhite :: AnsiColour+pureWhite =+    Escapes [SetRGBColor Foreground (sRGB 1 1 1)]++-- | Medium \"Light Aluminium\" (@#d3d7cf@ from the Tango color palette).+dullWhite :: AnsiColour+dullWhite =+    Escapes [SetRGBColor Foreground (sRGB24read "#D3D7CF")]++-- | Highlighted \"Light Aluminium\" (@#eeeeec@ from the Tango color palette).+brightWhite :: AnsiColour+brightWhite =+    Escapes [SetRGBColor Foreground (sRGB24read "#EEEEEC")]++{- |+Given an 'AnsiColour', lift it to bold intensity.++Note that many console fonts do /not/ have a bold face variant, and terminal+emulators that "support bold" do so by doubling the thickness of the lines in+the glyphs. This may or may not be desirable from a readibility standpoint but+really there's only so much you can do to keep users who make poor font+choices from making poor font choices.+-}+boldColour :: AnsiColour -> AnsiColour+boldColour (Escapes list) =+    Escapes (SetConsoleIntensity BoldIntensity : list)++instance Semigroup AnsiColour where+    (<>) (Escapes list1) (Escapes list2) = Escapes (list1 <> list2)++instance Monoid AnsiColour where+    mempty = Escapes []++{- |+This is not a colour, obviously, but it represents reseting to the default+terminal foreground colour, whatever the user has that set to.+-}+resetColour :: AnsiColour+resetColour =+    Escapes [Reset]
lib/Core/Text/Rope.hs view
@@ -75,6 +75,7 @@     Rope,     emptyRope,     singletonRope,+    packRope,     replicateRope,     replicateChar,     widthRope,@@ -136,7 +137,7 @@     fromText,     toLazyText,  )-import Data.Text.Prettyprint.Doc (Pretty (..), emptyDoc)+import Prettyprinter (Pretty (..), emptyDoc) import qualified Data.Text.Short as S (     ShortText,     any,@@ -279,6 +280,17 @@ -} singletonRope :: Char -> Rope singletonRope = Rope . F.singleton . S.singleton++{- |+A 'Rope' built from a list of characters. Equivalent to calling 'intoRope' on+the String, but can help you avoid ambiguious type errors when composing+functions or working with literals.++@since 0.3.4+-}+packRope :: String -> Rope+packRope xs = Rope . F.singleton . S.pack $ xs+  {- | Repeat the input 'Rope' @n@ times. The follows the same semantics as other
lib/Core/Text/Utilities.hs view
@@ -6,46 +6,17 @@ {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-} {-# OPTIONS_GHC -fno-warn-orphans #-}-{-# OPTIONS_HADDOCK prune #-}+{-# OPTIONS_HADDOCK prune, not-home #-}  {- | Useful tools for working with 'Rope's. Support for pretty printing, multi-line strings, and...--![ANSI colours](AnsiColours.png) -} module Core.Text.Utilities (     -- * Pretty printing     Render (..),-    AnsiColour,-    bold,     render,     renderNoAnsi,-    dullRed,-    brightRed,-    pureRed,-    dullGreen,-    brightGreen,-    pureGreen,-    dullBlue,-    brightBlue,-    pureBlue,-    dullCyan,-    brightCyan,-    pureCyan,-    dullMagenta,-    brightMagenta,-    pureMagenta,-    dullYellow,-    brightYellow,-    pureYellow,-    pureBlack,-    dullGrey,-    brightGrey,-    pureGrey,-    pureWhite,-    dullWhite,-    brightWhite,      -- * Helpers     indefinite,@@ -65,21 +36,26 @@     intoPieces,     intoChunks,     byteChunk,++    -- * Deprecated     intoDocA,+    module Core.Text.Colour,+    bold,+    -- | AnsiColour and colour constants moved to this module. ) where  import Core.Text.Breaking import Core.Text.Bytes+import Core.Text.Colour import Core.Text.Parsing import Core.Text.Rope import Data.Bits (Bits (..)) import qualified Data.ByteString as B (ByteString, length, splitAt, unpack) import Data.Char (intToDigit)-import Data.Colour.SRGB (sRGB, sRGB24read) import qualified Data.FingerTree as F (ViewL (..), viewl, (<|)) import qualified Data.List as List (dropWhileEnd, foldl', splitAt) import qualified Data.Text as T-import Data.Text.Prettyprint.Doc (+import Prettyprinter (     Doc,     LayoutOptions (LayoutOptions),     PageWidth (AvailablePerLine),@@ -97,7 +73,7 @@     unAnnotateS,     vcat,  )-import Data.Text.Prettyprint.Doc.Render.Text (renderLazy)+import Prettyprinter.Render.Text (renderLazy) import qualified Data.Text.Short as S (     ShortText,     replicate,@@ -108,19 +84,8 @@ import Data.Word (Word8) import Language.Haskell.TH (litE, stringL) import Language.Haskell.TH.Quote (QuasiQuoter (QuasiQuoter))-import System.Console.ANSI.Codes (setSGRCode)-import System.Console.ANSI.Types (ConsoleIntensity (..), ConsoleLayer (..), SGR (..))  {- |-An accumulation of ANSI escape codes used to add colour when pretty printing-to console.--}-newtype AnsiColour = Escapes [SGR]---- change AnsiStyle to a custom token type, perhaps Ansi, which--- has the escape codes already converted to Rope.--{- | Types which can be rendered "prettily", that is, formatted by a pretty printer and embossed with beautiful ANSI colours when printed to the terminal. @@ -145,149 +110,9 @@ intoDocA = error "Nothing should be invoking this method directly." {-# DEPRECATED intoDocA "method'intoDocA' has been renamed 'highlight'; implement that instead." #-} --- | Medium \"Scarlet Red\" (@#cc0000@ from the Tango color palette).-dullRed :: AnsiColour-dullRed =-    Escapes [SetRGBColor Foreground (sRGB24read "#CC0000")]---- | Highlighted \"Scarlet Red\" (@#ef2929@ from the Tango color palette).-brightRed :: AnsiColour-brightRed =-    Escapes [SetRGBColor Foreground (sRGB24read "#EF2929")]---- | Pure \"Red\" (full RGB red channel only).-pureRed :: AnsiColour-pureRed =-    Escapes [SetRGBColor Foreground (sRGB 1 0 0)]---- | Shadowed \"Chameleon\" (@#4e9a06@ from the Tango color palette).-dullGreen :: AnsiColour-dullGreen =-    Escapes [SetRGBColor Foreground (sRGB24read "#4E9A06")]---- | Highlighted \"Chameleon\" (@#8ae234@ from the Tango color palette).-brightGreen :: AnsiColour-brightGreen =-    Escapes [SetRGBColor Foreground (sRGB24read "#8AE234")]---- | Pure \"Green\" (full RGB green channel only).-pureGreen :: AnsiColour-pureGreen =-    Escapes [SetRGBColor Foreground (sRGB 0 1 0)]---- | Medium \"Sky Blue\" (@#3465a4@ from the Tango color palette).-dullBlue :: AnsiColour-dullBlue =-    Escapes [SetRGBColor Foreground (sRGB24read "#3465A4")]---- | Highlighted \"Sky Blue\" (@#729fcf@ from the Tango color palette).-brightBlue :: AnsiColour-brightBlue =-    Escapes [SetRGBColor Foreground (sRGB24read "#729FCF")]---- | Pure \"Blue\" (full RGB blue channel only).-pureBlue :: AnsiColour-pureBlue =-    Escapes [SetRGBColor Foreground (sRGB 0 0 1)]---- | Dull \"Cyan\" (from the __gnome-terminal__ console theme).-dullCyan :: AnsiColour-dullCyan =-    Escapes [SetRGBColor Foreground (sRGB24read "#06989A")]---- | Bright \"Cyan\" (from the __gnome-terminal__ console theme).-brightCyan :: AnsiColour-brightCyan =-    Escapes [SetRGBColor Foreground (sRGB24read "#34E2E2")]---- | Pure \"Cyan\" (full RGB blue + green channels).-pureCyan :: AnsiColour-pureCyan =-    Escapes [SetRGBColor Foreground (sRGB 0 1 1)]---- | Medium \"Plum\" (@#75507b@ from the Tango color palette).-dullMagenta :: AnsiColour-dullMagenta =-    Escapes [SetRGBColor Foreground (sRGB24read "#75507B")]---- | Highlighted \"Plum\" (@#ad7fa8@ from the Tango color palette).-brightMagenta :: AnsiColour-brightMagenta =-    Escapes [SetRGBColor Foreground (sRGB24read "#AD7FA8")]---- | Pure \"Magenta\" (full RGB red + blue channels).-pureMagenta :: AnsiColour-pureMagenta =-    Escapes [SetRGBColor Foreground (sRGB 1 0 1)]---- | Shadowed \"Butter\" (@#c4a000@ from the Tango color palette).-dullYellow :: AnsiColour-dullYellow =-    Escapes [SetRGBColor Foreground (sRGB24read "#C4A000")]---- | Highlighted \"Butter\" (@#fce94f@ from the Tango color palette).-brightYellow :: AnsiColour-brightYellow =-    Escapes [SetRGBColor Foreground (sRGB24read "#FCE94F")]---- | Pure \"Yellow\" (full RGB red + green channels).-pureYellow :: AnsiColour-pureYellow =-    Escapes [SetRGBColor Foreground (sRGB 1 1 0)]---- | Pure \"Black\" (zero in all RGB channels).-pureBlack :: AnsiColour-pureBlack =-    Escapes [SetRGBColor Foreground (sRGB 0 0 0)]---- | Shadowed \"Deep Aluminium\" (@#2e3436@ from the Tango color palette).-dullGrey :: AnsiColour-dullGrey =-    Escapes [SetRGBColor Foreground (sRGB24read "#2E3436")]---- | Medium \"Dark Aluminium\" (from the Tango color palette).-brightGrey :: AnsiColour-brightGrey =-    Escapes [SetRGBColor Foreground (sRGB24read "#555753")]---- | Pure \"Grey\" (set at @#999999@, being just over half in all RGB channels).-pureGrey :: AnsiColour-pureGrey =-    Escapes [SetRGBColor Foreground (sRGB24read "#999999")]---- | Pure \"White\" (fully on in all RGB channels).-pureWhite :: AnsiColour-pureWhite =-    Escapes [SetRGBColor Foreground (sRGB 1 1 1)]---- | Medium \"Light Aluminium\" (@#d3d7cf@ from the Tango color palette).-dullWhite :: AnsiColour-dullWhite =-    Escapes [SetRGBColor Foreground (sRGB24read "#D3D7CF")]---- | Highlighted \"Light Aluminium\" (@#eeeeec@ from the Tango color palette).-brightWhite :: AnsiColour-brightWhite =-    Escapes [SetRGBColor Foreground (sRGB24read "#EEEEEC")]--{- |-Given an 'AnsiColour', lift it to bold intensity.--Note that many console fonts do /not/ have a bold face variant, and terminal-emulators that "support bold" do so by doubling the thickness of the lines in-the glyphs. This may or may not be desirable from a readibility standpoint but-really there's only so much you can do to keep users who make poor font-choices from making poor font choices.--} bold :: AnsiColour -> AnsiColour-bold (Escapes list) =-    Escapes (SetConsoleIntensity BoldIntensity : list)--instance Semigroup AnsiColour where-    (<>) (Escapes list1) (Escapes list2) = Escapes (list1 <> list2)--instance Monoid AnsiColour where-    mempty = Escapes []+bold = boldColour+{-# DEPRECATED bold "Import Core.Text.Colour and use 'boldColour' instead" #-}  instance Render Rope where     type Token Rope = ()@@ -427,10 +252,10 @@                     (a : _) -> convert a <> go as' xs      convert :: AnsiColour -> Rope-    convert (Escapes codes) = intoRope (setSGRCode codes)+    convert = intoEscapes      reset :: Rope-    reset = intoRope (setSGRCode [Reset])+    reset = intoEscapes resetColour  {- | Having gone to all the trouble to colourize your rendered types... sometimes