Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data Formatted attr
- type AnsiFormatted = Formatted Attr
- emptyFormatted :: Formatted attr
- bare :: Text -> Formatted attr
- format :: (Eq attr, Monoid attr) => attr -> Formatted attr -> Formatted attr
- cat :: (Eq attr, Monoid attr) => [Formatted attr] -> Formatted attr
- mapText :: (Text -> Text) -> Formatted a -> Formatted a
- mapTextWithPos :: (Int -> Text -> Text) -> Formatted a -> Formatted a
- takeFormatted :: Int -> Formatted a -> Formatted a
- dropFormatted :: Int -> Formatted a -> Formatted a
- padFormatted :: Int -> Char -> Formatted a -> Formatted a
- fuse :: (Eq attr, Monoid attr) => Formatted attr -> Formatted attr -> Formatted attr
Documentation
A representattion of formatted Text
. The attribute is usually a Monoid
so that different formattings can be combined by nesting them.
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"
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, Monoid 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")