module Vgrep.Ansi (
AnsiFormatted
, Formatted ()
, emptyFormatted
, bare
, format
, cat
, mapText
, mapTextWithPos
, takeFormatted
, dropFormatted
, padFormatted
, renderAnsi
, stripAnsi
) where
import Data.Text (Text)
import qualified Graphics.Vty as Vty
import Vgrep.Ansi.Type
import Vgrep.Ansi.Vty.Attributes
renderAnsi :: Attr -> AnsiFormatted -> Vty.Image
renderAnsi :: Attr -> AnsiFormatted -> Image
renderAnsi Attr
attr = \case
AnsiFormatted
Empty -> Image
Vty.emptyImage
Text Int
_ Text
t -> Attr -> Text -> Image
Vty.text' Attr
attr Text
t
Format Int
_ Attr
attr' AnsiFormatted
t -> Attr -> AnsiFormatted -> Image
renderAnsi (Attr -> Attr -> Attr
combineStyles Attr
attr Attr
attr') AnsiFormatted
t
Cat Int
_ [AnsiFormatted]
ts -> [Image] -> Image
Vty.horizCat ((AnsiFormatted -> Image) -> [AnsiFormatted] -> [Image]
forall a b. (a -> b) -> [a] -> [b]
map (Attr -> AnsiFormatted -> Image
renderAnsi Attr
attr) [AnsiFormatted]
ts)
stripAnsi :: Formatted a -> Text
stripAnsi :: Formatted a -> Text
stripAnsi = \case
Formatted a
Empty -> Text
forall a. Monoid a => a
mempty
Text Int
_ Text
t -> Text
t
Format Int
_ a
_ Formatted a
t -> Formatted a -> Text
forall a. Formatted a -> Text
stripAnsi Formatted a
t
Cat Int
_ [Formatted a]
ts -> (Formatted a -> Text) -> [Formatted a] -> Text
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap Formatted a -> Text
forall a. Formatted a -> Text
stripAnsi [Formatted a]
ts