Safe Haskell | None |
---|---|
Language | Haskell2010 |
Typically to use Rainbox you will want these import
s:
import qualified Data.Sequence as Seq import Rainbow import Rainbox -- and, for GHC before 7.10: import Data.Monoid
Rainbox does not re-export anything from Data.Sequence or Rainbow because I don't know if you want all those things dumped into the same namespace.
Rainbox.Tutorial wil get you started. Rainbox.Core contains the implementation details, which you should not need to pay attention to (if you do need to use Rainbox.Core for ordinary usage of the library, that's a bug; please report it.)
- data Alignment a
- data Horizontal
- data Vertical
- center :: Alignment a
- left :: Alignment Vertical
- right :: Alignment Vertical
- top :: Alignment Horizontal
- bottom :: Alignment Horizontal
- centerH :: Alignment Horizontal
- centerV :: Alignment Vertical
- data Box a
- class Orientation a where
- fromChunk :: Alignment a -> Radiant -> Chunk Text -> Box a
- blank :: Alignment a -> Radiant -> Height -> Width -> Box a
- wrap :: Orientation a => Alignment b -> Radiant -> Box a -> Box b
- render :: Orientation a => Box a -> Seq (Chunk Text)
- data Cell = Cell {
- _rows :: Seq (Seq (Chunk Text))
- _horizontal :: Alignment Horizontal
- _vertical :: Alignment Vertical
- _background :: Radiant
- rows :: Lens' Cell (Seq (Seq (Chunk Text)))
- horizontal :: Lens' Cell (Alignment Horizontal)
- vertical :: Lens' Cell (Alignment Vertical)
- background :: Lens' Cell Radiant
- tableByRows :: Seq (Seq Cell) -> Box Vertical
- tableByColumns :: Seq (Seq Cell) -> Box Horizontal
- separator :: Radiant -> Int -> Cell
- intersperse :: a -> Seq a -> Seq a
Alignment and Boxes
Alignment. Used in conjunction with Horizontal
and Vertical
,
this determines how a payload aligns with the axis of a Box
.
data Horizontal Source
Determines how a payload aligns with a horizontal axis.
Determines how a payload aligns with a vertical axis.
Place this payload so that it is centered on the vertical axis or horizontal axis.
top :: Alignment Horizontal Source
Place this payload's top edge on the horizontal axis.
bottom :: Alignment Horizontal Source
Place this payload's bottom edge on the horizontal axis.
centerH :: Alignment Horizontal Source
Center horizontally; like center
, but monomorphic.
A Box
is the central building block. It consists of zero or
more payloads; each payload has the same orientation, which is either
Horizontal
or Vertical
. This orientation also determines
the orientation of the entire Box
.
A Box
is a Monoid
so you can combine them using the usual
monoid functions. For a Box
Vertical
, the leftmost values
added with mappend
are at the top of the Box
; for a Box
Horizontal
, the leftmost values added with mappend
are on the
left side of the Box
.
class Orientation a where Source
This typeclass is responsible for transforming a Box
into
Rainbow Chunk
so they can be printed to your screen. This
requires adding appropriate whitespace with the right colors, as
well as adding newlines in the right places.
spacer :: Radiant -> Int -> Box a Source
Builds a one-dimensional box of the given size; its single
dimension is parallel to the axis. When added to a
box, it will insert blank space of the given length. For a Box
Horizontal
, this produces a horizontal line; for a Box
Vertical
, a vertical line.
spreader :: Alignment a -> Int -> Box a Source
Builds a one-dimensional box of the given size; its single
dimension is perpendicular to the axis. This can be used to make
a Box
Vertical
wider or a Box
Horizontal
taller.
Box construction
:: Alignment a | |
-> Radiant | Background color. The background color in the |
-> Chunk Text | |
-> Box a |
Construct a box from a single Chunk
.
:: Orientation a | |
=> Alignment b | Alignment for new |
-> Radiant | Background color for new box |
-> Box a | |
-> Box b |
Rendering
Tables
A single cell in a spreadsheet-like grid.
Cell | |
|
Eq Cell Source | |
Ord Cell Source | |
Show Cell Source | |
Monoid Cell Source |
|
tableByRows :: Seq (Seq Cell) -> Box Vertical Source
Create a table where each inner Seq
is a row of cells,
from left to right. If necessary, blank cells are added to the end
of a row to ensure that each row has the same number of cells as
the longest row.
tableByColumns :: Seq (Seq Cell) -> Box Horizontal Source
Create a table where each inner Seq
is a column of cells,
from top to bottom. If necessary, blank cells are added to the end
of a column to ensure that each column has the same number of cells
as the longest column.
separator :: Radiant -> Int -> Cell Source
Creates a blank Cell
with the given background color and width;
useful for adding separators between columns.
Utilities
intersperse :: a -> Seq a -> Seq a Source
Like intersperse
in Data.List, but works on Seq
.