Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Data.Text.Prettyprint.Doc.Render.Terminal.Internal
Description
Warning: Internal module. May change arbitrarily between versions.
Synopsis
- data Color
- data Intensity
- data Layer
- data Bold = Bold
- data Underlined = Underlined
- data Italicized = Italicized
- color :: Color -> AnsiStyle
- bgColor :: Color -> AnsiStyle
- colorDull :: Color -> AnsiStyle
- bgColorDull :: Color -> AnsiStyle
- bold :: AnsiStyle
- italicized :: AnsiStyle
- underlined :: AnsiStyle
- renderLazy :: SimpleDocStream AnsiStyle -> Text
- renderIO :: Handle -> SimpleDocStream AnsiStyle -> IO ()
- panicStyleStackFullyConsumed :: void
- panicStyleStackNotFullyConsumed :: Int -> void
- data AnsiStyle = SetAnsiStyle {}
- styleToRawText :: AnsiStyle -> Text
- renderStrict :: SimpleDocStream AnsiStyle -> Text
- putDoc :: Doc AnsiStyle -> IO ()
- hPutDoc :: Handle -> Doc AnsiStyle -> IO ()
Documentation
(Definitions for the doctests)
>>>
:set -XOverloadedStrings
>>>
import qualified Data.Text.Lazy.IO as TL
>>>
import qualified Data.Text.Lazy as TL
>>>
import Data.Text.Prettyprint.Doc.Render.Terminal
The 8 ANSI terminal colors.
Dull or vivid coloring, as supported by ANSI terminals.
Instances
Eq Intensity Source # | |
Ord Intensity Source # | |
Defined in Data.Text.Prettyprint.Doc.Render.Terminal.Internal | |
Show Intensity Source # | |
Foreground (text) or background (paper) color
Constructors
Foreground | |
Background |
Constructors
Bold |
data Underlined Source #
Constructors
Underlined |
Instances
Eq Underlined Source # | |
Defined in Data.Text.Prettyprint.Doc.Render.Terminal.Internal Methods (==) :: Underlined -> Underlined -> Bool Source # (/=) :: Underlined -> Underlined -> Bool Source # | |
Ord Underlined Source # | |
Defined in Data.Text.Prettyprint.Doc.Render.Terminal.Internal Methods compare :: Underlined -> Underlined -> Ordering Source # (<) :: Underlined -> Underlined -> Bool Source # (<=) :: Underlined -> Underlined -> Bool Source # (>) :: Underlined -> Underlined -> Bool Source # (>=) :: Underlined -> Underlined -> Bool Source # max :: Underlined -> Underlined -> Underlined Source # min :: Underlined -> Underlined -> Underlined Source # | |
Show Underlined Source # | |
data Italicized Source #
Constructors
Italicized |
Instances
Eq Italicized Source # | |
Defined in Data.Text.Prettyprint.Doc.Render.Terminal.Internal Methods (==) :: Italicized -> Italicized -> Bool Source # (/=) :: Italicized -> Italicized -> Bool Source # | |
Ord Italicized Source # | |
Defined in Data.Text.Prettyprint.Doc.Render.Terminal.Internal Methods compare :: Italicized -> Italicized -> Ordering Source # (<) :: Italicized -> Italicized -> Bool Source # (<=) :: Italicized -> Italicized -> Bool Source # (>) :: Italicized -> Italicized -> Bool Source # (>=) :: Italicized -> Italicized -> Bool Source # max :: Italicized -> Italicized -> Italicized Source # min :: Italicized -> Italicized -> Italicized Source # | |
Show Italicized Source # | |
bgColorDull :: Color -> AnsiStyle Source #
Style the background with a dull color.
italicized :: AnsiStyle Source #
Render in italics.
underlined :: AnsiStyle Source #
Render underlined.
renderLazy :: SimpleDocStream AnsiStyle -> Text Source #
(
takes the output renderLazy
doc)doc
from a rendering function
and transforms it to lazy text, including ANSI styling directives for things
like colorization.
ANSI color information will be discarded by this function unless you are running on a Unix-like operating system. This is due to a technical limitation in Windows ANSI support.
With a bit of trickery to make the ANSI codes printable, here is an example that would render colored in an ANSI terminal:
>>>
let render = TL.putStrLn . TL.replace "\ESC" "\\e" . renderLazy . layoutPretty defaultLayoutOptions
>>>
let doc = annotate (color Red) ("red" <+> align (vsep [annotate (color Blue <> underlined) ("blue+u" <+> annotate bold "bold" <+> "blue+u"), "red"]))
>>>
render (unAnnotate doc)
red blue+u bold blue+u red>>>
render doc
\e[0;91mred \e[0;94;4mblue+u \e[0;94;1;4mbold\e[0;94;4m blue+u\e[0;91m red\e[0m
Run the above via echo -e
in your terminal to see the coloring....
renderIO :: Handle -> SimpleDocStream AnsiStyle -> IO () Source #
(
writes renderIO
h sdoc)sdoc
to the handle h
.
>>>
let render = renderIO System.IO.stdout . layoutPretty defaultLayoutOptions
>>>
let doc = annotate (color Red) ("red" <+> align (vsep [annotate (color Blue <> underlined) ("blue+u" <+> annotate bold "bold" <+> "blue+u"), "red"]))
We render the unAnnotate
d version here, since the ANSI codes don’t display
well in Haddock,
>>>
render (unAnnotate doc)
red blue+u bold blue+u red
This function behaves just like
renderIO
h sdoc =hPutStr
h (renderLazy
sdoc)
but will not generate any intermediate text, rendering directly to the handle.
panicStyleStackFullyConsumed :: void Source #
panicStyleStackNotFullyConsumed :: Int -> void Source #
>>>
let render = renderIO System.IO.stdout . layoutPretty defaultLayoutOptions
>>>
let doc = annotate (color Red) ("red" <+> align (vsep [annotate (color Blue <> underlined) ("blue+u" <+> annotate bold "bold" <+> "blue+u"), "red"]))
>>>
render (unAnnotate doc)
red blue+u bold blue+u red
This test won’t work since I don’t know how to type ESC for doctest :-/ -- >>> render doc -- ESC[0;91mred ESC[0;94;4mblue+u ESC[0;94;1;4mboldESC[0;94;4m blue+uESC[0;91m -- redESC[0m
Render the annotated document in a certain style. Styles not set in the annotation will use the style of the surrounding document, or the terminal’s default if none has been set yet.
style =color
Green
<>
bold
styledDoc =annotate
style "hello world"
Constructors
SetAnsiStyle | |
Fields
|
Instances
Eq AnsiStyle Source # | |
Ord AnsiStyle Source # | |
Defined in Data.Text.Prettyprint.Doc.Render.Terminal.Internal | |
Show AnsiStyle Source # | |
Semigroup AnsiStyle Source # | Keep the first decision for each of foreground color, background color, boldness, italication, and underlining. If a certain style is not set, the terminal’s default will be used. Example:
is red because the first color wins, and not bold because (or if) that’s the terminal’s default. |
Monoid AnsiStyle Source # |
|
styleToRawText :: AnsiStyle -> Text Source #
renderStrict :: SimpleDocStream AnsiStyle -> Text Source #
(
takes the output renderStrict
sdoc)sdoc
from a rendering and
transforms it to strict text.