rainbox-0.20.0.0: 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 #

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 # 
Instance details

Defined in Rainbox.Core

Methods

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

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

Foldable Alignment # 
Instance details

Defined in Rainbox.Core

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 # 
Instance details

Defined in Rainbox.Core

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) # 
Instance details

Defined in Rainbox.Core

Methods

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

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

Ord a => Ord (Alignment a) # 
Instance details

Defined in Rainbox.Core

Show a => Show (Alignment a) # 
Instance details

Defined in Rainbox.Core

Semigroup (Alignment a) # 
Instance details

Defined in Rainbox.Core

Methods

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

sconcat :: NonEmpty (Alignment a) -> Alignment a #

stimes :: Integral b => b -> Alignment a -> Alignment a #

Monoid (Alignment a) #

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

Instance details

Defined in Rainbox.Core

data Horizontal #

Determines how a payload aligns with a horizontal axis.

Constructors

Top 
Bottom 
Instances
Eq Horizontal # 
Instance details

Defined in Rainbox.Core

Ord Horizontal # 
Instance details

Defined in Rainbox.Core

Show Horizontal # 
Instance details

Defined in Rainbox.Core

Orientation Horizontal # 
Instance details

Defined in Rainbox.Core

UpDown (Box Horizontal) # 
Instance details

Defined in Rainbox.Core

UpDown (Payload Horizontal) # 
Instance details

Defined in Rainbox.Core

HasWidth (Box Horizontal) # 
Instance details

Defined in Rainbox.Core

Methods

width :: Box Horizontal -> Int #

HasHeight (Box Horizontal) # 
Instance details

Defined in Rainbox.Core

Methods

height :: Box Horizontal -> Int #

data Vertical #

Determines how a payload aligns with a vertical axis.

Constructors

Port 
Starboard 
Instances
Eq Vertical # 
Instance details

Defined in Rainbox.Core

Ord Vertical # 
Instance details

Defined in Rainbox.Core

Show Vertical # 
Instance details

Defined in Rainbox.Core

Orientation Vertical # 
Instance details

Defined in Rainbox.Core

LeftRight (Box Vertical) # 
Instance details

Defined in Rainbox.Core

LeftRight (Payload Vertical) # 
Instance details

Defined in Rainbox.Core

HasWidth (Box Vertical) # 
Instance details

Defined in Rainbox.Core

Methods

width :: Box Vertical -> Int #

HasHeight (Box Vertical) # 
Instance details

Defined in Rainbox.Core

Methods

height :: Box Vertical -> Int #

center :: Alignment a #

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

centerH :: Alignment Horizontal #

Center horizontally; like center, but monomorphic.

centerV :: Alignment Vertical #

Center vertically; like center, but monomorphic.

left :: Alignment Vertical #

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

right :: Alignment Vertical #

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

top :: Alignment Horizontal #

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

bottom :: Alignment Horizontal #

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

newtype Height #

A count of rows.

Constructors

Height Int 
Instances
Eq Height # 
Instance details

Defined in Rainbox.Core

Methods

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

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

Ord Height # 
Instance details

Defined in Rainbox.Core

Show Height # 
Instance details

Defined in Rainbox.Core

HasHeight Height # 
Instance details

Defined in Rainbox.Core

Methods

height :: Height -> Int #

newtype Width #

A count of columns.

Constructors

Width Int 
Instances
Eq Width # 
Instance details

Defined in Rainbox.Core

Methods

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

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

Ord Width # 
Instance details

Defined in Rainbox.Core

Methods

compare :: Width -> Width -> Ordering #

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

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

(>) :: Width -> Width -> Bool #

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

max :: Width -> Width -> Width #

min :: Width -> Width -> Width #

Show Width # 
Instance details

Defined in Rainbox.Core

Methods

showsPrec :: Int -> Width -> ShowS #

show :: Width -> String #

showList :: [Width] -> ShowS #

HasWidth Width # 
Instance details

Defined in Rainbox.Core

Methods

width :: Width -> Int #

class HasHeight a where #

Methods

height :: a -> Int #

Instances
HasHeight RodRows # 
Instance details

Defined in Rainbox.Core

Methods

height :: RodRows -> Int #

HasHeight Core # 
Instance details

Defined in Rainbox.Core

Methods

height :: Core -> Int #

HasHeight Height # 
Instance details

Defined in Rainbox.Core

Methods

height :: Height -> Int #

HasHeight (Chunk a) # 
Instance details

Defined in Rainbox.Core

Methods

height :: Chunk a -> Int #

HasHeight (Box Vertical) # 
Instance details

Defined in Rainbox.Core

Methods

height :: Box Vertical -> Int #

HasHeight (Box Horizontal) # 
Instance details

Defined in Rainbox.Core

Methods

height :: Box Horizontal -> Int #

HasHeight (Payload a) # 
Instance details

Defined in Rainbox.Core

Methods

height :: Payload a -> Int #

(HasHeight a, HasHeight b) => HasHeight (Either a b) # 
Instance details

Defined in Rainbox.Core

Methods

height :: Either a b -> Int #

class HasWidth a where #

Methods

width :: a -> Int #

Instances
HasWidth RodRows # 
Instance details

Defined in Rainbox.Core

Methods

width :: RodRows -> Int #

HasWidth Rod # 
Instance details

Defined in Rainbox.Core

Methods

width :: Rod -> Int #

HasWidth Core # 
Instance details

Defined in Rainbox.Core

Methods

width :: Core -> Int #

HasWidth Width # 
Instance details

Defined in Rainbox.Core

Methods

width :: Width -> Int #

HasWidth (Chunk Text) # 
Instance details

Defined in Rainbox.Core

Methods

width :: Chunk Text -> Int #

HasWidth (Box Vertical) # 
Instance details

Defined in Rainbox.Core

Methods

width :: Box Vertical -> Int #

HasWidth (Box Horizontal) # 
Instance details

Defined in Rainbox.Core

Methods

width :: Box Horizontal -> Int #

HasWidth (Payload a) # 
Instance details

Defined in Rainbox.Core

Methods

width :: Payload a -> Int #

(HasWidth a, HasWidth b) => HasWidth (Either a b) # 
Instance details

Defined in Rainbox.Core

Methods

width :: Either a b -> Int #

newtype Core #

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 # 
Instance details

Defined in Rainbox.Core

Methods

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

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

Ord Core # 
Instance details

Defined in Rainbox.Core

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 # 
Instance details

Defined in Rainbox.Core

Methods

showsPrec :: Int -> Core -> ShowS #

show :: Core -> String #

showList :: [Core] -> ShowS #

HasWidth Core # 
Instance details

Defined in Rainbox.Core

Methods

width :: Core -> Int #

HasHeight Core # 
Instance details

Defined in Rainbox.Core

Methods

height :: Core -> Int #

newtype Rod #

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 # 
Instance details

Defined in Rainbox.Core

Methods

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

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

Ord Rod # 
Instance details

Defined in Rainbox.Core

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 # 
Instance details

Defined in Rainbox.Core

Methods

showsPrec :: Int -> Rod -> ShowS #

show :: Rod -> String #

showList :: [Rod] -> ShowS #

HasWidth Rod # 
Instance details

Defined in Rainbox.Core

Methods

width :: Rod -> Int #

data RodRows #

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.

Instances
Eq RodRows # 
Instance details

Defined in Rainbox.Core

Methods

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

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

Ord RodRows # 
Instance details

Defined in Rainbox.Core

Show RodRows # 
Instance details

Defined in Rainbox.Core

HasWidth RodRows # 
Instance details

Defined in Rainbox.Core

Methods

width :: RodRows -> Int #

HasHeight RodRows # 
Instance details

Defined in Rainbox.Core

Methods

height :: RodRows -> Int #

rodRowsFromCore :: Radiant -> Core -> RodRows #

Convert a Core to a Seq of Rod for rendering.

chunksFromRodRows :: RodRows -> Seq (Seq (Chunk Text)) #

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 #

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.

Instances
Eq a => Eq (Payload a) # 
Instance details

Defined in Rainbox.Core

Methods

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

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

Ord a => Ord (Payload a) # 
Instance details

Defined in Rainbox.Core

Methods

compare :: Payload a -> Payload a -> Ordering #

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

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

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

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

max :: Payload a -> Payload a -> Payload a #

min :: Payload a -> Payload a -> Payload a #

Show a => Show (Payload a) # 
Instance details

Defined in Rainbox.Core

Methods

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

show :: Payload a -> String #

showList :: [Payload a] -> ShowS #

UpDown (Payload Horizontal) # 
Instance details

Defined in Rainbox.Core

LeftRight (Payload Vertical) # 
Instance details

Defined in Rainbox.Core

HasWidth (Payload a) # 
Instance details

Defined in Rainbox.Core

Methods

width :: Payload a -> Int #

HasHeight (Payload a) # 
Instance details

Defined in Rainbox.Core

Methods

height :: Payload a -> Int #

addVerticalPadding :: Box Horizontal -> Seq RodRows #

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 #

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

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 #

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 #

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

newtype Box a #

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) # 
Instance details

Defined in Rainbox.Core

Methods

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

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

Ord a => Ord (Box a) # 
Instance details

Defined in Rainbox.Core

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) # 
Instance details

Defined in Rainbox.Core

Methods

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

show :: Box a -> String #

showList :: [Box a] -> ShowS #

Semigroup (Box a) # 
Instance details

Defined in Rainbox.Core

Methods

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

sconcat :: NonEmpty (Box a) -> Box a #

stimes :: Integral b => b -> Box a -> Box a #

Monoid (Box a) # 
Instance details

Defined in Rainbox.Core

Methods

mempty :: Box a #

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

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

UpDown (Box Horizontal) # 
Instance details

Defined in Rainbox.Core

LeftRight (Box Vertical) # 
Instance details

Defined in Rainbox.Core

HasWidth (Box Vertical) # 
Instance details

Defined in Rainbox.Core

Methods

width :: Box Vertical -> Int #

HasWidth (Box Horizontal) # 
Instance details

Defined in Rainbox.Core

Methods

width :: Box Horizontal -> Int #

HasHeight (Box Vertical) # 
Instance details

Defined in Rainbox.Core

Methods

height :: Box Vertical -> Int #

HasHeight (Box Horizontal) # 
Instance details

Defined in Rainbox.Core

Methods

height :: Box Horizontal -> Int #

class Orientation a where #

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 #

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

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 #

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 #

Things that are oriented around a vertical axis.

Methods

port :: a -> Int #

Length to the left of the vertical axis.

starboard :: a -> Int #

Length to the right of the vertical axis.

Instances
LeftRight (Box Vertical) # 
Instance details

Defined in Rainbox.Core

LeftRight (Payload Vertical) # 
Instance details

Defined in Rainbox.Core

class UpDown a where #

Things that are oriented around a horizontal axis.

Methods

above :: a -> Int #

Number of lines above the horizontal axis.

below :: a -> Int #

Number of lines below the horizontal axis.

Instances
UpDown (Box Horizontal) # 
Instance details

Defined in Rainbox.Core

UpDown (Payload Horizontal) # 
Instance details

Defined in Rainbox.Core

fromChunk #

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 #

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 #

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

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 #

A single cell in a spreadsheet-like grid.

Constructors

Cell 

Fields

Instances
Eq Cell # 
Instance details

Defined in Rainbox.Core

Methods

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

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

Ord Cell # 
Instance details

Defined in Rainbox.Core

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 # 
Instance details

Defined in Rainbox.Core

Methods

showsPrec :: Int -> Cell -> ShowS #

show :: Cell -> String #

showList :: [Cell] -> ShowS #

Semigroup Cell # 
Instance details

Defined in Rainbox.Core

Methods

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

sconcat :: NonEmpty Cell -> Cell #

stimes :: Integral b => b -> Cell -> Cell #

Monoid Cell #

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.

Instance details

Defined in Rainbox.Core

Methods

mempty :: Cell #

mappend :: Cell -> Cell -> Cell #

mconcat :: [Cell] -> Cell #

background :: Functor f => (Radiant -> f Radiant) -> Cell -> f Cell #

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

separator :: Radiant -> Int -> Cell #

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

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

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

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

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

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

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

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

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

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

intersperse :: a -> Seq a -> Seq a #

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