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

Safe HaskellSafe-Inferred

Rainbox.Box.Primitives

Contents

Description

Box primitives.

This module provides all functions that have access to the internals of a Box. There are only six functions that make a Box:

  • blank - formats a blank box with nothing but a (possibly) colorful background. Useful to paste to other Box to provide white space.
  • chunks - Makes a box out of Rainbow Chunk.
  • catH - paste Box together horizontally
  • catV - paste Box together vertically
  • viewH - view a Box, keeping the same height but possibly trimming the width
  • viewV - view a Box, keeping the same width but possibly trimming the height

There are many crude diagrams in the Haddock documentation. A dash means a character with data; a period means a blank character. When you print your Box, the blank characters will have the appropriate background color.

Synopsis

Background

data Background Source

Background colors to use when inserting necessary padding.

Instances

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 

Box

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 

newtype Rod Source

Constructors

Rod 

Fields

unRod :: [Nibble]
 

Instances

Eq Rod 
Show Rod 
IsString Rod 
HasWidth Rod 

data Nibble Source

Instances

Eq Nibble 
Show Nibble 
IsString Nibble 
HasWidth Nibble 

data Spaces Source

Instances

data BoxP Source

Box payload. Has the data of the box.

Constructors

NoHeight Int

A Box with width but no height. The Int must be at least zero. If it is zero, the Box has no height and no width.

WithHeight [Rod]

A Box that has height of at least one. It must have at least one component Bar.

Instances

Eq BoxP 
Show BoxP 
HasWidth BoxP 

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 Width

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

Making Boxes

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

A blank Box. Useful for aligning other Box.

chunks :: [Chunk] -> BoxSource

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

catH :: Background -> Align Vert -> [Box] -> BoxSource

Merge several Box horizontally into one Box. That is, with alignment set to ATop:

 --- ------- ----
 --- -------
 ---

becomes

 --------------
 ----------....
 ---...........

With alignment set to ABottom, becomes

 ---...........
 ----------....
 --------------

catV :: Background -> Align Horiz -> [Box] -> BoxSource

Merge several Box vertically into one Box. That is, with alignment set to left:

 -------
 -------

 ---
 ---

 ----
 ----

becomes

 -------
 -------
 ---....
 ---....
 ---....
 ----...
 ----...

With alignment set to right, becomes

 -------
 -------
 ....---
 ....---
 ...----
 ...----

viewH :: Int -> Align Horiz -> Box -> BoxSource

viewV :: Int -> Align Vert -> Box -> BoxSource

View a Box, possibly shrinking it. You set the size of your viewport and how it is oriented relative to the Box as a whole. The Box returned may be smaller than the argument Box, but it will never be bigger.

Examples:

>>> :set -XOverloadedStrings
>>> let box = catV defaultBackground top [ "ab", "cd" ]
>>> printBox . view (Height 1) (Width 1) left top $ box
a
>>> printBox . view (Height 1) (Width 1) right bottom $ box
d

Helpers

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.