vgrep-0.2.3.0: A pager for grep
Safe HaskellNone
LanguageHaskell2010

Vgrep.Ansi.Type

Synopsis

Documentation

data Formatted attr Source #

A representattion of formatted Text. The attribute is usually a Monoid so that different formattings can be combined by nesting them.

Constructors

Empty

An empty block

Text !Int Text

A bare (unformatted) text node

Format !Int attr (Formatted attr)

Adds formatting to a block

Cat !Int [Formatted attr]

Concatenates several blocks of formatted text

Instances

Instances details
Functor Formatted Source # 
Instance details

Defined in Vgrep.Ansi.Type

Methods

fmap :: (a -> b) -> Formatted a -> Formatted b #

(<$) :: a -> Formatted b -> Formatted a #

Eq attr => Eq (Formatted attr) Source # 
Instance details

Defined in Vgrep.Ansi.Type

Methods

(==) :: Formatted attr -> Formatted attr -> Bool #

(/=) :: Formatted attr -> Formatted attr -> Bool #

Show attr => Show (Formatted attr) Source # 
Instance details

Defined in Vgrep.Ansi.Type

Methods

showsPrec :: Int -> Formatted attr -> ShowS #

show :: Formatted attr -> String #

showList :: [Formatted attr] -> ShowS #

(Eq attr, Semigroup attr) => Semigroup (Formatted attr) Source # 
Instance details

Defined in Vgrep.Ansi.Type

Methods

(<>) :: Formatted attr -> Formatted attr -> Formatted attr #

sconcat :: NonEmpty (Formatted attr) -> Formatted attr #

stimes :: Integral b => b -> Formatted attr -> Formatted attr #

(Eq attr, Semigroup attr) => Monoid (Formatted attr) Source # 
Instance details

Defined in Vgrep.Ansi.Type

Methods

mempty :: Formatted attr #

mappend :: Formatted attr -> Formatted attr -> Formatted attr #

mconcat :: [Formatted attr] -> Formatted attr #

type AnsiFormatted = Formatted Attr Source #

Type alias for Text formatted with Attr from Graphics.Vty.

Smart constructors

emptyFormatted :: Formatted attr Source #

Smart constructor for an empty Formatted text.

bare :: Text -> Formatted attr Source #

Smart constructor for bare (unformatted) text.

>>> bare ""
Empty
>>> bare "Text"
Text 4 "Text"

format :: (Eq attr, Monoid attr) => attr -> Formatted attr -> Formatted attr Source #

Adds formatting to a Formatted text. The Eq and Monoid instances for attr are used to flatten redundant formattings.

>>> format (Just ()) (format Nothing (bare "Text"))
Format 4 (Just ()) (Text 4 "Text")
>>> format (Just ()) (format (Just ()) (bare "Text"))
Format 4 (Just ()) (Text 4 "Text")
>>> format Nothing (bare "Text")
Text 4 "Text"

cat :: (Eq attr, Monoid attr) => [Formatted attr] -> Formatted attr Source #

Concatenates pieces of Formatted text. Redundant formattings and blocks of equal formatting are fused together.

Modifying the underlying text

mapText :: (Text -> Text) -> Formatted a -> Formatted a Source #

Apply a function to each piece of text in the Formatted tree.

>>> mapText T.toUpper (Cat 11 [Text 6 "Hello ", Format 5 () (Text 5 "World")])
Cat 11 [Text 6 "HELLO ",Format 5 () (Text 5 "WORLD")]

mapTextWithPos :: (Int -> Text -> Text) -> Formatted a -> Formatted a Source #

Like mapText, but passes the position of the text chunk to the function as well. Can be used for formatting text position-dependently, e.g. for expanding tabs to spaces.

takeFormatted :: Int -> Formatted a -> Formatted a Source #

Crops the text to a given length. If the text is already shorter than the desired width, it is returned as-is.

dropFormatted :: Int -> Formatted a -> Formatted a Source #

Drops a prefix of the given length. If the text is already shorter than the number of characters to be dropped, emptyFormatted is returned.

padFormatted :: Int -> Char -> Formatted a -> Formatted a Source #

Pads the text to a given width. If the text is already longer than the desired width, it is returned as-is.

Internal helpers

fuse :: (Eq attr, Semigroup attr) => Formatted attr -> Formatted attr -> Formatted attr Source #

Simplifies Formatted text by leaving out redundant empty bits, joining pieces of text with the same formatting, and flattening redundant applications of the same style.

>>> emptyFormatted `fuse` bare "Text"
Text 4 "Text"
>>> format (Just ()) (bare "Left") `fuse` format (Just ()) (bare "Right")
Format 9 (Just ()) (Text 9 "LeftRight")