table-layout-0.9.0.2: Format tabular data as grid or table.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Text.Layout.Table.Cell

Synopsis

Documentation

class Cell a where Source #

Types that can be shortened, measured for visible characters, and turned into a StringBuilder.

Methods

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.

remSpacesB :: (Cell a, StringBuilder b) => Int -> a -> 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       "

trimOrPad :: (Cell a, StringBuilder b) => Position o -> CutMark -> Int -> a -> b 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.

>>> trimOrPad left (singleCutMark "..") 10 "A longer text." :: String
"A longer.."

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

data CutAction Source #

Constructors

FillCA Int 
CutCA Int 
NoneCA 

Instances

Instances details
Eq CutAction Source # 
Instance details

Defined in Text.Layout.Table.Cell

Show CutAction Source # 
Instance details

Defined in Text.Layout.Table.Cell

data CutInfo Source #

Constructors

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.

Instances

Instances details
Eq CutInfo Source # 
Instance details

Defined in Text.Layout.Table.Cell

Methods

(==) :: CutInfo -> CutInfo -> Bool #

(/=) :: CutInfo -> CutInfo -> Bool #

Show CutInfo Source # 
Instance details

Defined in Text.Layout.Table.Cell

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.