-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Layout text as grid or table. -- -- `table-layout` is a library for text-based table layout, it provides -- several functions and types which help in this task from the ground -- up, although using them is not necessary. It provides the following -- layout features: -- --
-- >>> colsAsRowsAll top [justifyText 10 "This text will not fit on one line.", ["42", "23"]] -- [["This text","42"],["will not","23"],["fit on one",""],["line.",""]] ---- -- The result is intended to be used with a grid layout function like -- layoutToCells. colsAsRowsAll :: Position V -> [Col [a]] -> [Row [a]] -- | Works like colsAsRowsAll, but every position can be specified -- on its own: -- --
-- >>> colsAsRows [top, center, bottom] [["a1"], ["b1", "b2", "b3"], ["c3"]] -- [["a1","b1",""],["","b2",""],["","b3","c3"]] --colsAsRows :: [Position V] -> [Col [a]] -> [Row [a]] -- | Produce justified text, which is spread over multiple rows. For a -- simple cut, chunksOf from the split package is best -- suited. module Text.Layout.Table.Justify -- | Fits as many words on a line, depending on the given width. Every -- line, but the last one, gets equally filled with spaces between the -- words, as far as possible. justify :: Int -> [String] -> [String] -- | Uses words to split the text into words and justifies it with -- justify. -- --
-- >>> justifyText 10 "This text will not fit on one line." -- ["This text","will not","fit on one","line."] --justifyText :: Int -> String -> [String] -- | Splits a given number into summands of 2 different values, where the -- first one is exactly one bigger than the second one. Splitting 40 -- spaces into 9 almost equal parts would result in: -- --
-- >>> dimorphicSummands 40 9 -- [5,5,5,5,4,4,4,4,4] --dimorphicSummands :: Int -> Int -> [Int] dimorphicSummandsBy :: (Int -> a) -> Int -> Int -> [a] -- | Spread out summands evenly mixed as far as possible. mixedDimorphicSummandsBy :: (Int -> a) -> Int -> Int -> [a] -- | This module provides tools to layout text as grid or table. Besides -- basic things like specifying column positioning, alignment on the same -- character and length restriction it also provides advanced features -- like justifying text and fancy tables with styling support. module Text.Layout.Table -- | Specifies the layout of a column. data ColSpec -- | Smart constructor to specify a column. column :: LenSpec -> Position H -> AlignSpec -> CutMark -> ColSpec -- | Numbers are positioned on the right and aligned on the floating point -- dot. numCol :: ColSpec -- | Fixes the column length and positions according to the given -- Position. fixedCol :: Int -> Position H -> ColSpec -- | Fixes the column length and positions on the left. fixedLeftCol :: Int -> ColSpec -- | Determines how long a column will be. data LenSpec -- | Allows columns to use as much space as needed. expand :: LenSpec -- | Fixes column length to a specific width. fixed :: Int -> LenSpec -- | The column will expand as long as it is smaller as the given width. expandUntil :: Int -> LenSpec -- | The column will be at least as wide as the given width. fixedUntil :: Int -> LenSpec -- | Specifies a position relative from a beginning. data Position orientation -- | Horizontal orientation. data H left :: Position H right :: Position H center :: Position orientation -- | Determines whether a column will align at a specific letter. data AlignSpec -- | Don't align text. noAlign :: AlignSpec -- | Align text at the first occurence of a given Char. charAlign :: Char -> AlignSpec -- | Align at the first match of a predicate. predAlign :: (Char -> Bool) -> AlignSpec -- | Align all text at the first dot from the left. This is most useful for -- floating point numbers. dotAlign :: AlignSpec -- | Specifies how the place looks where a String has been cut. Note -- that the cut mark may be cut itself, to fit into a column. data CutMark -- | Don't show any cut mark when text is cut. noCutMark :: CutMark -- | Use the cut mark on both sides by reversing it on the other. singleCutMark :: String -> CutMark -- | Specify two different cut marks, one for cuts on the left and one for -- cuts on the right. doubleCutMark :: String -> String -> CutMark -- | Deprecated: Use def instead. ellipsisCutMark :: CutMark -- | An alias for lists, conceptually for values with a horizontal -- arrangement. type Row a = [a] -- | Modifies cells according to the column specification. grid :: [ColSpec] -> [Row String] -> [Row String] -- | Behaves like grid but produces lines by joining with -- whitespace. gridLines :: [ColSpec] -> [Row String] -> [String] -- | Behaves like gridLines but produces a string by joining with -- the newline character. gridString :: [ColSpec] -> [Row String] -> String -- | Applies functions to given lines in a alternating fashion. This makes -- it easy to color lines to improve readability in a row. altLines :: [a -> b] -> [a] -> [b] -- | Applies functions to cells in a alternating fashion for every line, -- every other line gets shifted by one. This is useful for -- distinguishability of single cells in a grid arrangement. checkeredCells :: (a -> b) -> (a -> b) -> [[a]] -> [[b]] -- | Groups rows together, which should not be visually seperated from each -- other. data RowGroup -- | Group the given rows together. rowsG :: [Row String] -> RowGroup -- | Make a group of a single row. rowG :: Row String -> RowGroup -- | Create a RowGroup by aligning the columns vertically. The -- position is specified for each column. colsG :: [Position V] -> [Col String] -> RowGroup -- | Create a RowGroup by aligning the columns vertically. Each -- column uses the same vertical positioning. colsAllG :: Position V -> [Col String] -> RowGroup -- | Specifies how a header is rendered. data HeaderColSpec -- | Smart constructor for HeaderColSpec. By omitting the cut mark -- it will use the one specified in the ColSpec like the other -- cells in that column. headerColumn :: Position H -> Maybe CutMark -> HeaderColSpec -- | Specifies a header. data Header -- | Specify a header column for every title. fullH :: [HeaderColSpec] -> [String] -> Header -- | Use titles with the default header column specification. titlesH :: [String] -> Header -- | Layouts a good-looking table with an optional header. Note that -- specifying fewer layout specifications than columns or vice versa will -- result in not showing the redundant ones. tableLines :: [ColSpec] -> TableStyle -> Header -> [RowGroup] -> [String] -- | Does the same as tableLines, but concatenates lines. tableString :: [ColSpec] -> TableStyle -> Header -> [RowGroup] -> String -- | Fits as many words on a line, depending on the given width. Every -- line, but the last one, gets equally filled with spaces between the -- words, as far as possible. justify :: Int -> [String] -> [String] -- | Uses words to split the text into words and justifies it with -- justify. -- --
-- >>> justifyText 10 "This text will not fit on one line." -- ["This text","will not","fit on one","line."] --justifyText :: Int -> String -> [String] -- | An alias for lists, conceptually for values with a vertical -- arrangement. type Col a = [a] -- | Merges multiple columns together and merges them to a valid grid -- without holes. The following example clarifies this: -- --
-- >>> colsAsRowsAll top [justifyText 10 "This text will not fit on one line.", ["42", "23"]] -- [["This text","42"],["will not","23"],["fit on one",""],["line.",""]] ---- -- The result is intended to be used with a grid layout function like -- layoutToCells. colsAsRowsAll :: Position V -> [Col [a]] -> [Row [a]] -- | Works like colsAsRowsAll, but every position can be specified -- on its own: -- --
-- >>> colsAsRows [top, center, bottom] [["a1"], ["b1", "b2", "b3"], ["c3"]] -- [["a1","b1",""],["","b2",""],["","b3","c3"]] --colsAsRows :: [Position V] -> [Col [a]] -> [Row [a]] top :: Position V bottom :: Position V -- | Vertical orientation data V -- | Assume the given length is greater or equal than the length of the -- String passed. Pads the given String accordingly using -- the position specification. -- --
-- >>> pad left 10 "foo" -- "foo " --pad :: Position o -> Int -> String -> String -- | 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." -- "A longer.." --trimOrPad :: Position o -> CutMark -> Int -> String -> String -- | Align a String 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"]
-- [" 1.5 "," 30 "," .25 "]
--
--
-- This function assumes that the given String fits the
-- AlignInfo. Thus:
--
-- -- ai <> deriveAlignInfo s = ai --align :: OccSpec -> AlignInfo -> String -> String -- | Aligns a String using a fixed width, fitting it to the width by -- either filling or cutting while respecting the alignment. alignFixed :: Position o -> CutMark -> Int -> OccSpec -> AlignInfo -> String -> String -- | Specifies how a column should be modified. Values of this type are -- derived in a traversal over the input columns by using -- deriveColModInfos. Finally, columnModifier will -- interpret them and apply the appropriate modification function to the -- cells of the column. data ColModInfo -- | Get the exact width of a ColModInfo after applying it with -- columnModifier. widthCMI :: ColModInfo -> Int -- | Remove alignment from a ColModInfo. This is used to change -- alignment of headers while using the combined width information. unalignedCMI :: ColModInfo -> ColModInfo -- | Ensures that the modification provides a minimum width but only if it -- is not limited. ensureWidthCMI :: Int -> Position H -> ColModInfo -> ColModInfo -- | Ensures that the given String will fit into the modified -- columns. ensureWidthOfCMI :: String -> Position H -> ColModInfo -> ColModInfo -- | Generates a function which modifies a given String according to -- Position, CutMark and ColModInfo. columnModifier :: Position H -> CutMark -> ColModInfo -> (String -> String) -- | Specifies the length before and after an alignment position (including -- the alignment character). data AlignInfo -- | The column width when using the AlignInfo. widthAI :: AlignInfo -> Int -- | Derive the ColModInfo by using layout specifications and the -- actual cells of a column. deriveColModInfos :: [(LenSpec, AlignSpec)] -> [Row String] -> [ColModInfo] -- | Generate the AlignInfo of a cell by using the OccSpec. deriveAlignInfo :: OccSpec -> String -> AlignInfo -- | Specifies an occurence of a letter. data OccSpec instance GHC.Base.Monoid Text.Layout.Table.AlignInfo instance Data.Default.Class.Default Text.Layout.Table.Header