-- 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 1.0.0.0 module Text.Layout.Table.LineStyle -- | The line styles supported by the Unicode Box-Drawing block. data LineStyle -- | No lines in both orientations. NoLine :: LineStyle -- | and . SingleLine :: LineStyle -- | and . HeavyLine :: LineStyle -- | and . DoubleLine :: LineStyle -- | and . DashLine :: LineStyle -- | and . HeavyDashLine :: LineStyle -- | and . Dash4Line :: LineStyle -- | and . HeavyDash4Line :: LineStyle -- | and . Dash2Line :: LineStyle -- | and . HeavyDash2Line :: LineStyle -- | Make a LineStyle bold. makeLineBold :: LineStyle -> LineStyle -- | Make a LineStyle unbolded. makeLineLight :: LineStyle -> LineStyle -- | Make a LineStyle dashed. makeLineDashed :: LineStyle -> LineStyle -- | Make a LineStyle solid. makeLineSolid :: LineStyle -> LineStyle -- | ASCII representations for horizontal lines. asciiHorizontal :: LineStyle -> String -- | ASCII representations for vertical lines. asciiVertical :: LineStyle -> String -- | ASCII representations for joins using pluses. asciiJoinString :: LineStyle -> LineStyle -> String -- | ASCII interior joins, allowing the lines to change when passing -- through the vertex. Uses pluses for joins. The argument order is west, -- east, north, then south. asciiJoinString4 :: LineStyle -> LineStyle -> LineStyle -> LineStyle -> String -- | ASCII representations for joins using rounded joins. roundedAsciiJoinString :: LineStyle -> LineStyle -> String -- | ASCII interior joins, allowing the lines to change when passing -- through the vertex. Uses rounded joins. The argument order is west, -- east, north, then south. roundedAsciiJoinString4 :: LineStyle -> LineStyle -> LineStyle -> LineStyle -> String -- | Unicode representations for horizontal lines. unicodeHorizontal :: LineStyle -> String -- | Unicode representations for vertical lines. unicodeVertical :: LineStyle -> String -- | Unicode interior joins, specifying the horizontal and vertical lines. unicodeJoinString :: LineStyle -> LineStyle -> String -- | Unicode interior joins, allowing the lines to change when passing -- through the vertex. unicodeJoinString4 :: LineStyle -> LineStyle -> LineStyle -> LineStyle -> String instance GHC.Classes.Eq Text.Layout.Table.LineStyle.LineStyle instance Data.Default.Class.Default Text.Layout.Table.LineStyle.LineStyle 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.Show.Show Text.Layout.Table.Primitives.AlignInfo.AlignInfo instance GHC.Classes.Eq Text.Layout.Table.Primitives.AlignInfo.AlignInfo instance GHC.Base.Semigroup Text.Layout.Table.Primitives.AlignInfo.AlignInfo instance GHC.Base.Monoid Text.Layout.Table.Primitives.AlignInfo.AlignInfo module Text.Layout.Table.Primitives.CellMod -- | Provide all the information necessary to compare resulting dimensions -- and to turn it into a StringBuilder. data CellMod a CellMod :: a -> Int -> Int -> Int -> Int -> CellMod a [baseCellCM] :: CellMod a -> a [leftAdjustmentCM] :: CellMod a -> Int [rightAdjustmentCM] :: CellMod a -> Int [leftCutMarkLenCM] :: CellMod a -> Int [rightCutMarkLenCM] :: CellMod a -> Int -- | Describe a padding operation on the left side. The padding may not be -- negative. padCellLeft :: Int -> a -> CellMod a -- | Describe a padding operation on the right side. The padding may not be -- negative. padCellRight :: Int -> a -> CellMod a -- | Describe a padding operation. The padding may not be negative. padCell :: Int -> Int -> a -> CellMod a -- | Describe a trim operation. None of the arguments may be negative. trimCell :: Int -> Int -> Int -> Int -> a -> CellMod a -- | Describe a trim operation on the left side. None of the arguments may -- be negative. trimCellLeft :: Int -> Int -> a -> CellMod a -- | Describe a trim operation on the right side. None of the arguments may -- be negative. trimCellRight :: Int -> Int -> a -> CellMod a modifyCellWithCutMarkLen :: Int -> Int -> Int -> Int -> a -> CellMod a -- | Given adjustments for the left and the right side, either pad or trim. -- Negative values will trim, positive values will pad. modifyCell :: Int -> Int -> a -> CellMod a keepCell :: a -> CellMod a instance GHC.Base.Functor Text.Layout.Table.Primitives.CellMod.CellMod instance GHC.Show.Show a => GHC.Show.Show (Text.Layout.Table.Primitives.CellMod.CellMod a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Text.Layout.Table.Primitives.CellMod.CellMod a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Text.Layout.Table.Primitives.CellMod.CellMod a) module Text.Layout.Table.Spec.CutMark -- | Specifies a cut mark that is used whenever content is cut to fit into -- a cell. If the cut mark itself is too small to fit into a cell it may -- be cut as well. 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 -- | Do not show any cut mark when content is cut. noCutMark :: CutMark leftMark :: CutMark -> String rightMark :: CutMark -> String -- | The default CutMark is a single ellipsis unicode character on -- each side. ellipsisCutMark :: CutMark instance GHC.Classes.Eq Text.Layout.Table.Spec.CutMark.CutMark instance GHC.Show.Show Text.Layout.Table.Spec.CutMark.CutMark 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] -- | Intermediate representation for a line of words. data Line Line :: Int -> Int -> [String] -> Line -- | The length of the current line with a single space as separator -- between the words. [lineLength] :: Line -> Int -- | The number of words on the current line. [lineWordCount] :: Line -> Int -- | The actual words of the line. [lineWords] :: Line -> [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 instance GHC.Classes.Eq 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 ExpandBetween :: Int -> 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 -- | The column will be at least as wide as the first width, and will -- expand as long as it is smaller than the second. expandBetween :: Int -> 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 -- | Do not align text. noAlign :: AlignSpec -- | Construct an AlignSpec by giving an occurence specification. occSpecAlign :: OccSpec -> AlignSpec -- | Align text 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 -- | Displays at the left or top, depending on the orientation. beginning :: 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 -- | The default HeaderColSpec centers the text and uses no -- CutMark. defHeaderColSpec :: HeaderColSpec instance Data.Default.Class.Default Text.Layout.Table.Spec.HeaderColSpec.HeaderColSpec module Text.Layout.Table.Spec.HeaderSpec -- | Specifies a header. data HeaderSpec sep a -- | A grouping of subheaders separated by delimiters with the given label GroupHS :: sep -> [HeaderSpec sep a] -> HeaderSpec sep a -- | A single header column with a given HeaderColSpec and content. HeaderHS :: HeaderColSpec -> a -> HeaderSpec sep a -- | Do not display the header, and determine the shape as a flat list -- sized to the table content with a given separator. NoneHS :: sep -> HeaderSpec sep a -- | The default HeaderSpec does not display the header and uses the -- default separator. defHeaderSpec :: Default sep => HeaderSpec sep a -- | Specify no header, with columns separated by a given separator. noneSepH :: sep -> HeaderSpec sep String -- | Specify no header, with columns separated by a default separator. noneH :: Default sep => HeaderSpec sep String -- | Specify every header column in detail and separate them by the given -- separator. fullSepH :: sep -> [HeaderColSpec] -> [a] -> HeaderSpec sep a -- | Specify every header column in detail and separate them with the -- default separator. fullH :: Default sep => [HeaderColSpec] -> [a] -> HeaderSpec sep a -- | Use titles with the default header column specification and separator. titlesH :: Default sep => [a] -> HeaderSpec sep a -- | Combine the header specification for multiple columns by separating -- the columns with a specific separator. groupH :: sep -> [HeaderSpec sep a] -> HeaderSpec sep a -- | Specify the header for a single column. headerH :: HeaderColSpec -> a -> HeaderSpec sep a -- | Zip a HeaderSpec with a list. zipHeader :: b -> [b] -> HeaderSpec sep a -> HeaderSpec sep (b, a) -- | Flatten a header to produce a list of content and separators. flattenHeader :: HeaderSpec sep a -> [Either sep a] -- | Get the titles and column specifications from a header. headerContents :: HeaderSpec sep a -> [(HeaderColSpec, a)] instance Data.Traversable.Traversable (Text.Layout.Table.Spec.HeaderSpec.HeaderSpec sep) instance Data.Foldable.Foldable (Text.Layout.Table.Spec.HeaderSpec.HeaderSpec sep) instance GHC.Base.Functor (Text.Layout.Table.Spec.HeaderSpec.HeaderSpec sep) instance Data.Bifunctor.Bifunctor Text.Layout.Table.Spec.HeaderSpec.HeaderSpec instance Data.Default.Class.Default sep => Data.Default.Class.Default (Text.Layout.Table.Spec.HeaderSpec.HeaderSpec sep a) module Text.Layout.Table.Spec.ColSpec -- | Specifies the layout of a column. data ColSpec lenSpec :: ColSpec -> LenSpec position :: ColSpec -> Position H -- | Displays at the left or top, depending on the orientation. beginning :: Position orientation alignSpec :: ColSpec -> AlignSpec cutMark :: ColSpec -> CutMark -- | The default CutMark is a single ellipsis unicode character on -- each side. ellipsisCutMark :: CutMark -- | Smart constructor to specify a column. column :: LenSpec -> Position H -> AlignSpec -> CutMark -> ColSpec -- | The default ColSpec uses as much space as needed, positioned at -- the left/top (depending on orientation), does not align to any -- character, and uses a single unicode ellipsis on either side as a cut -- mark. defColSpec :: 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. data RowGroup a SingletonRowGroup :: Row a -> RowGroup a MultiRowGroup :: [Row a] -> RowGroup a NullableRowGroup :: [Row (Maybe a)] -> RowGroup a -- | Group the given rows together. rowsG :: [Row a] -> RowGroup a -- | Make a group of a single row. rowG :: Row a -> RowGroup a -- | Provide a RowGroup where single cells may be missing. nullableRowsG :: [Row (Maybe a)] -> RowGroup a -- | Extracts the shape of the RowGroup from the first row. rowGroupShape :: RowGroup a -> [()] data ColumnSegment a SingleValueSegment :: a -> ColumnSegment a ColumnSegment :: Col a -> ColumnSegment a NullableColumnSegment :: Col (Maybe a) -> ColumnSegment a newtype SegmentedColumn a SegmentedColumn :: [ColumnSegment a] -> SegmentedColumn a -- | Break down several RowGroups, which conceptually form a -- column by themselves, into a list of columns. transposeRowGroups :: Col (RowGroup a) -> [SegmentedColumn a] -- | Map each column with the corresponding function and replace empty -- inputs with the given value. mapRowGroupColumns :: [(b, a -> b)] -> RowGroup a -> [[b]] instance GHC.Show.Show a => GHC.Show.Show (Text.Layout.Table.Spec.RowGroup.ColumnSegment a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Text.Layout.Table.Spec.RowGroup.ColumnSegment a) instance Data.Foldable.Foldable Text.Layout.Table.Spec.RowGroup.ColumnSegment instance GHC.Base.Functor Text.Layout.Table.Spec.RowGroup.ColumnSegment instance GHC.Show.Show a => GHC.Show.Show (Text.Layout.Table.Spec.RowGroup.SegmentedColumn a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Text.Layout.Table.Spec.RowGroup.SegmentedColumn a) instance Data.Foldable.Foldable Text.Layout.Table.Spec.RowGroup.SegmentedColumn instance GHC.Base.Functor Text.Layout.Table.Spec.RowGroup.SegmentedColumn 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 a Text. textB :: StringBuilder a => Text -> 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 -- | Creates a StringBuilder with the amount of missing spaces. remSpacesB' :: StringBuilder b => Int -> Int -> b instance Text.Layout.Table.StringBuilder.StringBuilder GHC.Base.String instance Text.Layout.Table.StringBuilder.StringBuilder (Data.Semigroup.Internal.Endo GHC.Base.String) instance Text.Layout.Table.StringBuilder.StringBuilder Data.Text.Internal.Text instance Text.Layout.Table.StringBuilder.StringBuilder Data.Text.Internal.Builder.Builder -- | 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 provided delimiters around -- the content appropriately and visually separate by hSpace. horizontalDetailLine :: StringBuilder b => String -> String -> String -> String -> String -> (Maybe b, Row (Either String b)) -> b -- | Render a line with actual content. horizontalContentLine :: StringBuilder b => String -> String -> String -> (Maybe b, Row (Either String b)) -> b module Text.Layout.Table.Cell -- | Ensure a value is not negative. truncateNegative :: Int -> Int -- | An object along with the amount that its length should be adjusted on -- both the left and right. Positive numbers are padding and negative -- numbers are trimming. data CellView a CellView :: a -> Int -> Int -> CellView a [baseCell] :: CellView a -> a [leftAdjustment] :: CellView a -> Int [rightAdjustment] :: CellView a -> Int -- | Add an adjustment to the left and right of a Cell. Positive -- numbers are padding and negative numbers are trimming. adjustCell :: Int -> Int -> a -> CellView a -- | Drop a number of characters from the left side. Treats negative -- numbers as zero. dropLeft :: Int -> a -> CellView a -- | Drop a number of characters from the right side. Treats negative -- numbers as zero. dropRight :: Int -> a -> CellView a -- | Drop characters from both sides. Treats negative numbers as zero. dropBoth :: Int -> Int -> a -> CellView a -- | The total amount of adjustment in CellView. totalAdjustment :: CellView a -> Int -- | Redistribute padding or trimming using a given ratio. redistributeAdjustment :: Int -> Int -> CellView a -> CellView a -- | Types that can be measured for visible characters, define a sub-string -- operation and turned into a StringBuilder. class Cell a -- | Returns the length of the visible characters as displayed on the -- output medium. visibleLength :: Cell a => a -> Int -- | Measure the preceding 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 -- | Insert the contents into a StringBuilder, padding or trimming -- as necessary. -- -- The Cell instance of 'CellView a' means that this can usually -- be substituted with buildCell, and is only needed for defining -- the instance. buildCellView :: (Cell a, StringBuilder b) => CellView a -> b -- | Construct buildCellView from a builder function, a function for -- trimming from the left, and a function for trimming from the right. -- -- Used to define instances of Cell. buildCellViewLRHelper :: StringBuilder b => (a -> b) -> (Int -> a -> a) -> (Int -> a -> a) -> CellView a -> b -- | Construct buildCellView from a builder function, and a function -- for trimming from the left and right simultaneously. -- -- Used to define instanced of Cell. buildCellViewBothHelper :: StringBuilder b => (a -> b) -> (Int -> Int -> a -> a) -> CellView a -> b -- | Construct buildCellView from builder functions and trimming -- functions. -- -- Used to define instances of Cell. buildCellViewHelper :: StringBuilder b => (a -> b) -> (Int -> a -> b) -> (Int -> a -> b) -> (Int -> Int -> a -> b) -> CellView a -> b -- | Creates a StringBuilder with the amount of missing spaces. remSpacesB :: (Cell a, StringBuilder b) => Int -> a -> b -- | Fill the right side with spaces if necessary. fillRight :: Cell a => Int -> a -> CellMod a -- | Fill the right side with spaces if necessary. Preconditions that are -- required to be met (otherwise the function will produce garbage): -- --
--   visibleLength c == k
--   
fillRight' :: Cell a => Int -> Int -> a -> CellMod a -- | Fill both sides with spaces if necessary. fillCenter :: Cell a => Int -> a -> CellMod a -- | Fill both sides with spaces if necessary. Preconditions that are -- required to be met (otherwise the function will produce garbage): -- --
--   visibleLength c == k
--   
fillCenter' :: Cell a => Int -> Int -> a -> CellMod a -- | Fill the left side with spaces if necessary. fillLeft :: Cell a => Int -> a -> CellMod a -- | Fill the left side with spaces if necessary. Preconditions that are -- required to be met (otherwise the function will produce garbage): -- --
--   visibleLength c == k
--   
fillLeft' :: Cell a => Int -> Int -> a -> CellMod a -- | Pads the given cell accordingly using the position specification. -- --
--   >>> buildCellMod noCutMark $ pad left 10 "foo" :: String
--   "foo       "
--   
pad :: Cell a => Position o -> Int -> a -> CellMod a -- | Pads the given cell accordingly using the position specification. -- Preconditions that are required to be met (otherwise the function will -- produce garbage): -- --
--   visibleLength c == k
--   
pad' :: Cell a => Position o -> Int -> Int -> a -> CellMod a -- | 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. -- --
--   >>> let cm = singleCutMark ".."
--   
--   >>> buildCellMod cm $ trimOrPad left cm 10 "A longer text." :: String
--   "A longer.."
--   
trimOrPad :: Cell a => Position o -> CutMark -> Int -> a -> CellMod a -- | If the given text is too long, it will be trimmed to length -- upper according to the position specification, and cut marks -- will be added to indicate that the column has been trimmed in length. -- Otherwise, if the given text is too short, it will be padded to length -- lower. -- --
--   >>> let cm = singleCutMark ".."
--   
--   >>> buildCellMod cm $ trimOrPadBetween left cm 7 10 "A longer text." :: String
--   "A longer.."
--   
--   >>> buildCellMod cm $ trimOrPadBetween left cm 7 10 "Short" :: String
--   "Short  "
--   
--   >>> buildCellMod cm $ trimOrPadBetween left cm 7 10 "A medium" :: String
--   "A medium"
--   
-- -- Preconditions that are required to be met (otherwise the output will -- be counterintuitive): -- --
--   lower <= upper
--   
trimOrPadBetween :: Cell a => Position o -> CutMark -> Int -> Int -> a -> CellMod a -- | Trim a cell based on the position. Cut marks may be trimmed if -- necessary. trim :: Cell a => Position o -> CutMark -> Int -> a -> CellMod a -- | Trim a cell based on the position. Cut marks may be trimmed if -- necessary. -- -- Preconditions that are required to be met (otherwise the function will -- produce garbage): -- --
--   visibleLength c > n
--   
-- --
--   visibleLength c == k
--   
trim' :: Cell a => Position o -> CutMark -> Int -> Int -> a -> CellMod a -- | 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 buildCellMod noCutMark . 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 => OccSpec -> AlignInfo -> a -> CellMod a 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. numSpacesAfterCut :: CutAction -> Int -> Int -> Int applyCutInfo :: Cell a => CutInfo -> CutMark -> Int -> Int -> a -> CellMod a -- | 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 => Position o -> CutMark -> Int -> OccSpec -> AlignInfo -> a -> CellMod a -- | Interpret CellMod to create a builder. buildCellMod :: (Cell c, StringBuilder s) => CutMark -> CellMod c -> s instance GHC.Base.Functor Text.Layout.Table.Cell.CellView instance GHC.Show.Show a => GHC.Show.Show (Text.Layout.Table.Cell.CellView a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Text.Layout.Table.Cell.CellView a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Text.Layout.Table.Cell.CellView a) instance GHC.Show.Show Text.Layout.Table.Cell.CutAction instance GHC.Classes.Eq Text.Layout.Table.Cell.CutAction instance GHC.Show.Show Text.Layout.Table.Cell.CutInfo instance GHC.Classes.Eq Text.Layout.Table.Cell.CutInfo instance Text.Layout.Table.Cell.Cell a => Text.Layout.Table.Cell.Cell (Text.Layout.Table.Cell.CellView a) instance Text.Layout.Table.Cell.Cell a => Text.Layout.Table.Cell.Cell (GHC.Maybe.Maybe a) instance (Text.Layout.Table.Cell.Cell a, Text.Layout.Table.Cell.Cell b) => Text.Layout.Table.Cell.Cell (Data.Either.Either a b) instance Text.Layout.Table.Cell.Cell GHC.Base.String instance Text.Layout.Table.Cell.Cell Data.Text.Internal.Text instance GHC.Base.Applicative Text.Layout.Table.Cell.CellView instance GHC.Base.Monad Text.Layout.Table.Cell.CellView 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 -- deriveColModInfosFromGrid. 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 :: Cell a => a -> Position H -> ColModInfo -> ColModInfo -- | Fit titles of a header column into the derived ColModInfo. fitTitlesCMI :: Cell a => [a] -> [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 -- | Generate the AlignInfo of a cell by using the OccSpec. deriveAlignInfo :: Cell a => OccSpec -> a -> AlignInfo unpackColSpecs :: [ColSpec] -> [(LenSpec, AlignSpec)] -- | Derive the ColModInfo for each column of a list of rows by -- using the corresponding specifications. deriveColModInfosFromGridLA :: Cell a => [(LenSpec, AlignSpec)] -> [Row a] -> [ColModInfo] -- | Derive the ColModInfo for each column of a list of rows by -- using the corresponding ColSpec. deriveColModInfosFromGrid :: Cell a => [ColSpec] -> [Row a] -> [ColModInfo] -- | Derive the ColModInfo of a single column by using the -- LenSpec and the AlignSpec. deriveColModInfoFromColumnLA :: (Foldable col, Cell a) => (LenSpec, AlignSpec) -> col a -> ColModInfo -- | Derive the ColModInfo for each column of a list of columns by -- using the corresponding specifications. deriveColModInfosFromColumnsLA :: (Foldable col, Cell a) => [(LenSpec, AlignSpec)] -> [col a] -> [ColModInfo] -- | Derive the ColModInfo for each column of a list of columns by -- using the corresponding ColSpec. deriveColModInfosFromColumns :: (Foldable col, Cell a) => [ColSpec] -> [col a] -> [ColModInfo] -- | Derive the ColModInfo and generate functions without any -- intermediate steps. deriveColumnModifiers :: (Cell a, StringBuilder b) => [ColSpec] -> [Row a] -> [a -> b] module Text.Layout.Table.Primitives.Header -- | Combine a HeaderColSpec and existing ColModInfos to -- format header cells. headerCellModifier :: (Cell a, StringBuilder b) => HeaderColSpec -> CutMark -> ColModInfo -> a -> b -- | Render tables that can be used in Pandoc. In particular, this -- supports the pipe_tables extension. module Text.Layout.Table.Pandoc -- | The separator to be used for HeaderSpec. The only supported -- value is def. Typically, it is not necessary to use this. data PandocSeparator -- | Generate a table that is readable but also serves as input to pandoc. -- --
--   >>> mapM_ putStrLn $ pandocPipeTableLines [defColSpec, numCol] (titlesH ["text", "numeric value"]) [["a", "1.5"], ["b", "6.60000"]]
--   |text|numberic value|
--   |:---|-------------:|
--   |a   |       1.5    |
--   |b   |       6.60000|
--   
pandocPipeTableLines :: Cell c => [ColSpec] -> HeaderSpec PandocSeparator c -> [Row String] -> [String] instance Data.Default.Class.Default Text.Layout.Table.Pandoc.PandocSeparator module Text.Layout.Table.Cell.WideString -- | A newtype for String in which characters can be wider than one space. newtype WideString WideString :: String -> WideString -- | A newtype for Text in which characters can be wider than one space. newtype WideText WideText :: Text -> WideText instance Data.String.IsString Text.Layout.Table.Cell.WideString.WideString instance GHC.Base.Monoid Text.Layout.Table.Cell.WideString.WideString instance GHC.Base.Semigroup Text.Layout.Table.Cell.WideString.WideString instance GHC.Read.Read Text.Layout.Table.Cell.WideString.WideString instance GHC.Show.Show Text.Layout.Table.Cell.WideString.WideString instance GHC.Classes.Ord Text.Layout.Table.Cell.WideString.WideString instance GHC.Classes.Eq Text.Layout.Table.Cell.WideString.WideString instance Data.String.IsString Text.Layout.Table.Cell.WideString.WideText instance GHC.Base.Monoid Text.Layout.Table.Cell.WideString.WideText instance GHC.Base.Semigroup Text.Layout.Table.Cell.WideString.WideText instance GHC.Read.Read Text.Layout.Table.Cell.WideString.WideText instance GHC.Show.Show Text.Layout.Table.Cell.WideString.WideText instance GHC.Classes.Ord Text.Layout.Table.Cell.WideString.WideText instance GHC.Classes.Eq Text.Layout.Table.Cell.WideString.WideText instance Text.Layout.Table.Cell.Cell Text.Layout.Table.Cell.WideString.WideText instance Text.Layout.Table.Cell.Cell Text.Layout.Table.Cell.WideString.WideString -- | 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. -- -- More complex nested formatting can be achieved by using the -- Monoid instance. module Text.Layout.Table.Cell.Formatted data Formatted a -- | Create a value from content that is kept plain without any formatting. plain :: a -> 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 -> Formatted a -> String -> Formatted a -- | Map over the formatting directives of a formatted value. mapAffix :: (String -> String) -> (String -> String) -> Formatted a -> Formatted a -- | Process a formatted value to produce an arbitrary value. This is the -- catamorphism for Formatted. cataFormatted :: b -> ([b] -> b) -> (a -> b) -> (String -> b -> String -> b) -> Formatted a -> b instance Data.Traversable.Traversable Text.Layout.Table.Cell.Formatted.Formatted instance Data.Foldable.Foldable Text.Layout.Table.Cell.Formatted.Formatted instance GHC.Base.Functor Text.Layout.Table.Cell.Formatted.Formatted instance GHC.Show.Show a => GHC.Show.Show (Text.Layout.Table.Cell.Formatted.Formatted a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Text.Layout.Table.Cell.Formatted.Formatted a) instance Data.String.IsString a => Data.String.IsString (Text.Layout.Table.Cell.Formatted.Formatted a) instance GHC.Base.Semigroup (Text.Layout.Table.Cell.Formatted.Formatted a) instance GHC.Base.Monoid (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 predefined styles, combinators to modify them, -- abstract style descriptions, and combinators for quickly turning them -- into styles. -- -- The following resource may be useful for constructing your own -- primitive styles: -- https://en.wikipedia.org/wiki/Box-drawing_character. module Text.Layout.Table.Style -- | Uses lines and plus for joints. asciiS :: TableStyle LineStyle LineStyle -- | My usual ASCII table style. asciiRoundS :: TableStyle LineStyle LineStyle -- | Like asciiS, but uses double lines and double pluses for -- borders. asciiDoubleS :: TableStyle LineStyle LineStyle -- | Uses special unicode characters to draw clean thin boxes. unicodeS :: TableStyle LineStyle LineStyle -- | Same as unicodeS but uses bold headers. unicodeBoldHeaderS :: TableStyle LineStyle LineStyle -- | Like unicodeS but with rounded edges. unicodeRoundS :: TableStyle LineStyle LineStyle -- | Uses bold lines. unicodeBoldS :: TableStyle LineStyle LineStyle -- | Uses bold lines with the exception of group separators, which are -- striped. unicodeBoldStripedS :: TableStyle LineStyle LineStyle -- | Draw every line with a double frame. unicodeDoubleFrameS :: TableStyle LineStyle LineStyle -- | Remove the top, bottom, left, and right borders from a -- TableStyle. withoutBorders :: TableStyle a b -> TableStyle a b -- | Remove the top border from a TableStyle. withoutTopBorder :: TableStyle a b -> TableStyle a b -- | Remove the bottom border from a TableStyle. withoutBottomBorder :: TableStyle a b -> TableStyle a b -- | Remove the left border from a TableStyle. withoutLeftBorder :: TableStyle a b -> TableStyle a b -- | Remove the right border from a TableStyle. withoutRightBorder :: TableStyle a b -> TableStyle a b -- | Modify a TableStyle to use Unicode rounded corners. withRoundCorners :: TableStyle a b -> TableStyle a b -- | Inherit from a TableStyle through a pair of functions. inheritStyle :: (c -> a) -> (d -> b) -> TableStyle a b -> TableStyle c d -- | Inherit from a TableStyle using a triple of functions, -- specifying the correspondence for row separators, column heading -- separators, and column separators. inheritStyleHeaderGroup :: (c -> a) -> (c -> a) -> (d -> b) -> (d -> b) -> TableStyle a b -> TableStyle c d asciiTableStyleFromSpec :: TableStyleSpec -> TableStyle LineStyle LineStyle roundedAsciiTableStyleFromSpec :: TableStyleSpec -> TableStyle LineStyle LineStyle unicodeTableStyleFromSpec :: TableStyleSpec -> TableStyle LineStyle LineStyle -- | Generate a 'TableStyle from a given TableStyleSpec, along with -- functions to construct horizontal and vertical lines and joins. The -- function for constructing join strings takes its arguments in the -- order west, east, north, south. tableStyleFromSpec :: (LineStyle -> String) -> (LineStyle -> String) -> (LineStyle -> LineStyle -> LineStyle -> LineStyle -> String) -> TableStyleSpec -> TableStyle LineStyle LineStyle -- | A short-hand specification for generating Unicode table styles, by -- specifying the line type of each of the main lines. data TableStyleSpec TableStyleSpec :: LineStyle -> LineStyle -> LineStyle -> LineStyle -> LineStyle -> LineStyle -> LineStyle -> LineStyle -> LineStyle -> LineStyle -> LineStyle -> LineStyle -> LineStyle -> LineStyle -> LineStyle -> LineStyle -> TableStyleSpec [headerSep] :: TableStyleSpec -> LineStyle [headerTop] :: TableStyleSpec -> LineStyle [headerLeft] :: TableStyleSpec -> LineStyle [headerRight] :: TableStyleSpec -> LineStyle [rowHeaderSep] :: TableStyleSpec -> LineStyle [rowHeaderLeft] :: TableStyleSpec -> LineStyle [rowHeaderTop] :: TableStyleSpec -> LineStyle [rowHeaderBottom] :: TableStyleSpec -> LineStyle [bothHeadersTop] :: TableStyleSpec -> LineStyle [bothHeadersBottom] :: TableStyleSpec -> LineStyle [bothHeadersLeft] :: TableStyleSpec -> LineStyle [bothHeadersRight] :: TableStyleSpec -> LineStyle [groupLeft] :: TableStyleSpec -> LineStyle [groupRight] :: TableStyleSpec -> LineStyle [groupTop] :: TableStyleSpec -> LineStyle [groupBottom] :: TableStyleSpec -> LineStyle -- | Constructs a simple TableStyleSpec which uses the given -- LineStyles in the headers and group, respectively. simpleTableStyleSpec :: LineStyle -> LineStyle -> TableStyleSpec -- | Modify a TableStyleSpec to use the given LineStyle for -- header separators. setTableStyleSpecSeparator :: LineStyle -> TableStyleSpec -> TableStyleSpec -- | Specifies the different letters to construct the non-content structure -- of a table. -- -- This is quite low-level and difficult to construct by hand. If you -- want to construct your own, you may wish to use the higher-level -- interface provided by (in increasing order of detail): -- --
    --
  1. simpleTableStyleSpec
  2. --
  3. TableStyleSpec
  4. --
  5. unicodeTableStyleFromSpec
  6. --
  7. asciiTableStyleFromSpec
  8. --
  9. tableStyleFromSpec
  10. --
data TableStyle rowSep colSep TableStyle :: String -> String -> String -> (colSep -> colSep -> String) -> String -> String -> String -> (colSep -> String) -> String -> String -> (colSep -> String) -> String -> String -> String -> (rowSep -> rowSep -> String) -> String -> String -> String -> (rowSep -> String) -> String -> String -> (rowSep -> String) -> String -> String -> String -> String -> String -> String -> String -> String -> String -> String -> (colSep -> String) -> (rowSep -> String) -> (rowSep -> colSep -> String) -> (rowSep -> String) -> (rowSep -> String) -> (colSep -> String) -> String -> String -> String -> (colSep -> String) -> String -> String -> String -> TableStyle rowSep colSep [headerSepH] :: TableStyle rowSep colSep -> String [headerSepLC] :: TableStyle rowSep colSep -> String [headerSepRC] :: TableStyle rowSep colSep -> String [headerSepC] :: TableStyle rowSep colSep -> colSep -> colSep -> String [headerTopH] :: TableStyle rowSep colSep -> String [headerTopL] :: TableStyle rowSep colSep -> String [headerTopR] :: TableStyle rowSep colSep -> String [headerTopC] :: TableStyle rowSep colSep -> colSep -> String [headerL] :: TableStyle rowSep colSep -> String [headerR] :: TableStyle rowSep colSep -> String [headerC] :: TableStyle rowSep colSep -> colSep -> String [rowHeaderSepV] :: TableStyle rowSep colSep -> String [rowHeaderSepTC] :: TableStyle rowSep colSep -> String [rowHeaderSepBC] :: TableStyle rowSep colSep -> String [rowHeaderSepC] :: TableStyle rowSep colSep -> rowSep -> rowSep -> String [rowHeaderLeftV] :: TableStyle rowSep colSep -> String [rowHeaderLeftT] :: TableStyle rowSep colSep -> String [rowHeaderLeftB] :: TableStyle rowSep colSep -> String [rowHeaderLeftC] :: TableStyle rowSep colSep -> rowSep -> String [rowHeaderT] :: TableStyle rowSep colSep -> String [rowHeaderB] :: TableStyle rowSep colSep -> String [rowHeaderC] :: TableStyle rowSep colSep -> rowSep -> String [bothHeadersTL] :: TableStyle rowSep colSep -> String [bothHeadersTR] :: TableStyle rowSep colSep -> String [bothHeadersBL] :: TableStyle rowSep colSep -> String [bothHeadersBR] :: TableStyle rowSep colSep -> String [bothHeadersL] :: TableStyle rowSep colSep -> String [bothHeadersR] :: TableStyle rowSep colSep -> String [bothHeadersT] :: TableStyle rowSep colSep -> String [bothHeadersB] :: TableStyle rowSep colSep -> String [groupL] :: TableStyle rowSep colSep -> String [groupR] :: TableStyle rowSep colSep -> String [groupC] :: TableStyle rowSep colSep -> colSep -> String [groupSepH] :: TableStyle rowSep colSep -> rowSep -> String [groupSepC] :: TableStyle rowSep colSep -> rowSep -> colSep -> String [groupSepLC] :: TableStyle rowSep colSep -> rowSep -> String [groupSepRC] :: TableStyle rowSep colSep -> rowSep -> String [groupTopC] :: TableStyle rowSep colSep -> colSep -> String [groupTopL] :: TableStyle rowSep colSep -> String [groupTopR] :: TableStyle rowSep colSep -> String [groupTopH] :: TableStyle rowSep colSep -> String [groupBottomC] :: TableStyle rowSep colSep -> colSep -> String [groupBottomL] :: TableStyle rowSep colSep -> String [groupBottomR] :: TableStyle rowSep colSep -> String [groupBottomH] :: TableStyle rowSep colSep -> String module Text.Layout.Table.Spec.TableSpec -- | Type used to specify tables. data TableSpec rowSep colSep r c a TableSpec :: [ColSpec] -> TableStyle rowSep colSep -> HeaderSpec rowSep r -> HeaderSpec colSep c -> [RowGroup a] -> TableSpec rowSep colSep r c a -- | Layout specification of the columns [colSpecs] :: TableSpec rowSep colSep r c a -> [ColSpec] -- | The style of the table [tableStyle] :: TableSpec rowSep colSep r c a -> TableStyle rowSep colSep -- | Specification of the row header [rowHeader] :: TableSpec rowSep colSep r c a -> HeaderSpec rowSep r -- | Specification of the column header [colHeader] :: TableSpec rowSep colSep r c a -> HeaderSpec colSep c -- | A list of visually separated rows [rowGroups] :: TableSpec rowSep colSep r c a -> [RowGroup a] -- | Specify a table with the style and the row groups. simpleTableS :: (Default rowSep, Default colSep) => TableStyle rowSep colSep -> [RowGroup a] -> TableSpec rowSep colSep String String a -- | Specify a table with the columns, the style, and the row groups. headerlessTableS :: (Default rowSep, Default colSep) => [ColSpec] -> TableStyle rowSep colSep -> [RowGroup a] -> TableSpec rowSep colSep String String a -- | Specify a table without a row header. columnHeaderTableS :: Default rowSep => [ColSpec] -> TableStyle rowSep colSep -> HeaderSpec colSep c -> [RowGroup a] -> TableSpec rowSep colSep String c a -- | Specify a table with everything. fullTableS :: [ColSpec] -> TableStyle rowSep colSep -> HeaderSpec rowSep r -> HeaderSpec colSep c -> [RowGroup a] -> TableSpec rowSep colSep r c a -- | 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"]]
--   [[Just "This  text",Just "42"],[Just "will   not",Just "23"],[Just "fit on one",Nothing],[Just "line.",Nothing]]
--   
-- -- The result is intended to be used with a grid layout function like -- grid. colsAsRowsAll :: Position V -> [Col a] -> [Row (Maybe a)] -- | Works like colsAsRowsAll but every position can be specified on -- its own: -- --
--   >>> colsAsRows [top, center, bottom] [["a1"], ["b1", "b2", "b3"], ["c3"]]
--   [[Just "a1",Just "b1",Nothing],[Nothing,Just "b2",Nothing],[Nothing,Just "b3",Just "c3"]]
--   
colsAsRows :: [Position V] -> [Col a] -> [Row (Maybe 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 -- | The default ColSpec uses as much space as needed, positioned at -- the left/top (depending on orientation), does not align to any -- character, and uses a single unicode ellipsis on either side as a cut -- mark. defColSpec :: 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 -- | The column will be at least as wide as the first width, and will -- expand as long as it is smaller than the second. expandBetween :: Int -> 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 -- | Displays at the left or top, depending on the orientation. beginning :: Position orientation -- | Determines whether a column will align at a specific letter. data AlignSpec -- | Do not align text. noAlign :: AlignSpec -- | Align text at the first occurence of a given Char. charAlign :: Char -> AlignSpec -- | Align text 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 a cut mark that is used whenever content is cut to fit into -- a cell. If the cut mark itself is too small to fit into a cell it may -- be cut as well. data CutMark -- | Do not show any cut mark when content 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 -- | The default CutMark is a single ellipsis unicode character on -- each side. ellipsisCutMark :: CutMark -- | An alias for lists, conceptually for values with a horizontal -- arrangement. type Row a = [a] -- | A version of gridB specialized to String. grid :: Cell a => [ColSpec] -> [Row a] -> [Row String] -- | Modifies cells according to the column specification. gridB :: (Cell a, StringBuilder b) => [ColSpec] -> [Row a] -> [Row b] -- | Modifies cells according to the column specification, also returning -- the ColModInfo used to generate the grid. gridBWithCMIs :: (Cell a, StringBuilder b) => [ColSpec] -> [Row a] -> ([Row b], [ColModInfo]) -- | A version of gridLinesB specialized to String. gridLines :: Cell a => [ColSpec] -> [Row a] -> [String] -- | A version of gridB that joins the cells of a row with one -- space. gridLinesB :: (Cell a, StringBuilder b) => [ColSpec] -> [Row a] -> [b] -- | A version of gridStringB specialized to String. gridString :: Cell a => [ColSpec] -> [Row a] -> String -- | A version of gridLinesB that also concatenates the lines. gridStringB :: (Cell a, StringBuilder b) => [ColSpec] -> [Row a] -> b -- | Concatenates a row with a given amount of spaces. concatRow :: StringBuilder b => Int -> Row b -> b concatLines :: StringBuilder b => [b] -> b -- | Concatenates a whole grid with the given amount of horizontal spaces -- between columns. 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 :: [Position V] -> [Col a] -> RowGroup a -- | Create a RowGroup by aligning the columns vertically. Each -- column uses the same position. colsAllG :: Position V -> [Col a] -> RowGroup a -- | A version of tableLinesB specialized to String. tableLines :: (Cell a, Cell r, Cell c) => TableSpec rowSep colSep r c a -> [String] -- | Renders a table as StringBuilder lines. Note that providing -- fewer layout specifications than columns or vice versa will result in -- not showing the redundant ones. tableLinesB :: (Cell a, Cell r, Cell c, StringBuilder b) => TableSpec rowSep colSep r c a -> [b] -- | Renders a table as StringBuilder lines, providing the -- ColModInfo for each column. Note that providing fewer layout -- specifications than columns or vice versa will result in not showing -- the redundant ones. tableLinesBWithCMIs :: forall rowSep r colSep c a b. (Cell a, Cell r, Cell c, StringBuilder b) => TableSpec rowSep colSep r c a -> ([b], [ColModInfo]) -- | A version of tableStringB specialized to String. tableString :: (Cell a, Cell r, Cell c) => TableSpec rowSep colSep r c a -> String -- | A version of tableLinesB that also concatenates the lines. tableStringB :: (Cell a, Cell r, Cell c, StringBuilder b) => TableSpec rowSep colSep r c a -> b -- | 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 sep a -- | Specify no header, with columns separated by a given separator. noneSepH :: sep -> HeaderSpec sep String -- | Specify no header, with columns separated by a default separator. noneH :: Default sep => HeaderSpec sep String -- | Specify every header column in detail and separate them by the given -- separator. fullSepH :: sep -> [HeaderColSpec] -> [a] -> HeaderSpec sep a -- | Specify every header column in detail and separate them with the -- default separator. fullH :: Default sep => [HeaderColSpec] -> [a] -> HeaderSpec sep a -- | Use titles with the default header column specification and separator. titlesH :: Default sep => [a] -> HeaderSpec sep a -- | Combine the header specification for multiple columns by separating -- the columns with a specific separator. groupH :: sep -> [HeaderSpec sep a] -> HeaderSpec sep a -- | Specify the header for a single column. headerH :: HeaderColSpec -> a -> HeaderSpec sep a -- | The default HeaderColSpec centers the text and uses no -- CutMark. defHeaderColSpec :: HeaderColSpec -- | 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] -- | Vertical orientation. data V top :: Position V bottom :: Position V -- | 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"]]
--   [[Just "This  text",Just "42"],[Just "will   not",Just "23"],[Just "fit on one",Nothing],[Just "line.",Nothing]]
--   
-- -- The result is intended to be used with a grid layout function like -- grid. colsAsRowsAll :: Position V -> [Col a] -> [Row (Maybe a)] -- | Works like colsAsRowsAll but every position can be specified on -- its own: -- --
--   >>> colsAsRows [top, center, bottom] [["a1"], ["b1", "b2", "b3"], ["c3"]]
--   [[Just "a1",Just "b1",Nothing],[Nothing,Just "b2",Nothing],[Nothing,Just "b3",Just "c3"]]
--   
colsAsRows :: [Position V] -> [Col a] -> [Row (Maybe a)] -- | Pads the given cell accordingly using the position specification. -- --
--   >>> buildCellMod noCutMark $ pad left 10 "foo" :: String
--   "foo       "
--   
pad :: Cell a => Position o -> Int -> a -> CellMod a -- | Trim a cell based on the position. Cut marks may be trimmed if -- necessary. trim :: Cell a => Position o -> CutMark -> Int -> a -> CellMod a -- | 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. -- --
--   >>> let cm = singleCutMark ".."
--   
--   >>> buildCellMod cm $ trimOrPad left cm 10 "A longer text." :: String
--   "A longer.."
--   
trimOrPad :: Cell a => Position o -> CutMark -> Int -> a -> CellMod a -- | If the given text is too long, it will be trimmed to length -- upper according to the position specification, and cut marks -- will be added to indicate that the column has been trimmed in length. -- Otherwise, if the given text is too short, it will be padded to length -- lower. -- --
--   >>> let cm = singleCutMark ".."
--   
--   >>> buildCellMod cm $ trimOrPadBetween left cm 7 10 "A longer text." :: String
--   "A longer.."
--   
--   >>> buildCellMod cm $ trimOrPadBetween left cm 7 10 "Short" :: String
--   "Short  "
--   
--   >>> buildCellMod cm $ trimOrPadBetween left cm 7 10 "A medium" :: String
--   "A medium"
--   
-- -- Preconditions that are required to be met (otherwise the output will -- be counterintuitive): -- --
--   lower <= upper
--   
trimOrPadBetween :: Cell a => Position o -> CutMark -> Int -> Int -> a -> CellMod a -- | 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 buildCellMod noCutMark . 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 => OccSpec -> AlignInfo -> a -> CellMod a -- | Aligns a cell using a fixed width, fitting it to the width by either -- filling or cutting while respecting the alignment. alignFixed :: Cell a => Position o -> CutMark -> Int -> OccSpec -> AlignInfo -> a -> CellMod a -- | Interpret CellMod to create a builder. buildCellMod :: (Cell c, StringBuilder s) => CutMark -> CellMod c -> s -- | Add an adjustment to the left and right of a Cell. Positive -- numbers are padding and negative numbers are trimming. adjustCell :: Int -> Int -> a -> CellView a -- | Specifies how a column should be modified. Values of this type are -- derived in a traversal over the input columns by using -- deriveColModInfosFromGrid. 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 :: Cell a => a -> 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 for each column of a list of rows by -- using the corresponding ColSpec. deriveColModInfosFromGrid :: Cell a => [ColSpec] -> [Row a] -> [ColModInfo] -- | Derive the ColModInfo for each column of a list of columns by -- using the corresponding ColSpec. deriveColModInfosFromColumns :: (Foldable col, Cell a) => [ColSpec] -> [col 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 -- | Zip a HeaderSpec with a list. zipHeader :: b -> [b] -> HeaderSpec sep a -> HeaderSpec sep (b, a) -- | Flatten a header to produce a list of content and separators. flattenHeader :: HeaderSpec sep a -> [Either sep a] -- | Get the titles and column specifications from a header. headerContents :: HeaderSpec sep a -> [(HeaderColSpec, a)]