Safe Haskell | Safe-Inferred |
---|
Rainbox.Box
Contents
Description
Working with Box
.
A Box
is a rectangular block of text. You can paste Box
together to create new rectangles, and you can grow or reduce
existing Box
to create new Box
es.
There are only six primitive 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 horizontally -
catV
- pasteBox
together vertically -
viewH
- view aBox
, keeping the same height but possibly trimming the width -
viewV
- view aBox
, keeping the same width but possibly trimming the height
The other functions use these building blocks to do other useful things.
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.
- data Background = Background {}
- defaultBackground :: Background
- backgroundFromChunk :: Chunk -> Background
- backgroundToTextSpec :: Background -> TextSpec
- same :: Color8 -> Background
- newtype Height = Height {}
- height :: Box -> Int
- newtype Width = Width {}
- class HasWidth a where
- 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 {}
- barToBox :: Bar -> Box
- barsToBox :: Background -> Align Horiz -> [Bar] -> Box
- data Box
- unBox :: Box -> BoxP
- blank :: Background -> Height -> Width -> Box
- blankH :: Background -> Int -> Box
- blankV :: Background -> Int -> Box
- chunks :: [Chunk] -> Box
- chunk :: Chunk -> Box
- catH :: Background -> Align Vert -> [Box] -> Box
- catV :: Background -> Align Horiz -> [Box] -> Box
- sepH :: Background -> Int -> Align Vert -> [Box] -> Box
- sepV :: Background -> Int -> Align Horiz -> [Box] -> Box
- punctuateH :: Background -> Align Vert -> Box -> [Box] -> Box
- punctuateV :: Background -> Align Horiz -> Box -> [Box] -> Box
- view :: Height -> Width -> Align Vert -> Align Horiz -> Box -> Box
- viewH :: Int -> Align Horiz -> Box -> Box
- viewV :: Int -> Align Vert -> Box -> Box
- grow :: Background -> Height -> Width -> Align Vert -> Align Horiz -> Box -> Box
- growH :: Background -> Int -> Align Horiz -> Box -> Box
- growV :: Background -> Int -> Align Vert -> Box -> Box
- column :: Background -> Align Horiz -> [Box] -> [Box]
- resize :: Background -> Height -> Width -> Align Vert -> Align Horiz -> Box -> Box
- resizeH :: Background -> Int -> Align Horiz -> Box -> Box
- resizeV :: Background -> Int -> Align Vert -> Box -> Box
- render :: Box -> [Chunk]
- printBox :: Box -> IO ()
Backgrounds
data Background Source
Background colors to use when inserting necessary padding.
Constructors
Background | |
Fields |
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.
Height and columns
A count of rows
A count of columns
Alignment
Box properties
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.
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.
Making Boxes
blankH :: Background -> Int -> BoxSource
A blank horizontal box with a given width and no height.
blankV :: Background -> Int -> BoxSource
A blank vertical box with a given length.
Pasting Boxes together
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
---........... ----------.... --------------
sepH :: Background -> Int -> Align Vert -> [Box] -> BoxSource
sepH sep a bs
lays out bs
horizontally with alignment a
,
with sep
amount of space in between each.
sepV :: Background -> Int -> Align Horiz -> [Box] -> BoxSource
sepV sep a bs
lays out bs
vertically with alignment a
,
with sep
amount of space in between each.
punctuateH :: Background -> Align Vert -> Box -> [Box] -> BoxSource
punctuateH a p bs
horizontally lays out the boxes bs
with a
copy of p
interspersed between each.
punctuateV :: Background -> Align Horiz -> Box -> [Box] -> BoxSource
A vertical version of punctuateH
.
Viewing Boxes
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
Growing Boxes
grow :: Background -> Height -> Width -> Align Vert -> Align Horiz -> Box -> BoxSource
Grow a box. Each dimension of the result Box
is never smaller
than the corresponding dimension of the input Box
. Analogous to
view
, so you give the resulting dimensions that you want. The
alignment is analogous to view
; for instance, if you specify
that the alignment is top
and left
, the extra padding is
added to the right and bottom sides of the resulting Box
.
Grow a Box
horizontally.
Grow a Box
vertically.
Resizing
Resize horizontally.
Resize vertically.