Module

Dodo.Box

Package
purescript-dodo-printer
Repository
natefaubion/purescript-dodo-printer

#DocBox Source

data DocBox a

Unlike Docs, which can only be joined along a line, DocBoxes are two-dimensional units which can be stacked vertically and horizontally (eg. for tables).

Docs can be lifted into DocBox by using the doxBox printer.

example = Dodo.print docBox twoSpaces myDoc

Instances

#DocBoxBuffer Source

newtype DocBoxBuffer a

#DocAnnStk Source

type DocAnnStk a = List (Either a (Doc a))

#Vertical Source

newtype Vertical a

A newtype whose Semigroup instance stacks DocBoxes vertically.

Constructors

Instances

#Horizontal Source

newtype Horizontal a

A newtype whose Semigroup instance stacks DocBoxes horizontally.

Constructors

Instances

#Align Source

data Align

Constructors

Instances

#BoxSize Source

type BoxSize = { height :: Int, width :: Int }

#valign Source

valign :: forall a. Align -> DocBox a -> DocBox a

Pads a DocBox vertically to fit the tallest box within a horizontal run.

example =
  valign Middle shortDoc
    `happend` tallDoc

#halign Source

halign :: forall a. Align -> DocBox a -> DocBox a

Pads a DocBox horizontally to fit the widest line within a vertical run.

example =
  halign Middle skinnyDoc
    `vappend` wideDoc

#vappend Source

vappend :: forall a. DocBox a -> DocBox a -> DocBox a

Joins two DocBoxes vertically on top of each other.

#happend Source

happend :: forall a. DocBox a -> DocBox a -> DocBox a

Joins two DocBoxes horizontally next to each other.

#vertical Source

vertical :: forall f a. Foldable f => f (DocBox a) -> DocBox a

Joins DocBoxes in a vertical run.

#verticalWithAlign Source

verticalWithAlign :: forall f a. Foldable f => Align -> f (DocBox a) -> DocBox a

Joins DocBoxes in a vertical run with uniform horizontal alignment.

#horizontal Source

horizontal :: forall f a. Foldable f => f (DocBox a) -> DocBox a

Joins DocBoxes in a horizontal run.

#horizontalWithAlign Source

horizontalWithAlign :: forall f a. Foldable f => Align -> f (DocBox a) -> DocBox a

Joins DocBoxes in a horizontal run with uniform vertical alignment.

#resize Source

resize :: forall a. BoxSize -> DocBox a -> DocBox a

Resizes a box to a larger or equivalent size, positioning its content according to its alignment.

#fill Source

fill :: forall a. Doc a -> BoxSize -> DocBox a

Fills a box to a given size with a Doc. The Doc is assumed to be 1x1. Providing a Doc of a different size will result in incorrect layouts.

example =
  fill (Ansi.dim (Dodo.text "-"))
    { width: 100
    , height: 1
    }

#vpadding Source

vpadding :: forall a. Int -> DocBox a

Vertical padding of a specific height.

#hpadding Source

hpadding :: forall a. Int -> DocBox a

Horizontal padding of a specific width.

#sizeOf Source

sizeOf :: forall a. DocBox a -> BoxSize

Returns the size of a DocBox.

#isEmpty Source

isEmpty :: forall a. DocBox a -> Boolean

Checks whether a DocBox is empty.

#empty Source

empty :: forall a. DocBox a

The identity DocBox.

#toDoc Source

toDoc :: forall a. DocBox a -> Doc a

Converts a DocBox back into Doc for printing.

#docBox Source

docBox :: forall a. Printer (DocBoxBuffer a) a (DocBox a)

A printer which can lift a Doc into DocBox. It is assumed that the Doc's annotations respect a distributive law:

annotate ann (a <> b) = annotate ann a <> annotate ann b