-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Format tabular data as grid or table. -- -- `table-layout` is a library for text-based table layout and cell -- formatting with the following features: -- -- -- -- The module Text.Layout.Table contains everything that is -- required. However, all of the intermediate functionality is also -- exposed which makes it easy to create something completely new. A -- small tutorial is provided in the README.md file. @package table-layout @version 0.9.0.1 module Text.Layout.Table.Primitives.AlignInfo -- | Specifies the length before and after an alignment position (excluding -- the alignment character). data AlignInfo AlignInfo :: Int -> Maybe Int -> AlignInfo -- | Private show function. showAI :: AlignInfo -> String -- | The column width when using the AlignInfo. widthAI :: AlignInfo -> Int instance GHC.Base.Semigroup Text.Layout.Table.Primitives.AlignInfo.AlignInfo instance GHC.Base.Monoid Text.Layout.Table.Primitives.AlignInfo.AlignInfo module Text.Layout.Table.Spec.CutMark -- | 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 leftMark :: CutMark -> String rightMark :: CutMark -> String instance Data.Default.Class.Default Text.Layout.Table.Spec.CutMark.CutMark -- | This module contains primitive modifiers for lists and Strings -- to be filled or fitted to a specific length. module Text.Layout.Table.Primitives.Basic spaces :: Int -> 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] -- | 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 as possible depending on the given width. -- Every line, except 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] -- | Fit as much words on a line as possible. Produce a list of the length -- of the line with one space between the words, the word count and the -- words. -- -- Cutting below word boundaries is not yet supported. fitWords :: Int -> [String] -> [Line] -- | Join the words on a line together by filling it with spaces in -- between. concatPadLine :: Int -> Line -> 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] instance GHC.Show.Show Text.Layout.Table.Justify.Line module Text.Layout.Table.Spec.LenSpec -- | Determines how long a column will be. data LenSpec Expand :: LenSpec Fixed :: Int -> LenSpec ExpandUntil :: Int -> LenSpec FixedUntil :: Int -> 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 instance Data.Default.Class.Default Text.Layout.Table.Spec.LenSpec.LenSpec module Text.Layout.Table.Spec.OccSpec -- | 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) predicate :: OccSpec -> Char -> Bool module Text.Layout.Table.Spec.AlignSpec -- | Determines whether a column will align at a specific letter. data AlignSpec AlignOcc :: OccSpec -> AlignSpec NoAlign :: 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 instance Data.Default.Class.Default Text.Layout.Table.Spec.AlignSpec.AlignSpec module Text.Layout.Table.Spec.Position -- | Specifies a position relative from a beginning. data Position orientation Start :: Position orientation Center :: Position orientation End :: 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 instance GHC.Classes.Eq (Text.Layout.Table.Spec.Position.Position orientation) instance GHC.Show.Show (Text.Layout.Table.Spec.Position.Position Text.Layout.Table.Spec.Position.V) instance GHC.Show.Show (Text.Layout.Table.Spec.Position.Position Text.Layout.Table.Spec.Position.H) instance Data.Default.Class.Default (Text.Layout.Table.Spec.Position.Position orientation) module Text.Layout.Table.Spec.HeaderColSpec -- | Specifies how a header is rendered. data HeaderColSpec HeaderColSpec :: Position H -> Maybe CutMark -> 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 instance Data.Default.Class.Default Text.Layout.Table.Spec.HeaderColSpec.HeaderColSpec module Text.Layout.Table.Spec.HeaderSpec -- | Specifies a header. data HeaderSpec HeaderHS :: [HeaderColSpec] -> [String] -> HeaderSpec NoneHS :: HeaderSpec -- | Specify a header column for every title. fullH :: [HeaderColSpec] -> [String] -> HeaderSpec -- | Use titles with the default header column specification. titlesH :: [String] -> HeaderSpec instance Data.Default.Class.Default Text.Layout.Table.Spec.HeaderSpec.HeaderSpec module Text.Layout.Table.Spec.ColSpec -- | 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.Spec.ColSpec.ColSpec module Text.Layout.Table.Spec.Util -- | 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] module Text.Layout.Table.Spec.RowGroup -- | Groups rows together which should not be visually seperated from each -- other. newtype RowGroup a RowGroup :: [Row a] -> RowGroup a [rows] :: RowGroup a -> [Row a] -- | Group the given rows together. rowsG :: [Row a] -> RowGroup a -- | Make a group of a single row. rowG :: Row a -> RowGroup a module Text.Layout.Table.StringBuilder -- | A type that is used to construct parts of a table. class Monoid a => StringBuilder a -- | Create a builder with a String. stringB :: StringBuilder a => String -> a -- | Create a builder with a single Char. charB :: StringBuilder a => Char -> a -- | Create a builder with several Chars. replicateCharB :: StringBuilder a => Int -> Char -> a -- | Create a builder that contains k spaces. Negative numbers are -- treated as zero. spacesB :: StringBuilder a => Int -> a instance Text.Layout.Table.StringBuilder.StringBuilder GHC.Base.String instance Text.Layout.Table.StringBuilder.StringBuilder (Data.Semigroup.Internal.Endo GHC.Base.String) -- | This module provides primitives for generating tables. Tables are -- generated line by line thus the functions in this module produce -- StringBuilders that contain a line. module Text.Layout.Table.Primitives.Table -- | Draw a horizontal line that will use the delimiters around the -- appropriately and visually separate by hSpace. hLineDetail :: StringBuilder b => Char -> Char -> Char -> Char -> Row b -> b -- | A simplified version of hLineDetail that will use the same -- delimiter for everything. hLine :: StringBuilder b => Char -> Char -> Row b -> b -- | Render a line with actual content. hLineContent :: StringBuilder b => Char -> Row b -> b module Text.Layout.Table.Cell -- | Types that can be shortened, measured for visible characters, and -- turned into a StringBuilder. class Cell a -- | Drop a number of characters from the left side. Treats negative -- numbers as zero. dropLeft :: Cell a => Int -> a -> a -- | Drop a number of characters from the right side. Treats negative -- numbers as zero. dropRight :: Cell a => Int -> a -> a -- | Drop characters from both sides. Treats negative numbers as zero. dropBoth :: Cell a => Int -> Int -> a -> a -- | Returns the length of the visible characters as displayed on the -- output medium. visibleLength :: Cell a => a -> Int -- | Measure the preceeding and following characters for a position where -- the predicate matches. measureAlignment :: Cell a => (Char -> Bool) -> a -> AlignInfo -- | Insert the contents into a StringBuilder. buildCell :: (Cell a, StringBuilder b) => a -> b remSpacesB :: (Cell a, StringBuilder b) => Int -> a -> b remSpacesB' :: StringBuilder b => Int -> Int -> b -- | Fill the right side with spaces if necessary. fillRight :: (Cell a, StringBuilder b) => Int -> a -> b -- | Fill both sides with spaces if necessary. fillCenter :: (Cell a, StringBuilder b) => Int -> a -> b -- | Fill the left side with spaces if necessary. fillLeft :: (Cell a, StringBuilder b) => Int -> a -> b -- | 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       "
--   
pad :: (Cell a, StringBuilder b) => Position o -> Int -> a -> b -- | 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.."
--   
trimOrPad :: (Cell a, StringBuilder b) => Position o -> CutMark -> Int -> a -> b -- | Trim a cell based on the position. Preconditions that require to be -- met (otherwise the function will produce garbage): prop> -- visibleLength c > n trim :: (Cell a, StringBuilder b) => Position o -> CutMark -> Int -> a -> b -- | 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
--   
align :: (Cell a, StringBuilder b) => OccSpec -> AlignInfo -> a -> b data CutAction FillCA :: Int -> CutAction CutCA :: Int -> CutAction NoneCA :: CutAction surplusSpace :: CutAction -> Int determineCutAction :: Int -> Int -> CutAction data CutInfo -- | Apply a cut action to each side. SidesCI :: CutAction -> CutAction -> CutInfo -- | Apply a mark to a whitespace string pointing to the left. MarkLeftCI :: CutInfo -- | Apply a mark to a whitespace string pointing to the right. MarkRightCI :: CutInfo -- | 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. determineCuts :: Int -> Int -> Int -> Int -> CutInfo -- | If the amount to be cut is bigger than the cell length then any -- missing amount is taken away from any remaining padding. spacesAfterCut :: StringBuilder b => CutAction -> Int -> Int -> b applyCutInfo :: (Cell a, StringBuilder b) => CutInfo -> CutMark -> Int -> Int -> a -> b -- | 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. viewRange :: Position o -> Int -> Int -> Int -> (Int, Int) -- | 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. cellRange :: Int -> AlignInfo -> (Int, Int) -- | Aligns a cell using a fixed width, fitting it to the width by either -- filling or cutting while respecting the alignment. alignFixed :: (Cell a, StringBuilder b) => Position o -> CutMark -> Int -> OccSpec -> AlignInfo -> a -> b instance GHC.Show.Show Text.Layout.Table.Cell.CutInfo instance GHC.Classes.Eq Text.Layout.Table.Cell.CutInfo instance GHC.Show.Show Text.Layout.Table.Cell.CutAction instance GHC.Classes.Eq Text.Layout.Table.Cell.CutAction instance Text.Layout.Table.Cell.Cell GHC.Base.String module Text.Layout.Table.Primitives.ColumnModifier -- | 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 FillAligned :: OccSpec -> AlignInfo -> ColModInfo FillTo :: Int -> ColModInfo FitTo :: Int -> Maybe (OccSpec, AlignInfo) -> ColModInfo -- | Private show function. showCMI :: ColModInfo -> String -- | 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 -- | Fit titles of a header column into the derived ColModInfo. fitTitlesCMI :: [String] -> [Position H] -> [ColModInfo] -> [ColModInfo] -- | Generates a function which modifies a given cell according to -- Position, CutMark and ColModInfo. This is used to -- modify a single cell of a column to bring all cells of a column to the -- same width. columnModifier :: (Cell a, StringBuilder b) => Position H -> CutMark -> ColModInfo -> a -> b -- | Derive the ColModInfo by using layout specifications and the -- actual cells of a column. This function only needs to know about -- LenSpec and AlignInfo. deriveColModInfos :: Cell a => [(LenSpec, AlignSpec)] -> [Row a] -> [ColModInfo] deriveColModInfos' :: Cell a => [ColSpec] -> [Row a] -> [ColModInfo] -- | Derive the ColModInfo and generate functions without any -- intermediate steps. deriveColMods :: (Cell a, StringBuilder b) => [ColSpec] -> [Row a] -> [a -> b] -- | Generate the AlignInfo of a cell by using the OccSpec. deriveAlignInfo :: Cell a => OccSpec -> a -> AlignInfo module Text.Layout.Table.Primitives.Header -- | Combine a HeaderColSpec and existing ColModInfos to -- format header cells. headerCellModifier :: HeaderColSpec -> CutMark -> ColModInfo -> String -> String -- | Render tables that can be used in Pandoc. In particular, this -- supports the pipe_tables extension. module Text.Layout.Table.Pandoc -- | Generate a table that is readable but also serves as input to pandoc. -- --
--   >>> mapM_ putStrLn $ pandocPipeTableLines [def, numCol] (titlesH ["text", "numeric value"]) [["a", "1.5"], ["b", "6.60000"]]
--   |text|numberic value|
--   |:---|-------------:|
--   |a   |       1.5    |
--   |b   |       6.60000|
--   
pandocPipeTableLines :: [ColSpec] -> HeaderSpec -> [Row String] -> [String] applyPandocPositionMarker :: Position H -> String -> String -- | Provides formatting to an instance of Cell. For example, in a -- unix terminal one could use the following: -- --
--   >>> buildCell (formatted "\ESC[31m" "Hello World!" "\ESC[0m") :: String
--   Hello World!
--   
-- -- The text then appears in dull red. module Text.Layout.Table.Cell.Formatted data Formatted a -- | Create a formatted value with formatting directives that are applied -- to the whole value. The actual formatting has to be done by the -- backend. formatted :: String -> a -> String -> Formatted a -- | Create a value from content that is kept plain without any formatting. plain :: a -> Formatted a instance GHC.Base.Functor Text.Layout.Table.Cell.Formatted.Formatted instance Data.String.IsString a => Data.String.IsString (Text.Layout.Table.Cell.Formatted.Formatted a) instance Text.Layout.Table.Cell.Cell a => Text.Layout.Table.Cell.Cell (Text.Layout.Table.Cell.Formatted.Formatted 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 functions for vertical alginment of columns. module Text.Layout.Table.Vertical -- | Fill all columns to the same length by aligning at the given -- positions. vPad :: a -> [Position V] -> [Col a] -> [Col a] -- | Fill all columns to the same length by aligning at the given position. vPadAll :: a -> Position V -> [Col a] -> [Col a] -- | Merges multiple columns together to a valid grid without holes. For -- example: -- --
--   >>> 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 -- grid. colsAsRowsAll :: Monoid a => 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 :: Monoid a => [Position V] -> [Col a] -> [Row 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 -- | An alias for lists, conceptually for values with a horizontal -- arrangement. type Row a = [a] -- | Modifies cells according to the column specification. grid :: Cell a => [ColSpec] -> [Row a] -> [Row String] -- | Behaves like grid but produces lines by joining with -- whitespace. gridLines :: Cell a => [ColSpec] -> [Row a] -> [String] -- | Behaves like gridLines but produces a string by joining with -- the newline character. gridString :: Cell a => [ColSpec] -> [Row a] -> String -- | Concatenates a row with a given amount of spaces. concatRow :: StringBuilder b => Int -> Row b -> b concatLines :: StringBuilder b => [b] -> b concatGrid :: StringBuilder b => Int -> [Row b] -> b -- | 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 a -- | Group the given rows together. rowsG :: [Row a] -> RowGroup a -- | Make a group of a single row. rowG :: Row a -> RowGroup a -- | Create a RowGroup by aligning the columns vertically. The -- position is specified for each column. colsG :: Monoid a => [Position V] -> [Col a] -> RowGroup a -- | Create a RowGroup by aligning the columns vertically. Each -- column uses the same vertical positioning. colsAllG :: Monoid a => Position V -> [Col a] -> RowGroup a -- | 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 HeaderSpec -- | Specify a header column for every title. fullH :: [HeaderColSpec] -> [String] -> HeaderSpec -- | Use titles with the default header column specification. titlesH :: [String] -> HeaderSpec -- | Layouts a pretty table with an optional header. Note that providing -- fewer layout specifications than columns or vice versa will result in -- not showing the redundant ones. tableLines :: Cell a => [ColSpec] -> TableStyle -> HeaderSpec -> [RowGroup a] -> [String] -- | Does the same as tableLines, but concatenates lines. tableString :: Cell a => [ColSpec] -> TableStyle -> HeaderSpec -> [RowGroup a] -> String -- | Fits as many words on a line as possible depending on the given width. -- Every line, except 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 to a valid grid without holes. For -- example: -- --
--   >>> 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 -- grid. colsAsRowsAll :: Monoid a => 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 :: Monoid a => [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 -- cell passed. Pads the given cell accordingly using the position -- specification. -- --
--   >>> pad left 10 "foo" :: String
--   "foo       "
--   
pad :: (Cell a, StringBuilder b) => Position o -> Int -> a -> b -- | 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.."
--   
trimOrPad :: (Cell a, StringBuilder b) => Position o -> CutMark -> Int -> a -> b -- | 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
--   
align :: (Cell a, StringBuilder b) => OccSpec -> AlignInfo -> a -> b -- | Aligns a cell using a fixed width, fitting it to the width by either -- filling or cutting while respecting the alignment. alignFixed :: (Cell a, StringBuilder b) => Position o -> CutMark -> Int -> OccSpec -> AlignInfo -> a -> b -- | 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 cell according to -- Position, CutMark and ColModInfo. This is used to -- modify a single cell of a column to bring all cells of a column to the -- same width. columnModifier :: (Cell a, StringBuilder b) => Position H -> CutMark -> ColModInfo -> a -> b -- | Specifies the length before and after an alignment position (excluding -- 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. This function only needs to know about -- LenSpec and AlignInfo. deriveColModInfos :: Cell a => [(LenSpec, AlignSpec)] -> [Row a] -> [ColModInfo] -- | Generate the AlignInfo of a cell by using the OccSpec. deriveAlignInfo :: Cell a => OccSpec -> a -> AlignInfo -- | Specifies an occurence of a letter. data OccSpec