-- 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: -- --
-- >>> justifyText 10 "This text will not fit on one line." -- ["This text","will not","fit on one","line."] --justifyText :: Int -> String -> [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] -- | 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] data VertPosSpec TopVPos :: VertPosSpec CenterVPos :: VertPosSpec BottomVPos :: VertPosSpec -- | Merges multiple columns together and merges them to a valid grid -- without holes. The following example clarifies this: -- --
-- >>> columnsAsGrid TopVPos [justifyText 10 "This text will not fit on one line.", ["42", "23"]] -- [["This text","42"],["will not","23"],["fit on one",""],["line.",""]] --columnsAsGrid :: VertPosSpec -> [[[a]]] -> [[[a]]] -- | Fill all sublists to the same length. vpadCols :: VertPosSpec -> a -> [[a]] -> [[a]] -- | This module provides a primitive styling facility. To make your own -- style have a look at -- https://en.wikipedia.org/wiki/Box-drawing_character. module Text.Layout.Table.Style -- | Specifies the different letters to construct the non-content structure -- of a table. data TableStyle TableStyle :: Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> TableStyle [headerSepH] :: TableStyle -> Char [headerSepLC] :: TableStyle -> Char [headerSepRC] :: TableStyle -> Char [headerSepC] :: TableStyle -> Char [headerTopL] :: TableStyle -> Char [headerTopR] :: TableStyle -> Char [headerTopC] :: TableStyle -> Char [headerTopH] :: TableStyle -> Char [headerV] :: TableStyle -> Char [groupV] :: TableStyle -> Char [groupSepH] :: TableStyle -> Char [groupSepC] :: TableStyle -> Char [groupSepLC] :: TableStyle -> Char [groupSepRC] :: TableStyle -> Char [groupTopC] :: TableStyle -> Char [groupTopL] :: TableStyle -> Char [groupTopR] :: TableStyle -> Char [groupTopH] :: TableStyle -> Char [groupBottomC] :: TableStyle -> Char [groupBottomL] :: TableStyle -> Char [groupBottomR] :: TableStyle -> Char [groupBottomH] :: TableStyle -> Char -- | My usual ASCII table style. asciiRoundS :: TableStyle -- | Uses special unicode characters to draw clean thin boxes. unicodeS :: TableStyle -- | Same as unicodeS but uses bold headers. unicodeBoldHeaderS :: TableStyle -- | Same as unicodeS but uses round edges. unicodeRoundS :: TableStyle -- | Uses bold lines. unicodeBoldS :: TableStyle -- | Uses bold lines with exception of group seperators, which are striped -- slim. unicodeBoldStripedS :: TableStyle -- | 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. -- --
-- >>> putStrLn $ layoutToString [["a", "b"], ["c", "d"]] (repeat defaultL) -- a b -- c d ---- -- Fancy table without header: -- --
-- >>> putStrLn $ layoutTableToString [rowGroup [["Jack", "184.74"]], rowGroup [["Jane", "162.2"]]] Nothing [defaultL, numL] unicodeRoundS -- ╭──────┬────────╮ -- │ Jack │ 184.74 │ -- ├──────┼────────┤ -- │ Jane │ 162.2 │ -- ╰──────┴────────╯ ---- -- Fancy table with header: -- --
-- >>> putStrLn $ layoutTableToString [ rowGroup [["A very long text", "0.42000000"]] -- , rowGroup [["Short text", "100200.5"]] -- ] -- (Just (["Title", "Length"], repeat centerHL)) -- [ fixedLeftL 20 -- , LayoutSpec (Fixed 10) -- CenterPos -- dotAlign -- ellipsisCutMark -- ] -- unicodeRoundS -- ╭──────────────────────┬────────────╮ -- │ Title │ Length │ -- ╞══════════════════════╪════════════╡ -- │ A very long text │ 0.4200… │ -- ├──────────────────────┼────────────┤ -- │ Short text │ …200.5 │ -- ╰──────────────────────┴────────────╯ --module Text.Layout.Table -- | Determines the layout of a column. data LayoutSpec LayoutSpec :: LenSpec -> PosSpec -> AlignSpec -> CutMarkSpec -> LayoutSpec [lenSpec] :: LayoutSpec -> LenSpec [posSpec] :: LayoutSpec -> PosSpec [alignSpec] :: LayoutSpec -> AlignSpec [cutMarkSpec] :: LayoutSpec -> CutMarkSpec -- | The default layout will allow maximum expand and is positioned on the -- left. defaultL :: LayoutSpec -- | Numbers are positioned on the right and aligned on the floating point -- dot. numL :: LayoutSpec -- | Fixes the column length and positions according to the given -- PosSpec. fixedL :: Int -> PosSpec -> LayoutSpec -- | Fixes the column length and positions on the left. fixedLeftL :: Int -> LayoutSpec -- | Determines how long a column will be. data LenSpec Expand :: LenSpec Fixed :: Int -> LenSpec ExpandUntil :: Int -> LenSpec FixedUntil :: Int -> LenSpec -- | Determines how a column will be positioned. Note that on an odd number -- of space, centering is left-biased. data PosSpec LeftPos :: PosSpec RightPos :: PosSpec CenterPos :: PosSpec -- | Determines whether a column will align at a specific letter. data AlignSpec -- | Don't align text. noAlign :: AlignSpec charAlign :: Char -> AlignSpec predAlign :: (Char -> Bool) -> AlignSpec -- | Align all text at the dot. dotAlign :: AlignSpec isAligned :: AlignSpec -> Bool -- | Specifies an occurence of a letter. data OccSpec -- | 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 CutMarkSpec -- | Default cut mark used when cutting off text. defaultCutMark :: CutMarkSpec -- | A single unicode character showing three dots is used as cut mark. ellipsisCutMark :: CutMarkSpec -- | Don't use a cut mark. noCutMark :: CutMarkSpec -- | Use the same cut mark for left and right. singleCutMark :: String -> CutMarkSpec -- | Display custom characters on a cut. cutMark :: String -> String -> CutMarkSpec -- | Modifies cells according to the given LayoutSpec. layoutToCells :: [[String]] -> [LayoutSpec] -> [[String]] -- | Behaves like layoutCells but produces lines by joining with -- whitespace. layoutToLines :: [[String]] -> [LayoutSpec] -> [String] -- | Behaves like layoutCells but produces a String by -- joining with the newline character. layoutToString :: [[String]] -> [LayoutSpec] -> String -- | Applies functions alternating to given lines. This makes it easy to -- color lines to improve readability in a row. altLines :: [a -> b] -> [a] -> [b] -- | Applies functions alternating to cells 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 are not seperated from each other. data RowGroup -- | Construct a row group from a list of rows. rowGroup :: [[String]] -> RowGroup -- | Specifies how a header is layout, by omitting the cut mark it will use -- the one specified in the LayoutSpec like the other cells in -- that column. data HeaderLayoutSpec HeaderLayoutSpec :: PosSpec -> (Maybe CutMarkSpec) -> HeaderLayoutSpec -- | A centered header layout. centerHL :: HeaderLayoutSpec -- | A left-positioned header layout. leftHL :: HeaderLayoutSpec -- | Layouts a good-looking table with a optional header. Note that -- specifying fewer layout specifications than columns or vice versa will -- result in not showing them. layoutTableToLines :: [RowGroup] -> Maybe ([String], [HeaderLayoutSpec]) -> [LayoutSpec] -> TableStyle -> [String] layoutTableToString :: [RowGroup] -> Maybe ([String], [HeaderLayoutSpec]) -> [LayoutSpec] -> TableStyle -> 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] data VertPosSpec TopVPos :: VertPosSpec CenterVPos :: VertPosSpec BottomVPos :: VertPosSpec -- | Merges multiple columns together and merges them to a valid grid -- without holes. The following example clarifies this: -- --
-- >>> columnsAsGrid TopVPos [justifyText 10 "This text will not fit on one line.", ["42", "23"]] -- [["This text","42"],["will not","23"],["fit on one",""],["line.",""]] --columnsAsGrid :: VertPosSpec -> [[[a]]] -> [[[a]]] -- | Justifies texts and presents the resulting lines in a grid structure -- (each text in one column). justifyTextsAsGrid :: [(Int, String)] -> [[String]] -- | Justifies lists of words and presents the resulting lines in a grid -- structure (each list of words in one column). This is useful if you -- don't want to split just at whitespaces. justifyWordListsAsGrid :: [(Int, [String])] -> [[String]] -- | 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 LeftPos 10 "foo" -- "foo " --pad :: PosSpec -> Int -> String -> String -- | If the given text is too long, the String will be shortened -- according to the position specification, also adds some dots to -- indicate that the column has been trimmed in length, otherwise behaves -- like pad. -- --
-- >>> trimOrPad LeftPos (singleCutMark "..") 10 "A longer text." -- "A longer.." --trimOrPad :: PosSpec -> CutMarkSpec -> Int -> String -> String -- | Align a column by first finding the position to pad with and then -- padding the missing lengths to the maximum value. If no such position -- is found, it will align it such that it gets aligned before that -- position. -- -- This function assumes: -- --
-- ai <> deriveAlignInfo s = ai --align :: OccSpec -> AlignInfo -> String -> String -- | Aligns a column using a fixed width, fitting it to the width by either -- filling or cutting while respecting the alignment. alignFixed :: PosSpec -> CutMarkSpec -> Int -> OccSpec -> AlignInfo -> String -> String -- | Specifies how a column should be modified. data ColModInfo FillAligned :: OccSpec -> AlignInfo -> ColModInfo FillTo :: Int -> ColModInfo FitTo :: Int -> (Maybe (OccSpec, AlignInfo)) -> ColModInfo -- | Get the exact width after the modification. 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 -> PosSpec -> ColModInfo -> ColModInfo -- | Ensures that the given String will fit into the modified -- columns. ensureWidthOfCMI :: String -> PosSpec -> ColModInfo -> ColModInfo -- | Generates a function which modifies a given String according to -- PosSpec, CutMarkSpec and ColModInfo. columnModifier :: PosSpec -> CutMarkSpec -> ColModInfo -> (String -> String) -- | Specifies the length before and after a letter. data AlignInfo AlignInfo :: Int -> Int -> AlignInfo -- | The column width when using the AlignInfo. widthAI :: AlignInfo -> Int -- | Derive the ColModInfo by using layout specifications and -- looking at the cells. deriveColModInfos :: [(LenSpec, AlignSpec)] -> [[String]] -> [ColModInfo] -- | Generate the AlignInfo of a cell using the OccSpec. deriveAlignInfo :: OccSpec -> String -> AlignInfo instance GHC.Show.Show Text.Layout.Table.AlignInfo instance GHC.Show.Show Text.Layout.Table.PosSpec instance GHC.Show.Show Text.Layout.Table.LenSpec instance GHC.Base.Monoid Text.Layout.Table.AlignInfo