CLI.PrettyPrinter

This module lets you define how text should be formatted before printing it to the terminal.

type Document

A Document represents formatted text.

empty : Document

The empty Document takes up no space. It's analogous to the empty String.

text : String -> Document

Turn a String into a Document. Newlines are not respected, if you want to spread text over multiple lines, use verticalBlock.

Word boundaries are also not respected. If that's important to you, you might want to use words

words : String -> Document

Similar to text, but word boundaries are respected if the String has to be broken up over multiple lines. Whitespace between words are reduced to a single space.

indent : Document -> Document

The contents of the Document is indented one level.

block : Array Document -> Document

This joins multiple Documents into one. If possible, everything will be placed on a single line.

verticalBlock : Array Document -> Document

Like block, but each Document is placed on a seperate line.

type Color
= Black
| Red
| Green
| Yellow
| Blue
| Magenta
| Cyan
| White

Supported text colors

color : Color -> Document -> Document

Colorize the text in the given Document.

intenseColor : Color -> Document -> Document

Like color, but intensifies the given color.

stripColor : Document -> Document

This removes all colorized text in a Document.

toString : Document -> String

Convert a Document into a String that's ready to be written to the terminal.

type alias ToStringOptions =
{ maxColumns : Int
, indentationSize : Int
, newlineSeparator : String
}

Different settings when converting a Document into String.

  • maxColumns defines the maximum number of characters in a line.
  • indentationSize defines the number of spaces per indentation level.
  • newlineSeparator defines the String used for representing newlines.
defaultOptions : ToStringOptions

A default set of options for converting Document into String.

toStringWithOptions : ToStringOptions -> Document -> String

Like toString, but allows you to override the default options.