rainbox-0.24.2.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 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 # 
Instance details

Defined in Rainbox.Core

Methods

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

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

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

Defined in Rainbox.Core

Methods

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

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

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

Defined in Rainbox.Core

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

Defined in Rainbox.Core

Semigroup (Alignment a) Source # 
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) Source #

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

Instance details

Defined in Rainbox.Core

data Horizontal Source #

Determines how a payload aligns with a horizontal axis.

Constructors

Top 
Bottom 
Instances
Eq Horizontal Source # 
Instance details

Defined in Rainbox.Core

Ord Horizontal Source # 
Instance details

Defined in Rainbox.Core

Show Horizontal Source # 
Instance details

Defined in Rainbox.Core

Orientation Horizontal Source # 
Instance details

Defined in Rainbox.Core

UpDown (Box Horizontal) Source # 
Instance details

Defined in Rainbox.Core

UpDown (Payload Horizontal) Source # 
Instance details

Defined in Rainbox.Core

HasWidth (Box Horizontal) Source # 
Instance details

Defined in Rainbox.Core

HasHeight (Box Horizontal) Source # 
Instance details

Defined in Rainbox.Core

data Vertical Source #

Determines how a payload aligns with a vertical axis.

Constructors

Port 
Starboard 
Instances
Eq Vertical Source # 
Instance details

Defined in Rainbox.Core

Ord Vertical Source # 
Instance details

Defined in Rainbox.Core

Show Vertical Source # 
Instance details

Defined in Rainbox.Core

Orientation Vertical Source # 
Instance details

Defined in Rainbox.Core

LeftRight (Box Vertical) Source # 
Instance details

Defined in Rainbox.Core

LeftRight (Payload Vertical) Source # 
Instance details

Defined in Rainbox.Core

HasWidth (Box Vertical) Source # 
Instance details

Defined in Rainbox.Core

Methods

width :: Box Vertical -> Int Source #

HasHeight (Box Vertical) Source # 
Instance details

Defined in Rainbox.Core

Methods

height :: Box Vertical -> Int Source #

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 
Instances
Eq Height Source # 
Instance details

Defined in Rainbox.Core

Methods

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

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

Ord Height Source # 
Instance details

Defined in Rainbox.Core

Show Height Source # 
Instance details

Defined in Rainbox.Core

HasHeight Height Source # 
Instance details

Defined in Rainbox.Core

Methods

height :: Height -> Int Source #

newtype Width Source #

A count of columns.

Constructors

Width Int 
Instances
Eq Width Source # 
Instance details

Defined in Rainbox.Core

Methods

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

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

Ord Width Source # 
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 Source # 
Instance details

Defined in Rainbox.Core

Methods

showsPrec :: Int -> Width -> ShowS #

show :: Width -> String #

showList :: [Width] -> ShowS #

HasWidth Width Source # 
Instance details

Defined in Rainbox.Core

Methods

width :: Width -> Int Source #

class HasHeight a where Source #

Methods

height :: a -> Int Source #

Instances
HasHeight Chunk Source # 
Instance details

Defined in Rainbox.Core

Methods

height :: Chunk -> Int Source #

HasHeight RodRows Source # 
Instance details

Defined in Rainbox.Core

Methods

height :: RodRows -> Int Source #

HasHeight Core Source # 
Instance details

Defined in Rainbox.Core

Methods

height :: Core -> Int Source #

HasHeight Height Source # 
Instance details

Defined in Rainbox.Core

Methods

height :: Height -> Int Source #

HasHeight (Box Vertical) Source # 
Instance details

Defined in Rainbox.Core

Methods

height :: Box Vertical -> Int Source #

HasHeight (Box Horizontal) Source # 
Instance details

Defined in Rainbox.Core

HasHeight (Payload a) Source # 
Instance details

Defined in Rainbox.Core

Methods

height :: Payload a -> Int Source #

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

Defined in Rainbox.Core

Methods

height :: Either a b -> Int Source #

class HasWidth a where Source #

Methods

width :: a -> Int Source #

Instances
HasWidth Chunk Source # 
Instance details

Defined in Rainbox.Core

Methods

width :: Chunk -> Int Source #

HasWidth RodRows Source # 
Instance details

Defined in Rainbox.Core

Methods

width :: RodRows -> Int Source #

HasWidth Rod Source # 
Instance details

Defined in Rainbox.Core

Methods

width :: Rod -> Int Source #

HasWidth Core Source # 
Instance details

Defined in Rainbox.Core

Methods

width :: Core -> Int Source #

HasWidth Width Source # 
Instance details

Defined in Rainbox.Core

Methods

width :: Width -> Int Source #

HasWidth (Box Vertical) Source # 
Instance details

Defined in Rainbox.Core

Methods

width :: Box Vertical -> Int Source #

HasWidth (Box Horizontal) Source # 
Instance details

Defined in Rainbox.Core

HasWidth (Payload a) Source # 
Instance details

Defined in Rainbox.Core

Methods

width :: Payload a -> Int Source #

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

Defined in Rainbox.Core

Methods

width :: Either a b -> 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 (Height, Width)) 
Instances
Eq Core Source # 
Instance details

Defined in Rainbox.Core

Methods

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

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

Ord Core Source # 
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 Source # 
Instance details

Defined in Rainbox.Core

Methods

showsPrec :: Int -> Core -> ShowS #

show :: Core -> String #

showList :: [Core] -> ShowS #

HasWidth Core Source # 
Instance details

Defined in Rainbox.Core

Methods

width :: Core -> Int Source #

HasHeight Core Source # 
Instance details

Defined in Rainbox.Core

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) 
Instances
Eq Rod Source # 
Instance details

Defined in Rainbox.Core

Methods

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

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

Ord Rod Source # 
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 Source # 
Instance details

Defined in Rainbox.Core

Methods

showsPrec :: Int -> Rod -> ShowS #

show :: Rod -> String #

showList :: [Rod] -> ShowS #

HasWidth Rod Source # 
Instance details

Defined in Rainbox.Core

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.

Instances
Eq RodRows Source # 
Instance details

Defined in Rainbox.Core

Methods

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

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

Ord RodRows Source # 
Instance details

Defined in Rainbox.Core

Show RodRows Source # 
Instance details

Defined in Rainbox.Core

HasWidth RodRows Source # 
Instance details

Defined in Rainbox.Core

Methods

width :: RodRows -> Int Source #

HasHeight RodRows Source # 
Instance details

Defined in Rainbox.Core

Methods

height :: RodRows -> Int Source #

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.

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

Defined in Rainbox.Core

Methods

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

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

Ord a => Ord (Payload a) Source # 
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) Source # 
Instance details

Defined in Rainbox.Core

Methods

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

show :: Payload a -> String #

showList :: [Payload a] -> ShowS #

UpDown (Payload Horizontal) Source # 
Instance details

Defined in Rainbox.Core

LeftRight (Payload Vertical) Source # 
Instance details

Defined in Rainbox.Core

HasWidth (Payload a) Source # 
Instance details

Defined in Rainbox.Core

Methods

width :: Payload a -> Int Source #

HasHeight (Payload a) Source # 
Instance details

Defined in Rainbox.Core

Methods

height :: Payload a -> Int Source #

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

Defined in Rainbox.Core

Methods

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

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

Ord a => Ord (Box a) Source # 
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) Source # 
Instance details

Defined in Rainbox.Core

Methods

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

show :: Box a -> String #

showList :: [Box a] -> ShowS #

Semigroup (Box a) Source # 
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) Source # 
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) Source # 
Instance details

Defined in Rainbox.Core

LeftRight (Box Vertical) Source # 
Instance details

Defined in Rainbox.Core

HasWidth (Box Vertical) Source # 
Instance details

Defined in Rainbox.Core

Methods

width :: Box Vertical -> Int Source #

HasWidth (Box Horizontal) Source # 
Instance details

Defined in Rainbox.Core

HasHeight (Box Vertical) Source # 
Instance details

Defined in Rainbox.Core

Methods

height :: Box Vertical -> Int Source #

HasHeight (Box Horizontal) Source # 
Instance details

Defined in Rainbox.Core

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.

Instances
LeftRight (Box Vertical) Source # 
Instance details

Defined in Rainbox.Core

LeftRight (Payload Vertical) Source # 
Instance details

Defined in Rainbox.Core

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.

Instances
UpDown (Box Horizontal) Source # 
Instance details

Defined in Rainbox.Core

UpDown (Payload Horizontal) Source # 
Instance details

Defined in Rainbox.Core

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.

hPutBox :: Orientation a => Handle -> Box a -> IO () Source #

Renders a Box to the given Handle. This uses hPutChunks so consult that function for more details on how this works; generally it is going to use the maximum number of colors possible for your terminal.

putBox :: Orientation a => Box a -> IO () Source #

Uses hPutBox to render the given Box to standard output.

data Cell Source #

A single cell in a spreadsheet-like grid.

Constructors

Cell 

Fields

Instances
Eq Cell Source # 
Instance details

Defined in Rainbox.Core

Methods

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

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

Ord Cell Source # 
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 Source # 
Instance details

Defined in Rainbox.Core

Methods

showsPrec :: Int -> Cell -> ShowS #

show :: Cell -> String #

showList :: [Cell] -> ShowS #

Semigroup Cell Source # 
Instance details

Defined in Rainbox.Core

Methods

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

sconcat :: NonEmpty Cell -> Cell #

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

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.

Instance details

Defined in Rainbox.Core

Methods

mempty :: Cell #

mappend :: Cell -> Cell -> Cell #

mconcat :: [Cell] -> Cell #

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 #