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

Safe HaskellSafe-Inferred

Rainbox.Reader

Contents

Description

Box with many functions in a Reader monad.

The advantage of this module over Rainbox is that many of the functions have fewer arguments because they are instead carried in the Reader monad. This also allows you to use four infix operators to easily join up Box. The disadvantage is that using the Reader monad adds a layer of indirection.

Synopsis

Backgrounds

data Background Source

Background colors to use when inserting necessary padding.

Instances

defaultBackground :: BackgroundSource

Use the default background colors of the current terminal.

same :: Color8 -> BackgroundSource

Use the same color for 8 and 256-color backgrounds.

Box properties

newtype Bar Source

Occupies a single row on screen. The Chunk you place in a Bar should not have any control characters such as newlines or tabs, as rainbox assumes that each character in a Bar takes up one screen column and that each character does not create newlines. Leave newline handling up to rainbox. However, rainbox will not check to make sure that your inputs do not contain newlines, tabs, or other spurious characters. Similarly, use of combining characters will create unexpected results, as Rainbox will see something that takes up (for instance) two characters and think it takes up two screen columns, when in reality it will take up only one screen column. So, if you need accented characters, use a single Unicode code point, not two code points. For example, for é, use U+00E9, not U+0065 and U+0301.

Constructors

Bar 

Fields

unBar :: [Chunk]
 

Instances

Eq Bar 
Show Bar 
IsString Bar 
Monoid Bar 
HasWidth Bar 

data Box Source

A Box has a width in columns and a height in rows. Its height and width both are always at least zero. It can have positive height even if its width is zero, and it can have positive width even if its height is zero.

Each row in a Box always has the same number of characters; a Box with zero height has no characters but still has a certain width.

Instances

Eq Box 
Show Box 
IsString Box 
HasWidth Box 

Height and columns

newtype Height Source

A count of rows

Constructors

Height 

Fields

unHeight :: Int
 

Instances

Eq Height 
Ord Height 
Show Height 

height :: Box -> IntSource

How many Rod are in this Box?

newtype Width Source

A count of columns

Constructors

Width 

Fields

unWidth :: Int
 

Instances

Eq Width 
Ord Width 
Show Width 

class HasWidth a whereSource

How many columns are in this thing? A column is one character wide. Every Bar in a Box always has the same number of columns.

This is for things that have a single, solitary width, not things like columns that might have different widths at different points.

Methods

width :: a -> IntSource

Alignment

data Align a Source

Alignment.

Instances

Eq a => Eq (Align a) 
Show a => Show (Align a) 

data Vert Source

Vertical alignment.

Instances

Eq Vert 
Show Vert 

data Horiz Source

Horizontal alignment.

Instances

Eq Horiz 
Show Horiz 

Reader monad

data Specs Source

Constructors

Specs 

Fields

background :: Background
 
alignH :: Align Horiz
 
alignV :: Align Vert
 
spaceH :: Int

Amount of intervening space for horizontal joins

spaceV :: Int
 

Instances

Eq Specs 
Show Specs 

Making Boxes

blank :: Background -> Height -> Width -> BoxSource

A blank Box. Useful for aligning other Box.

blankH :: Monad m => Int -> Env m BoxSource

blankV :: Monad m => Int -> Env m BoxSource

chunks :: [Chunk] -> BoxSource

A Box made of Chunk. Always one Bar tall, and has as many columns as there are characters in the Chunk.

chunk :: Chunk -> BoxSource

A Box made of a single Chunk.

Pasting Boxes together

catH :: Monad m => [Box] -> Env m BoxSource

catV :: Monad m => [Box] -> Env m BoxSource

sepH :: Monad m => Int -> [Box] -> Env m BoxSource

sepV :: Monad m => Int -> [Box] -> Env m BoxSource

punctuateH :: Monad m => Box -> [Box] -> Env m BoxSource

punctuateV :: Monad m => Box -> [Box] -> Env m BoxSource

(<->) :: Monad m => Box -> Box -> Env m BoxSource

Paste two Box together horizontally with no intervening space. Left fixity, precedence 5.

(<+>) :: Monad m => Box -> Box -> Env m BoxSource

Paste two Box together horizontally. Intervening space is determined by spaceH. Left fixity, precedence 5.

(/-/) :: Monad m => Box -> Box -> Env m BoxSource

Paste two Box together vertically with no intervening space. Left fixity, precedence 6.

(/+/) :: Monad m => Box -> Box -> Env m BoxSource

Paste two Box together vertically. Intervening space is determined by spaceV. Left fixity, precedence 6.

Viewing Boxes

view :: Monad m => Height -> Width -> Box -> Env m BoxSource

viewH :: Monad m => Int -> Box -> Env m BoxSource

viewV :: Monad m => Int -> Box -> Env m BoxSource

Growing Boxes

grow :: Monad m => Height -> Width -> Box -> Env m BoxSource

growH :: Monad m => Int -> Box -> Env m BoxSource

growV :: Monad m => Int -> Box -> Env m BoxSource

column :: Monad m => [Box] -> Env m [Box]Source

Resizing

resize :: Monad m => Height -> Width -> Box -> Env m BoxSource

resizeH :: Monad m => Int -> Box -> Env m BoxSource

resizeV :: Monad m => Int -> Box -> Env m BoxSource

Printing Boxes

render :: Box -> [Chunk]Source

Convert a Box to Rainbow Chunks. You can then print it using putChunks or the like.

printBox :: Box -> IO ()Source

Prints a Box to standard output. If standard output is not a terminal, no colors are used. Otherwise, colors are used if your TERM environment variable suggests they are available.