Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- class Cell a where
- dropLeft :: Int -> a -> a
- dropRight :: Int -> a -> a
- dropBoth :: Int -> Int -> a -> a
- visibleLength :: a -> Int
- measureAlignment :: (Char -> Bool) -> a -> AlignInfo
- buildCell :: StringBuilder b => a -> b
- remSpacesB :: (Cell a, StringBuilder b) => Int -> a -> b
- remSpacesB' :: StringBuilder b => Int -> Int -> b
- fillRight :: (Cell a, StringBuilder b) => Int -> a -> b
- fillCenter :: (Cell a, StringBuilder b) => Int -> a -> b
- fillLeft :: (Cell a, StringBuilder b) => Int -> a -> b
- pad :: (Cell a, StringBuilder b) => Position o -> Int -> a -> b
- trimOrPad :: (Cell a, StringBuilder b) => Position o -> CutMark -> Int -> a -> b
- trim :: (Cell a, StringBuilder b) => Position o -> CutMark -> Int -> a -> b
- align :: (Cell a, StringBuilder b) => OccSpec -> AlignInfo -> a -> b
- data CutAction
- surplusSpace :: CutAction -> Int
- determineCutAction :: Int -> Int -> CutAction
- data CutInfo
- determineCuts :: Int -> Int -> Int -> Int -> CutInfo
- spacesAfterCut :: StringBuilder b => CutAction -> Int -> Int -> b
- applyCutInfo :: (Cell a, StringBuilder b) => CutInfo -> CutMark -> Int -> Int -> a -> b
- viewRange :: Position o -> Int -> Int -> Int -> (Int, Int)
- cellRange :: Int -> AlignInfo -> (Int, Int)
- alignFixed :: (Cell a, StringBuilder b) => Position o -> CutMark -> Int -> OccSpec -> AlignInfo -> a -> b
Documentation
Types that can be shortened, measured for visible characters, and turned
into a StringBuilder
.
dropLeft :: Int -> a -> a Source #
Drop a number of characters from the left side. Treats negative numbers as zero.
dropRight :: Int -> a -> a Source #
Drop a number of characters from the right side. Treats negative numbers as zero.
dropBoth :: Int -> Int -> a -> a Source #
Drop characters from both sides. Treats negative numbers as zero.
visibleLength :: a -> Int Source #
Returns the length of the visible characters as displayed on the output medium.
measureAlignment :: (Char -> Bool) -> a -> AlignInfo Source #
Measure the preceeding and following characters for a position where the predicate matches.
buildCell :: StringBuilder b => a -> b Source #
Insert the contents into a StringBuilder
.
Instances
Cell String Source # | |
Defined in Text.Layout.Table.Cell | |
Cell a => Cell (Formatted a) Source # | |
Defined in Text.Layout.Table.Cell.Formatted dropLeft :: Int -> Formatted a -> Formatted a Source # dropRight :: Int -> Formatted a -> Formatted a Source # dropBoth :: Int -> Int -> Formatted a -> Formatted a Source # visibleLength :: Formatted a -> Int Source # measureAlignment :: (Char -> Bool) -> Formatted a -> AlignInfo Source # buildCell :: StringBuilder b => Formatted a -> b Source # |
remSpacesB :: (Cell a, StringBuilder b) => Int -> a -> b Source #
remSpacesB' :: StringBuilder b => Int -> Int -> b Source #
fillRight :: (Cell a, StringBuilder b) => Int -> a -> b Source #
Fill the right side with spaces if necessary.
fillCenter :: (Cell a, StringBuilder b) => Int -> a -> b Source #
Fill both sides with spaces if necessary.
fillLeft :: (Cell a, StringBuilder b) => Int -> a -> b Source #
Fill the left side with spaces if necessary.
pad :: (Cell a, StringBuilder b) => Position o -> Int -> a -> b Source #
Assume the given length is greater or equal than the length of the cell passed. Pads the given cell accordingly using the position specification.
>>>
pad left 10 "foo" :: String
"foo "
trim :: (Cell a, StringBuilder b) => Position o -> CutMark -> Int -> a -> b Source #
Trim a cell based on the position. Preconditions that require to be met (otherwise the function will produce garbage): prop> visibleLength c > n
align :: (Cell a, StringBuilder b) => OccSpec -> AlignInfo -> a -> b Source #
Align a cell by first locating the position to align with and then padding on both sides. If no such position is found, it will align it such that it gets aligned before that position.
>>>
let { os = predOccSpec (== '.') ; ai = deriveAlignInfo os "iiii.fff" }
>>>
in align os ai <$> ["1.5", "30", ".25"] :: [String]
[" 1.5 "," 30 "," .25 "]
This function assumes that the given String
fits the AlignInfo
. Thus:
ai <> deriveAlignInfo s = ai
Instances
surplusSpace :: CutAction -> Int Source #
SidesCI CutAction CutAction | Apply a cut action to each side. |
MarkLeftCI | Apply a mark to a whitespace string pointing to the left. |
MarkRightCI | Apply a mark to a whitespace string pointing to the right. |
determineCuts :: Int -> Int -> Int -> Int -> CutInfo Source #
Compares the view range, that represents the visible part, with the cell range, which is the position of the cell relative to the alignment, and determines the actions that should be performed.
spacesAfterCut :: StringBuilder b => CutAction -> Int -> Int -> b Source #
If the amount to be cut is bigger than the cell length then any missing amount is taken away from any remaining padding.
applyCutInfo :: (Cell a, StringBuilder b) => CutInfo -> CutMark -> Int -> Int -> a -> b Source #
viewRange :: Position o -> Int -> Int -> Int -> (Int, Int) Source #
Given a position, the available width, and the length of an alignment (left and right side, separator is implied) compute a range for the view. The lower bound is inclusive and the upper bound exclusive.
cellRange :: Int -> AlignInfo -> (Int, Int) Source #
Given the maximum left alignment and the alignment of the cell create a range that describes the position of the cell. The lower bound is inclusive and the upper bound exclusive.
alignFixed :: (Cell a, StringBuilder b) => Position o -> CutMark -> Int -> OccSpec -> AlignInfo -> a -> b Source #
Aligns a cell using a fixed width, fitting it to the width by either filling or cutting while respecting the alignment.