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

Safe HaskellSafe-Inferred
LanguageHaskell2010

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

newtype Background Source

Background colors to use when inserting necessary padding.

Constructors

Background Radiant 

Alignment

data Align a Source

Alignment.

Instances

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

data Vert Source

Vertical alignment.

Instances

data Horiz Source

Horizontal alignment.

Instances

Box

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]
 

newtype Rod Source

Constructors

Rod 

Fields

unRod :: [Nibble]
 

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

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.

Height and Width

newtype Height Source

A count of rows

Constructors

Height 

Fields

unHeight :: Int
 

Instances

height :: Box -> Int Source

How many Rod are in this Box?

newtype Width Source

A count of columns

Constructors

Width 

Fields

unWidth :: Int
 

Instances

class HasWidth a where Source

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 -> Int Source

Making Boxes

blank :: Background -> Height -> Width -> Box Source

A blank Box. Useful for aligning other Box.

chunks :: [Chunk] -> Box Source

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] -> Box Source

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] -> Box Source

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

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

---
---

----
----

becomes

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

With alignment set to right, becomes

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

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

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.