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

Safe HaskellSafe-Inferred
LanguageHaskell2010

Rainbox.Core

Description

Contains the innards of Rainbox. You shouldn't need anything in here. Some functions here are partial or have undefined results if their inputs don't respect particular invariants.

Synopsis

Documentation

data Alignment a Source

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

Constructors

Center 
NonCenter a 

Instances

Eq a => Eq (Alignment a) 
Ord a => Ord (Alignment a) 
Show a => Show (Alignment a) 

data Horizontal Source

Determines how a payload aligns with a horizontal axis.

Constructors

ATop 
ABottom 

data Vertical Source

Determines how a payload aligns with a vertical axis.

Constructors

ALeft 
ARight 

center :: Alignment a Source

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

centerH :: Alignment Horizontal Source

Center horizontally; like center, but monomorphic.

centerV :: Alignment Vertical Source

Center vertically; like center, but monomorphic.

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.

newtype Height Source

A count of rows.

Constructors

Height Int 

newtype Width Source

A count of columns.

Constructors

Width Int 

newtype Core Source

A Core is either a single Chunk or, if the box is blank, is merely a height and a width.

Constructors

Core (Either Chunk (Height, Width)) 

newtype Rod Source

An intermediate type used in rendering; it consists either of text Chunk or of a number of spaces coupled with a background color.

Constructors

Rod (Either (Int, Radiant) Chunk) 

Instances

data RodRows Source

A list of screen rows; each screen row is a Seq of Rod.

A RodRows with width but no height does nothing if rendered alone, but it can affect the width of other RodRows if combined with them.

Constructors

RodRowsWithHeight (Seq (Seq Rod))

Each outer Seq represents a single screen row. Each Seq has a height of 1.

The outer Seq must have a length of at least 1, even if the inner Seq is empty. If the outer Seq has a length of zero, undefined behavior occurs. For a RodRows with no height and no width, use RodRowsNoHeight.

RodRowsNoHeight Int

A RodRows that has no height. If the Int is less than 1, the RodRows has no width and no height. Otherwise, the RodRows has no height but has the given width.

rodRowsFromCore :: Radiant -> Core -> RodRows Source

Convert a Core to a Seq of Rod for rendering.

chunksFromRodRows :: RodRows -> Seq (Seq Chunk) Source

Converts a RodRows to a nested Seq of Chunk in preparation for rendering. Newlines are added to the end of each line.

data Payload a Source

A Payload holds a RodRows, which determines the number and content of the screen rows. The Payload also has an Alignment, which specifies how the payload aligns with the axis. Whether the Alignment is Horizontal or Vertical determines the orientation of the Payload. The Payload also contains a background color, which is type Radiant. The background color extends continuously from the Payload in both directions that are perpendicular to the axis.

addVerticalPadding :: Box Horizontal -> Seq RodRows Source

Adds padding to the top and bottom of each Payload. A Payload with a Core is converted to a RodRows and has padding added; a Payload with a RodRows has necessary padding added to the top and bottom. The number of elements in the resulting Seq is the same as the number of elements in the input Seq; no merging is performed.

horizontalMerge :: Seq RodRows -> RodRows Source

Merges multiple horizontal RodRows into a single RodRows. All RodRows must already have been the same height; if they are not the same height, undefined behavior occurs.

addHorizontalPadding :: Box Vertical -> Seq RodRows Source

Adds padding to the left and right of each Payload. A Payload with a Core is converted to a RodRows and has padding added; a Payload with a RodRows has necessary padding added to the left and right. The number of elements in the resulting Seq is the same as the number of elements in the input Seq; no merging is performed.

verticalMerge :: Seq RodRows -> RodRows Source

Merge multiple vertical RodRows into a single RodRows. Each RodRows should already be the same width.

newtype 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.

Constructors

Box (Seq (Payload a)) 

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.

Methods

rodRows :: Box a -> RodRows Source

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.

class LeftRight a where Source

Things that are oriented around a vertical axis.

Methods

port :: a -> Int Source

Length to the left of the vertical axis.

starboard :: a -> Int Source

Length to the right of the vertical axis.

class UpDown a where Source

Things that are oriented around a horizontal axis.

Methods

above :: a -> Int Source

Number of lines above the horizontal axis.

below :: a -> Int Source

Number of lines below the horizontal axis.

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 
-> 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.

render :: Orientation a => Box a -> Seq Chunk 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.

data Cell Source

A single cell in a spreadsheet-like grid.

Constructors

Cell 

Fields

cellRows :: Seq (Seq Chunk)

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

cellHoriz :: Alignment Horizontal

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

cellVert :: Alignment Vertical

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

cellBackground :: 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.

separator :: Radiant -> Int -> Cell Source

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

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.

addWidthMap :: Seq (Seq (Box Vertical, b, c)) -> (Map Int (Int, Int), Seq (Seq (Box Vertical, b, c))) Source

padBoxV :: Map Int (Int, Int) -> Seq (Seq (Box Vertical, a, b)) -> Seq (Seq (Box Vertical, a, b)) Source

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.

padBoxH :: Map Int (Int, Int) -> Seq (Seq (Box Horizontal, a, b)) -> Seq (Seq (Box Horizontal, a, b)) Source

equalize :: a -> Seq (Seq a) -> Seq (Seq a) Source

Ensures that each inner Seq is the same length by adding the given empty element where needed.

mconcatSeq :: Monoid a => Seq a -> a Source

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

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

split :: Int -> (Int, Int) Source

Split a number into two parts, so that the sum of the two parts is equal to the original number.