-- 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: -- -- -- -- Note: This package is currently under development and may not -- be suited for productive use. @package table-layout @version 0.5.2.0 module Text.Layout.Table.Primitives.Occurence -- | Specifies an occurence of a letter. data OccSpec -- | Construct an occurence specification by using a predicate. predOccSpec :: (Char -> Bool) -> OccSpec -- | Use an occurence specification to split a String. splitAtOcc :: OccSpec -> String -> (String, String) module Text.Layout.Table.Primitives.LenSpec -- | 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 -- | This module contains primitive modifiers for lists and Strings -- to be filled or fitted to a specific length. module Text.Layout.Table.Primitives.Basic -- | 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 -- | Specify two different cut marks, one for cuts on the left and one for -- cuts on the right. doubleCutMark :: String -> String -> CutMark -- | Use the cut mark on both sides by reversing it on the other. singleCutMark :: String -> CutMark -- | Don't show any cut mark when text is cut. noCutMark :: CutMark -- | A single unicode character showing three dots is used as cut mark. ellipsisCutMark :: CutMark spaces :: Int -> String concatLines :: [String] -> String fillLeft' :: Int -> Int -> String -> String -- | Fill on the left until the String has the desired length. fillLeft :: Int -> String -> String -- | Fill on the right until the String has the desired length. fillRight :: Int -> String -> String fillCenter' :: Int -> Int -> String -> String -- | Fill on both sides equally until the String has the desired -- length. fillCenter :: Int -> String -> String -- | Fits to the given length by either trimming or filling it to the -- right. fitRightWith :: CutMark -> Int -> String -> String -- | Fits to the given length by either trimming or filling it to the -- right. fitLeftWith :: CutMark -> Int -> String -> String -- | Fits to the given length by either trimming or filling it on both -- sides, but when only 1 character should be trimmed it will trim left. fitCenterWith :: CutMark -> Int -> String -> String -- | Applies a CutMark to the left of a String, while -- preserving the length. applyMarkLeftWith :: CutMark -> String -> String -- | Applies a CutMark to the right of a String, while -- preserving the length. applyMarkRightWith :: CutMark -> String -> String fillStart' :: a -> Int -> Int -> [a] -> [a] fillStart :: a -> Int -> [a] -> [a] fillEnd :: a -> Int -> [a] -> [a] fillBoth' :: a -> Int -> Int -> [a] -> [a] fillBoth :: a -> Int -> [a] -> [a] instance Data.Default.Class.Default Text.Layout.Table.Primitives.Basic.CutMark module Text.Layout.Table.Primitives.AlignSpec -- | Determines whether a column will align at a specific letter. data AlignSpec -- | Don't align text. noAlign :: AlignSpec -- | Construct an AlignSpec by giving an occurence specification. occSpecAlign :: OccSpec -> AlignSpec -- | Align at the first match of a predicate. predAlign :: (Char -> Bool) -> AlignSpec -- | Align text at the first occurence of a given Char. charAlign :: Char -> AlignSpec module Text.Layout.Table.Position -- | Specifies a position relative from a beginning. data Position orientation -- | Horizontal orientation. data H -- | Vertical orientation data V left :: Position H right :: Position H center :: Position orientation top :: Position V bottom :: Position V module Text.Layout.Table.Primitives.Column -- | Specifies the layout of a column. data ColSpec lenSpec :: ColSpec -> LenSpec position :: ColSpec -> Position H alignSpec :: ColSpec -> AlignSpec cutMark :: ColSpec -> CutMark -- | Smart constructor to specify a column. column :: LenSpec -> Position H -> AlignSpec -> CutMark -> ColSpec instance Data.Default.Class.Default Text.Layout.Table.Primitives.Column.ColSpec module Text.Layout.Table.Internal -- | Groups rows together, which are not seperated from each other. newtype RowGroup RowGroup :: [[String]] -> RowGroup [rows] :: RowGroup -> [[String]] -- | Construct a row group from a list of rows. rowGroup :: [Row String] -> RowGroup -- | Specifies how a header is layout, by omitting the cut mark it will use -- the one specified in the ColSpec like the other cells in that -- column. data HeaderColSpec HeaderColSpec :: (Position H) -> (Maybe CutMark) -> HeaderColSpec headerColumn :: Position H -> Maybe CutMark -> HeaderColSpec -- | Header columns are usually centered. -- | An alias for lists, conceptually for values with a horizontal -- arrangement. type Row a = [a] -- | An alias for lists, conceptually for values with a vertical -- arrangement. type Col a = [a] instance Data.Default.Class.Default Text.Layout.Table.Internal.HeaderColSpec -- | Produce justified text, which is spread over multiple rows, and join -- it with other columns. For a simple cut, chunksOf from the -- split package is best suited. module Text.Layout.Table.Justify -- | Justifies texts and presents the resulting lines in a grid structure -- (each text in one column). justifyTextsAsGrid :: [(Int, String)] -> [Row 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])] -> [Row 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] -- | 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] -- | Merges multiple columns together and merges them to a valid grid -- without holes. The following example clarifies this: -- --
--   >>> columnsAsGrid 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 layoutToCells or with -- rowGroup. columnsAsGrid :: Position V -> [Col [a]] -> [Row [a]] -- | Fill all columns to the same length by aligning at the given position. vpadCols :: Position V -> a -> [[a]] -> [[a]] -- | 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] -- | 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 lines and plus for joints. asciiS :: 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 -- | Draw every line with a double frame. unicodeDoubleFrameS :: 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. -- --

Some examples

-- -- Layouting text as a plain grid (given a list of rows): -- --
--   >>> putStrLn $ layoutToString [["a", "b"], ["c", "d"]] (repeat def)
--   a b
--   c d
--   
-- -- Fancy table without header: -- --
--   >>> putStrLn $ layoutTableToString [rowGroup [["Jack", "184.74"]], rowGroup [["Jane", "162.2"]]] def [def , numCol] 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 def))
--                                      [fixedLeftCol 20, column (fixed 10) center dotAlign def]
--                                      unicodeRoundS
--   ╭──────────────────────┬────────────╮
--   │        Title         │   Length   │
--   ╞══════════════════════╪════════════╡
--   │ A very long text     │    0.4200… │
--   ├──────────────────────┼────────────┤
--   │ Short text           │ …200.5     │
--   ╰──────────────────────┴────────────╯
--   
-- -- Using justified text and RowGroups to group multiple rows -- together to form one cell: -- --
--   >>> putStrLn $ layoutTableToString [rowGroup $ columnsAsGrid center [justifyText 50 txt, [show $ length txt]]]
--                                      (Just (["Text", "Length"], repeat def))
--                                      [fixedLeftCol 50, numCol]
--                                      asciiS
--   +----------------------------------------------------+--------+
--   |                        Text                        | Length |
--   +----------------------------------------------------+--------+
--   | Lorem  ipsum dolor sit amet, consetetur sadipscing |        |
--   | elitr,  sed  diam nonumy eirmod tempor invidunt ut |        |
--   | labore  et  dolore  magna  aliquyam erat, sed diam |        |
--   | voluptua.  At  vero  eos  et  accusam et justo duo |    295 |
--   | dolores et ea rebum. Stet clita kasd gubergren, no |        |
--   | sea  takimata  sanctus  est  Lorem ipsum dolor sit |        |
--   | amet.                                              |        |
--   +----------------------------------------------------+--------+
--   
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 -- | A single unicode character showing three dots is used as cut mark. ellipsisCutMark :: CutMark -- | An alias for lists, conceptually for values with a horizontal -- arrangement. type Row a = [a] -- | Modifies cells according to the given ColSpec. layoutToCells :: [Row String] -> [ColSpec] -> [Row String] -- | Behaves like layoutToCells but produces lines by joining with -- whitespace. layoutToLines :: [Row String] -> [ColSpec] -> [String] -- | Behaves like layoutToCells but produces a String by -- joining with the newline character. layoutToString :: [Row String] -> [ColSpec] -> 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 :: [Row String] -> RowGroup -- | Specifies how a header is layout, by omitting the cut mark it will use -- the one specified in the ColSpec like the other cells in that -- column. data HeaderColSpec headerColumn :: Position H -> Maybe CutMark -> HeaderColSpec -- | 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], [HeaderColSpec]) -> [ColSpec] -> TableStyle -> [String] layoutTableToString :: [RowGroup] -> Maybe ([String], [HeaderColSpec]) -> [ColSpec] -> 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] -- | 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: -- --
--   >>> columnsAsGrid 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 layoutToCells or with -- rowGroup. columnsAsGrid :: Position V -> [Col [a]] -> [Row [a]] top :: Position V bottom :: Position V -- | Vertical orientation data V -- | Justifies texts and presents the resulting lines in a grid structure -- (each text in one column). justifyTextsAsGrid :: [(Int, String)] -> [Row 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])] -> [Row 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 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, also adds some dots to -- indicate that the column has been trimmed in length, otherwise behaves -- like pad. -- --
--   >>> trimOrPad left (singleCutMark "..") 10 "A longer text."
--   "A longer.."
--   
trimOrPad :: Position o -> CutMark -> 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 :: Position o -> CutMark -> Int -> OccSpec -> AlignInfo -> String -> String -- | Specifies how a column should be modified. data 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 -> 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 a letter. data 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)] -> [Row String] -> [ColModInfo] -- | Generate the AlignInfo of a cell using the OccSpec. deriveAlignInfo :: OccSpec -> String -> AlignInfo -- | Specifies an occurence of a letter. data OccSpec instance GHC.Base.Monoid Text.Layout.Table.AlignInfo