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

Safe HaskellNone
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

Functor Alignment Source # 

Methods

fmap :: (a -> b) -> Alignment a -> Alignment b #

(<$) :: a -> Alignment b -> Alignment a #

Foldable Alignment Source # 

Methods

fold :: Monoid m => Alignment m -> m #

foldMap :: Monoid m => (a -> m) -> Alignment a -> m #

foldr :: (a -> b -> b) -> b -> Alignment a -> b #

foldr' :: (a -> b -> b) -> b -> Alignment a -> b #

foldl :: (b -> a -> b) -> b -> Alignment a -> b #

foldl' :: (b -> a -> b) -> b -> Alignment a -> b #

foldr1 :: (a -> a -> a) -> Alignment a -> a #

foldl1 :: (a -> a -> a) -> Alignment a -> a #

toList :: Alignment a -> [a] #

null :: Alignment a -> Bool #

length :: Alignment a -> Int #

elem :: Eq a => a -> Alignment a -> Bool #

maximum :: Ord a => Alignment a -> a #

minimum :: Ord a => Alignment a -> a #

sum :: Num a => Alignment a -> a #

product :: Num a => Alignment a -> a #

Traversable Alignment Source # 

Methods

traverse :: Applicative f => (a -> f b) -> Alignment a -> f (Alignment b) #

sequenceA :: Applicative f => Alignment (f a) -> f (Alignment a) #

mapM :: Monad m => (a -> m b) -> Alignment a -> m (Alignment b) #

sequence :: Monad m => Alignment (m a) -> m (Alignment a) #

Eq a => Eq (Alignment a) Source # 

Methods

(==) :: Alignment a -> Alignment a -> Bool #

(/=) :: Alignment a -> Alignment a -> Bool #

Ord a => Ord (Alignment a) Source # 
Show a => Show (Alignment a) Source # 
Monoid (Alignment a) Source #

mempty is center. mappend takes the rightmost non-center value.

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 

Instances

class HasHeight a where Source #

Minimal complete definition

height

Methods

height :: a -> Int Source #

class HasWidth a where Source #

Minimal complete definition

width

Methods

width :: a -> Int Source #

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 Text) (Height, Width)) 

Instances

Eq Core Source # 

Methods

(==) :: Core -> Core -> Bool #

(/=) :: Core -> Core -> Bool #

Ord Core Source # 

Methods

compare :: Core -> Core -> Ordering #

(<) :: Core -> Core -> Bool #

(<=) :: Core -> Core -> Bool #

(>) :: Core -> Core -> Bool #

(>=) :: Core -> Core -> Bool #

max :: Core -> Core -> Core #

min :: Core -> Core -> Core #

Show Core Source # 

Methods

showsPrec :: Int -> Core -> ShowS #

show :: Core -> String #

showList :: [Core] -> ShowS #

HasWidth Core Source # 

Methods

width :: Core -> Int Source #

HasHeight Core Source # 

Methods

height :: Core -> Int Source #

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 Text)) 

Instances

Eq Rod Source # 

Methods

(==) :: Rod -> Rod -> Bool #

(/=) :: Rod -> Rod -> Bool #

Ord Rod Source # 

Methods

compare :: Rod -> Rod -> Ordering #

(<) :: Rod -> Rod -> Bool #

(<=) :: Rod -> Rod -> Bool #

(>) :: Rod -> Rod -> Bool #

(>=) :: Rod -> Rod -> Bool #

max :: Rod -> Rod -> Rod #

min :: Rod -> Rod -> Rod #

Show Rod Source # 

Methods

showsPrec :: Int -> Rod -> ShowS #

show :: Rod -> String #

showList :: [Rod] -> ShowS #

HasWidth Rod Source # 

Methods

width :: Rod -> Int Source #

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

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.

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

Instances

Eq a => Eq (Box a) Source # 

Methods

(==) :: Box a -> Box a -> Bool #

(/=) :: Box a -> Box a -> Bool #

Ord a => Ord (Box a) Source # 

Methods

compare :: Box a -> Box a -> Ordering #

(<) :: Box a -> Box a -> Bool #

(<=) :: Box a -> Box a -> Bool #

(>) :: Box a -> Box a -> Bool #

(>=) :: Box a -> Box a -> Bool #

max :: Box a -> Box a -> Box a #

min :: Box a -> Box a -> Box a #

Show a => Show (Box a) Source # 

Methods

showsPrec :: Int -> Box a -> ShowS #

show :: Box a -> String #

showList :: [Box a] -> ShowS #

Monoid (Box a) Source # 

Methods

mempty :: Box a #

mappend :: Box a -> Box a -> Box a #

mconcat :: [Box a] -> Box a #

UpDown (Box Horizontal) Source # 
LeftRight (Box Vertical) Source # 
HasWidth (Box Vertical) Source # 

Methods

width :: Box Vertical -> Int Source #

HasWidth (Box Horizontal) Source # 
HasHeight (Box Vertical) Source # 

Methods

height :: Box Vertical -> Int Source #

HasHeight (Box Horizontal) Source # 

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

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.

Minimal complete definition

port, starboard

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.

Minimal complete definition

above, below

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

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.

data Cell Source #

A single cell in a spreadsheet-like grid.

Constructors

Cell 

Fields

Instances

Eq Cell Source # 

Methods

(==) :: Cell -> Cell -> Bool #

(/=) :: Cell -> Cell -> Bool #

Ord Cell Source # 

Methods

compare :: Cell -> Cell -> Ordering #

(<) :: Cell -> Cell -> Bool #

(<=) :: Cell -> Cell -> Bool #

(>) :: Cell -> Cell -> Bool #

(>=) :: Cell -> Cell -> Bool #

max :: Cell -> Cell -> Cell #

min :: Cell -> Cell -> Cell #

Show Cell Source # 

Methods

showsPrec :: Int -> Cell -> ShowS #

show :: Cell -> String #

showList :: [Cell] -> ShowS #

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.

Methods

mempty :: Cell #

mappend :: Cell -> Cell -> Cell #

mconcat :: [Cell] -> Cell #

rows :: Functor f => (Seq (Seq (Chunk Text)) -> f (Seq (Seq (Chunk Text)))) -> Cell -> f Cell Source #

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.

addHeightMap :: Seq (Seq (Box Horizontal, b, c)) -> (Map Int (Int, Int), Seq (Seq (Box Horizontal, b, c))) Source #

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.