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

Safe HaskellSafe-Inferred
LanguageHaskell2010

Rainbox

Contents

Description

Create grids of (possibly) colorful boxes.

For an introduction, see Rainbox.Tutorial. That file is written in literate Haskell, so you will want to look at the source itself. HsColour does not do very well with literate Haskell, so you will want to view the file in your text editor or on Github:

https://github.com/massysett/rainbox/blob/master/lib/Rainbox/Tutorial.lhs

This module only helps you create simple grids of cells, rather like a spreadsheet that does not allow you to merge or split cells. If your needs are more complicated, use Rainbox.Box, which allows you to build Boxes of arbitrary complexity by pasting simpler Boxes together. (You can of course use this module together with Rainbox.Box to create very complex layouts.)

Synopsis

Alignment

data Align a Source

Alignment.

Instances

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

data Horiz Source

Horizontal alignment.

Instances

data Vert Source

Vertical alignment.

Instances

Bar

newtype Bar Source

Occupies a single row on screen. The Chunks 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]
 

Cell and Box

data Cell Source

A Cell consists of multiple screen lines; each screen line is a Bar.

Constructors

Cell 

Fields

bars :: [Bar]

Each Bar is one line on the screen.

horiz :: Align Horiz

How this Cell aligns compared to the other Cell in its column; use left, center, or right.

vert :: Align Vert

How this Cell aligns compared to other Cell in its row; use top, center, or bottom.

background :: Radiant

Background color for necessary padding that is added to the Cell to make it the correct width and height. Does not affect the Chunk contained in the bars; these will use the colors that are designated in the Chunk itself.

Instances

Eq Cell 
Show Cell 
IsString Cell

Creates a Cell with a left horizontal alignment, a top vertical alignment, and a background of noColorRadianat. The cell will be one Bar tall and contain the text given in the string.

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.

Creating Box and gluing them together

For simple needs you will only need gridByRows or gridByCols; boxCells and glueBoxes are provided for more complex needs.

gridByRows :: [[Cell]] -> Box Source

Creates a single Box from a list of rows of Cell. Each list is a row of Cell. The list of rows is from top to bottom; within each row, the cells are given from left to right. All rows will be the same length as the first row. Any row that is longer than the first row will have cells lopped off of the end, and any row that is shorter than the first row will be padded with empty cells on the end.

gridByCols :: [[Cell]] -> Box Source

Creates a single Box from a list of columns of Cell. Each list is a column of Cell. The list of columns is from left to right; within each column, the cells are given from top to bottom. All columns will be the same height as the first column. Any column that is longer than the first column will have cells lopped off the bottom, and any column that is shorter than the first column will be padded on the bottom with blank cells.

boxCells :: (Ix col, Ix row) => Array (col, row) Cell -> Array (col, row) Box Source

Transforms a grid of Cell to a grid of Box by adding necessary padding to each Cell. In every row of the array, all the Box will have equal height; in every column of the array, all the Box will have equal width.

glueBoxes :: (Ix col, Ix row) => Array (col, row) Box -> Box Source

Use catH and catV to fuse an array of Box into a single Box. For example, if the bounds of the array are ((0,0),(3,5)), then the array has the number of cells given by rangeSize ((0,0), (3,5)) (that is, 24). The upper left corner is (0,0) and the lower right corner is (3,5); the upper right and lower left corners are (3,0) and (0,5), respectively.

Rendering

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.