Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
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 otherBox
to provide white space.chunks
- Makes a box out of RainbowChunk
.catH
- pasteBox
together horizontallycatV
- pasteBox
together verticallyviewH
- view aBox
, keeping the same height but possibly trimming the widthviewV
- view aBox
, 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.
- newtype Background = Background Radiant
- data Align a
- data Vert
- data Horiz
- center :: Align a
- top :: Align Vert
- bottom :: Align Vert
- left :: Align Horiz
- right :: Align Horiz
- newtype Bar = Bar {}
- newtype Rod = Rod {}
- barToBox :: Bar -> Box
- barsToBox :: Background -> Align Horiz -> [Bar] -> Box
- data Nibble
- unNibble :: Nibble -> Either Spaces Chunk
- data Spaces
- numSpaces :: Spaces -> Int
- spcBackground :: Spaces -> Background
- data BoxP
- = NoHeight Int
- | WithHeight [Rod]
- data Box
- unBox :: Box -> BoxP
- newtype Height = Height {}
- height :: Box -> Int
- newtype Width = Width {}
- class HasWidth a where
- blank :: Background -> Height -> Width -> Box
- chunks :: [Chunk] -> Box
- catH :: Background -> Align Vert -> [Box] -> Box
- catV :: Background -> Align Horiz -> [Box] -> Box
- viewH :: Int -> Align Horiz -> Box -> Box
- viewV :: Int -> Align Vert -> Box -> Box
- split :: Int -> (Int, Int)
Background
newtype Background Source
Background colors to use when inserting necessary padding.
Alignment
Box
Occupies a single row on screen. The Chunk
s 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.
spcBackground :: Spaces -> Background Source
Box payload. Has the data of the box.
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. |
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
Making Boxes
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
---........... ----------.... --------------
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