rainbox-0.18.0.8: Two-dimensional box pretty printing, with colors

Safe HaskellNone
LanguageHaskell2010

Rainbox

Contents

Description

Typically to use Rainbox you will want these imports:

import qualified Data.Sequence as Seq
import Rainbow
import Rainbox

-- and, for GHC before 7.10:
import Data.Monoid

Rainbox does not re-export anything from Data.Sequence or Rainbow because I don't know if you want all those things dumped into the same namespace.

Rainbox.Tutorial wil get you started. Rainbox.Core contains the implementation details, which you should not need to pay attention to (if you do need to use Rainbox.Core for ordinary usage of the library, that's a bug; please report it.)

Synopsis

Alignment and Boxes

data Alignment a Source

Alignment. Used in conjunction with Horizontal and Vertical, this determines how a payload aligns with the axis of a Box.

center :: Alignment a Source

Place this payload so that it is centered on the vertical axis or horizontal axis.

left :: Alignment Vertical Source

Place this payload's left edge on the vertical axis.

right :: Alignment Vertical Source

Place this payload's right edge on the vertical axis.

top :: Alignment Horizontal Source

Place this payload's top edge on the horizontal axis.

bottom :: Alignment Horizontal Source

Place this payload's bottom edge on the horizontal axis.

centerH :: Alignment Horizontal Source

Center horizontally; like center, but monomorphic.

centerV :: Alignment Vertical Source

Center vertically; like center, but monomorphic.

data Box a Source

A Box is the central building block. It consists of zero or more payloads; each payload has the same orientation, which is either Horizontal or Vertical. This orientation also determines the orientation of the entire Box.

A Box is a Monoid so you can combine them using the usual monoid functions. For a Box Vertical, the leftmost values added with mappend are at the top of the Box; for a Box Horizontal, the leftmost values added with mappend are on the left side of the Box.

class Orientation a where Source

This typeclass is responsible for transforming a Box into Rainbow Chunk so they can be printed to your screen. This requires adding appropriate whitespace with the right colors, as well as adding newlines in the right places.

Minimal complete definition

rodRows, spacer, spreader

Methods

spacer :: Radiant -> Int -> Box a Source

Builds a one-dimensional box of the given size; its single dimension is parallel to the axis. When added to a box, it will insert blank space of the given length. For a Box Horizontal, this produces a horizontal line; for a Box Vertical, a vertical line.

spreader :: Alignment a -> Int -> Box a Source

Builds a one-dimensional box of the given size; its single dimension is perpendicular to the axis. This can be used to make a Box Vertical wider or a Box Horizontal taller.

Box construction

fromChunk Source

Arguments

:: Alignment a 
-> Radiant

Background color. The background color in the Chunk is not changed; this background is used if the Payload must be padded later on.

-> Chunk Text 
-> Box a 

Construct a box from a single Chunk.

blank Source

Arguments

:: Alignment a 
-> Radiant

Color for the blank area.

-> Height 
-> Width 
-> Box a 

Construct a blank box. Useful for adding in background spacers. For functions that build one-dimensional boxes, see spacer and spreader.

wrap Source

Arguments

:: Orientation a 
=> Alignment b

Alignment for new Box. This also determines whether the new Box is Horizontal or Vertical.

-> Radiant

Background color for new box

-> Box a 
-> Box b 

Wrap a Box in another Box. Useful for changing a Horizontal Box to a Vertical one, or simply for putting a Box inside another one to control size and background color.

Rendering

render :: Orientation a => Box a -> Seq (Chunk Text) Source

Convert a box to a Seq of Chunk in preparation for rendering. Use toList to convert the Seq of Chunk to a list so that you can print it using the functions in Rainbow.

Tables

data Cell Source

A single cell in a spreadsheet-like grid.

Constructors

Cell 

Fields

_rows :: Seq (Seq (Chunk Text))

The cell can have multiple rows of text; there is one Seq for each row of text.

_horizontal :: Alignment Horizontal

How this Cell should align compared to other Cell in its row.

_vertical :: Alignment Vertical

How this Cell should align compared to other Cell in its column.

_background :: Radiant

Background color for this cell. The background in the individual Chunk in the cellRows are not affected by cellBackground; instead, cellBackground determines the color of necessary padding that will be added so that the cells make a uniform table.

Instances

Eq Cell Source 
Ord Cell Source 
Show Cell Source 
Monoid Cell Source

mappend combines two Cell horizontally so they are side-by-side, left-to-right. The _horizontal, _vertical, and _background fields are combined using their respective Monoid instances. mempty uses the respective mempty value for each field.

tableByRows :: Seq (Seq Cell) -> Box Vertical Source

Create a table where each inner Seq is a row of cells, from left to right. If necessary, blank cells are added to the end of a row to ensure that each row has the same number of cells as the longest row.

tableByColumns :: Seq (Seq Cell) -> Box Horizontal Source

Create a table where each inner Seq is a column of cells, from top to bottom. If necessary, blank cells are added to the end of a column to ensure that each column has the same number of cells as the longest column.

separator :: Radiant -> Int -> Cell Source

Creates a blank Cell with the given background color and width; useful for adding separators between columns.

Utilities

intersperse :: a -> Seq a -> Seq a Source

Like intersperse in Data.List, but works on Seq.