Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- truncateNegative :: Int -> Int
- data CellView a = CellView {
- baseCell :: a
- leftAdjustment :: Int
- rightAdjustment :: Int
- adjustCell :: Int -> Int -> a -> CellView a
- dropLeft :: Int -> a -> CellView a
- dropRight :: Int -> a -> CellView a
- dropBoth :: Int -> Int -> a -> CellView a
- totalAdjustment :: CellView a -> Int
- redistributeAdjustment :: Int -> Int -> CellView a -> CellView a
- class Cell a where
- visibleLength :: a -> Int
- measureAlignment :: (Char -> Bool) -> a -> AlignInfo
- buildCell :: StringBuilder b => a -> b
- buildCellView :: StringBuilder b => CellView a -> b
- buildCellViewLRHelper :: StringBuilder b => (a -> b) -> (Int -> a -> a) -> (Int -> a -> a) -> CellView a -> b
- buildCellViewBothHelper :: StringBuilder b => (a -> b) -> (Int -> Int -> a -> a) -> CellView a -> b
- buildCellViewHelper :: StringBuilder b => (a -> b) -> (Int -> a -> b) -> (Int -> a -> b) -> (Int -> Int -> a -> b) -> CellView a -> b
- remSpacesB :: (Cell a, StringBuilder b) => Int -> a -> b
- fillRight :: Cell a => Int -> a -> CellMod a
- fillRight' :: Cell a => Int -> Int -> a -> CellMod a
- fillCenter :: Cell a => Int -> a -> CellMod a
- fillCenter' :: Cell a => Int -> Int -> a -> CellMod a
- fillLeft :: Cell a => Int -> a -> CellMod a
- fillLeft' :: Cell a => Int -> Int -> a -> CellMod a
- pad :: Cell a => Position o -> Int -> a -> CellMod a
- pad' :: Cell a => Position o -> Int -> Int -> a -> CellMod a
- trimOrPad :: Cell a => Position o -> CutMark -> Int -> a -> CellMod a
- trimOrPadBetween :: Cell a => Position o -> CutMark -> Int -> Int -> a -> CellMod a
- trim :: Cell a => Position o -> CutMark -> Int -> a -> CellMod a
- trim' :: Cell a => Position o -> CutMark -> Int -> Int -> a -> CellMod a
- align :: Cell a => OccSpec -> AlignInfo -> a -> CellMod a
- data CutAction
- surplusSpace :: CutAction -> Int
- determineCutAction :: Int -> Int -> CutAction
- data CutInfo
- determineCuts :: Int -> Int -> Int -> Int -> CutInfo
- numSpacesAfterCut :: CutAction -> Int -> Int -> Int
- applyCutInfo :: Cell a => CutInfo -> CutMark -> Int -> Int -> a -> CellMod a
- viewRange :: Position o -> Int -> Int -> Int -> (Int, Int)
- cellRange :: Int -> AlignInfo -> (Int, Int)
- alignFixed :: Cell a => Position o -> CutMark -> Int -> OccSpec -> AlignInfo -> a -> CellMod a
- buildCellMod :: (Cell c, StringBuilder s) => CutMark -> CellMod c -> s
Documentation
truncateNegative :: Int -> Int Source #
Ensure a value is not negative.
An object along with the amount that its length should be adjusted on both the left and right. Positive numbers are padding and negative numbers are trimming.
CellView | |
|
Instances
Applicative CellView Source # | |
Functor CellView Source # | |
Monad CellView Source # | |
Show a => Show (CellView a) Source # | |
Eq a => Eq (CellView a) Source # | |
Ord a => Ord (CellView a) Source # | |
Defined in Text.Layout.Table.Cell | |
Cell a => Cell (CellView a) Source # | |
Defined in Text.Layout.Table.Cell visibleLength :: CellView a -> Int Source # measureAlignment :: (Char -> Bool) -> CellView a -> AlignInfo Source # buildCell :: StringBuilder b => CellView a -> b Source # buildCellView :: StringBuilder b => CellView (CellView a) -> b Source # |
adjustCell :: Int -> Int -> a -> CellView a Source #
Add an adjustment to the left and right of a Cell
.
Positive numbers are padding and negative numbers are trimming.
dropLeft :: Int -> a -> CellView a Source #
Drop a number of characters from the left side. Treats negative numbers as zero.
dropRight :: Int -> a -> CellView a Source #
Drop a number of characters from the right side. Treats negative numbers as zero.
dropBoth :: Int -> Int -> a -> CellView a Source #
Drop characters from both sides. Treats negative numbers as zero.
totalAdjustment :: CellView a -> Int Source #
The total amount of adjustment in CellView
.
redistributeAdjustment :: Int -> Int -> CellView a -> CellView a Source #
Redistribute padding or trimming using a given ratio.
Types that can be measured for visible characters, define a sub-string
operation and turned into a StringBuilder
.
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 preceding and following characters for a position where the predicate matches.
buildCell :: StringBuilder b => a -> b Source #
Insert the contents into a StringBuilder
.
buildCellView :: StringBuilder b => CellView a -> b Source #
Insert the contents into a StringBuilder
, padding or trimming as
necessary.
The Cell
instance of 'CellView a' means that this can usually be
substituted with buildCell
, and is only needed for defining the
instance.
Instances
buildCellViewLRHelper Source #
:: StringBuilder b | |
=> (a -> b) | Builder function for |
-> (Int -> a -> a) | Function for trimming on the left. |
-> (Int -> a -> a) | Function for trimming on the right. |
-> CellView a | |
-> b |
Construct buildCellView
from a builder function, a function for
trimming from the left, and a function for trimming from the right.
Used to define instances of Cell
.
buildCellViewBothHelper Source #
:: StringBuilder b | |
=> (a -> b) | Builder function for |
-> (Int -> Int -> a -> a) | Function for trimming on the left and right simultaneously. |
-> CellView a | |
-> b |
Construct buildCellView
from a builder function, and a function for
trimming from the left and right simultaneously.
Used to define instanced of Cell
.
:: StringBuilder b | |
=> (a -> b) | Builder function for |
-> (Int -> a -> b) | Function for trimming on the left. |
-> (Int -> a -> b) | Function for trimming on the right. |
-> (Int -> Int -> a -> b) | Function for trimming on the left and right simultaneously. |
-> CellView a | |
-> b |
Construct buildCellView
from builder functions and trimming functions.
Used to define instances of Cell
.
:: (Cell a, StringBuilder b) | |
=> Int | The expected length. |
-> a | A cell. |
-> b |
Creates a StringBuilder
with the amount of missing spaces.
fillRight' :: Cell a => Int -> Int -> a -> CellMod a Source #
Fill the right side with spaces if necessary. Preconditions that are required to be met (otherwise the function will produce garbage):
visibleLength c == k
fillCenter :: Cell a => Int -> a -> CellMod a Source #
Fill both sides with spaces if necessary.
fillCenter' :: Cell a => Int -> Int -> a -> CellMod a Source #
Fill both sides with spaces if necessary. Preconditions that are required to be met (otherwise the function will produce garbage):
visibleLength c == k
fillLeft' :: Cell a => Int -> Int -> a -> CellMod a Source #
Fill the left side with spaces if necessary. Preconditions that are required to be met (otherwise the function will produce garbage):
visibleLength c == k
pad :: Cell a => Position o -> Int -> a -> CellMod a Source #
Pads the given cell accordingly using the position specification.
>>>
buildCellMod noCutMark $ pad left 10 "foo" :: String
"foo "
pad' :: Cell a => Position o -> Int -> Int -> a -> CellMod a Source #
Pads the given cell accordingly using the position specification. Preconditions that are required to be met (otherwise the function will produce garbage):
visibleLength c == k
trimOrPad :: Cell a => Position o -> CutMark -> Int -> a -> CellMod a Source #
If the given text is too long, the String
will be shortened according to
the position specification. Adds cut marks to indicate that the column has
been trimmed in length, otherwise it behaves like pad
.
>>>
let cm = singleCutMark ".."
>>>
buildCellMod cm $ trimOrPad left cm 10 "A longer text." :: String
"A longer.."
:: Cell a | |
=> Position o | |
-> CutMark | |
-> Int | The length |
-> Int | The length |
-> a | |
-> CellMod a |
If the given text is too long, it will be trimmed to length upper
according to the position specification, and cut marks will be added to
indicate that the column has been trimmed in length. Otherwise, if
the given text is too short, it will be padded to length lower
.
>>>
let cm = singleCutMark ".."
>>>
buildCellMod cm $ trimOrPadBetween left cm 7 10 "A longer text." :: String
"A longer..">>>
buildCellMod cm $ trimOrPadBetween left cm 7 10 "Short" :: String
"Short ">>>
buildCellMod cm $ trimOrPadBetween left cm 7 10 "A medium" :: String
"A medium"
Preconditions that are required to be met (otherwise the output will be counterintuitive):
lower <= upper
trim :: Cell a => Position o -> CutMark -> Int -> a -> CellMod a Source #
Trim a cell based on the position. Cut marks may be trimmed if necessary.
trim' :: Cell a => Position o -> CutMark -> Int -> Int -> a -> CellMod a Source #
Trim a cell based on the position. Cut marks may be trimmed if necessary.
Preconditions that are required to be met (otherwise the function will produce garbage):
visibleLength c > n
visibleLength c == k
align :: Cell a => OccSpec -> AlignInfo -> a -> CellMod a 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 buildCellMod noCutMark . 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
surplusSpace :: CutAction -> Int Source #
determineCutAction :: Int -> Int -> CutAction 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.
numSpacesAfterCut :: CutAction -> Int -> Int -> Int Source #
If the amount to be cut is bigger than the cell length then any missing amount is taken away from any remaining padding.
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 => Position o -> CutMark -> Int -> OccSpec -> AlignInfo -> a -> CellMod a Source #
Aligns a cell using a fixed width, fitting it to the width by either filling or cutting while respecting the alignment.
buildCellMod :: (Cell c, StringBuilder s) => CutMark -> CellMod c -> s Source #
Interpret CellMod
to create a builder.