HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleprettyprinter-ansi-terminal-1.1.3Haskell2010

Prettyprinter.Render.Terminal.Internal

Warning: Internal module. May change arbitrarily between versions.

  • 6 types
  • 12 values

Styling

2 declarations
datadata AnsiStyle
#

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

Instances5Eq, Ord, Show, Semigroup, Monoid
  • Eq AnsiStyleDefined in prettyprinter-ansi-terminal-1.1.3 · Prettyprinter.Render.Terminal.Internal
  • Ord AnsiStyleDefined in prettyprinter-ansi-terminal-1.1.3 · Prettyprinter.Render.Terminal.Internal
  • Show AnsiStyleDefined in prettyprinter-ansi-terminal-1.1.3 · Prettyprinter.Render.Terminal.Internal
  • Semigroup AnsiStyleDefined in prettyprinter-ansi-terminal-1.1.3 · Prettyprinter.Render.Terminal.Internal

    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:

    color Red <> color Green
    

    is red because the first color wins, and not bold because (or if) that’s the terminal’s default.

  • Monoid AnsiStyleDefined in prettyprinter-ansi-terminal-1.1.3 · Prettyprinter.Render.Terminal.Internal

    mempty does nothing, which is equivalent to inheriting the style of the surrounding doc, or the terminal’s default if no style has been set yet.

datadata Color
#

The 8 ANSI terminal colors.

Instances3Eq, Ord, Show
  • Eq ColorDefined in prettyprinter-ansi-terminal-1.1.3 · Prettyprinter.Render.Terminal.Internal
  • Ord ColorDefined in prettyprinter-ansi-terminal-1.1.3 · Prettyprinter.Render.Terminal.Internal
  • Show ColorDefined in prettyprinter-ansi-terminal-1.1.3 · Prettyprinter.Render.Terminal.Internal

Font color

Background color

Font style

Internal markers

datadata Intensity
#

Dull or vivid coloring, as supported by ANSI terminals.

Instances3Eq, Ord, Show
  • Eq IntensityDefined in prettyprinter-ansi-terminal-1.1.3 · Prettyprinter.Render.Terminal.Internal
  • Ord IntensityDefined in prettyprinter-ansi-terminal-1.1.3 · Prettyprinter.Render.Terminal.Internal
  • Show IntensityDefined in prettyprinter-ansi-terminal-1.1.3 · Prettyprinter.Render.Terminal.Internal
datadata Bold
#
Instances3Eq, Ord, Show
  • Eq BoldDefined in prettyprinter-ansi-terminal-1.1.3 · Prettyprinter.Render.Terminal.Internal
  • Ord BoldDefined in prettyprinter-ansi-terminal-1.1.3 · Prettyprinter.Render.Terminal.Internal
  • Show BoldDefined in prettyprinter-ansi-terminal-1.1.3 · Prettyprinter.Render.Terminal.Internal
datadata Underlined
#
Instances3Eq, Ord, Show
  • Eq UnderlinedDefined in prettyprinter-ansi-terminal-1.1.3 · Prettyprinter.Render.Terminal.Internal
  • Ord UnderlinedDefined in prettyprinter-ansi-terminal-1.1.3 · Prettyprinter.Render.Terminal.Internal
  • Show UnderlinedDefined in prettyprinter-ansi-terminal-1.1.3 · Prettyprinter.Render.Terminal.Internal
datadata Italicized
#
Instances3Eq, Ord, Show
  • Eq ItalicizedDefined in prettyprinter-ansi-terminal-1.1.3 · Prettyprinter.Render.Terminal.Internal
  • Ord ItalicizedDefined in prettyprinter-ansi-terminal-1.1.3 · Prettyprinter.Render.Terminal.Internal
  • Show ItalicizedDefined in prettyprinter-ansi-terminal-1.1.3 · Prettyprinter.Render.Terminal.Internal

Conversion to ANSI-infused Text

2 declarations

(renderLazy doc) takes the output 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:

Example4 expressions
let render = TL.putStrLn . TL.replace "\ESC" "\\e" . renderLazy . layoutPretty defaultLayoutOptionslet 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    redrender 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.

Render directly to stdout

1 declaration

(renderIO h sdoc) writes sdoc to the handle h.

Example2 expressions
let render = renderIO System.IO.stdout . layoutPretty defaultLayoutOptionslet doc = annotate (color Red) ("red" <+> align (vsep [annotate (color Blue <> underlined) ("blue+u" <+> annotate bold "bold" <+> "blue+u"), "red"]))

We render the unAnnotated version here, since the ANSI codes don’t display well in Haddock,

Example1 expression
render (unAnnotate doc)red blue+u bold blue+u    red

This function behaves just like

renderIO h sdoc = TL.hPutStr h (renderLazy sdoc)

but will not generate any intermediate text, rendering directly to the handle.

Convenience functions