packages feed

table-layout 0.6.0.0 → 0.6.0.1

raw patch · 5 files changed

+31/−30 lines, 5 files

Files

README.md view
@@ -92,8 +92,8 @@ │ Short text │ …00.5      │ └────────────┴────────────┘ ```-## Vertical positioning and justified text-Because a row group consists of multiple lines, we may also want to align the content of cells vertically, especially when we don't know how many lines will be there. Display a left-justified text alongside the length of the text:+### Vertical positioning and justified text+Because a row group consists of multiple lines, we may also want to align the content of cells vertically, especially when we don't know how many lines will be there. The following piece of code will display a left-justified text alongside the length of the text: ``` hs let txt = "Lorem ipsum ..."  in putStrLn $ layoutTableToString [colsAllG center [ justifyText 50 txt@@ -118,5 +118,10 @@ | amet.                                              |        | +----------------------------------------------------+--------+ ```+Additionally, the positioning can be specified for each column with `colsG`. For grids `colsAsRows` and `colsAsRowsAll` are provided.++## Suggestions++Feel free to contact me, I'm always happy about some feedback!  [ansi-terminal package]: http://hackage.haskell.org/package/ansi-terminal
src/Text/Layout/Table.hs view
@@ -105,7 +105,6 @@ -- TODO RowGroup:    optional: provide extra layout for a RowGroup -- TODO ColModInfo:  provide a special version of ensureWidthOfCMI to force header visibility -- TODO ColSpec:     add some kind of combinator to construct ColSpec values (e.g. via Monoid, see optparse-applicative)--- TODO              move functions not related to direct end-user into Primitives  import qualified Control.Arrow                                   as A import           Data.List@@ -404,7 +403,6 @@                                FixedUntil i  -> expandUntil not i                         in fun . foldMap (deriveAlignInfo oS) - -- | Generate the 'AlignInfo' of a cell using the 'OccSpec'. deriveAlignInfo :: OccSpec -> String -> AlignInfo deriveAlignInfo occSpec s = AlignInfo <$> length . fst <*> length . snd $ splitAtOcc occSpec s@@ -432,17 +430,17 @@ layoutToString tab specs = concatLines $ layoutToLines tab specs  ---------------------------------------------------------------------------------- Grid modifier functions+-- Grid modification functions ------------------------------------------------------------------------------- --- | Applies functions alternating to given lines. This makes it easy to color--- lines to improve readability in a row.+-- | 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] altLines = zipWith ($) . cycle --- | Applies functions alternating to cells for every line, every other line--- gets shifted by one. This is useful for distinguishability of single cells in--- a grid arrangement.+-- | 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]] checkeredCells f g = zipWith altLines $ cycle [[f, g], [g, f]] @@ -471,26 +469,26 @@ layoutTableToLines rGs optHeaderInfo specs (TableStyle { .. }) =     topLine : addHeaderLines (rowGroupLines ++ [bottomLine])   where-    -- Line helpers-    vLine hs d                  = vLineDetail hs d d d-    vLineDetail hS dL d dR cols = intercalate [hS] $ [dL] : intersperse [d] cols ++ [[dR]]+    -- Helpers for horizontal lines+    hLine hS d                  = hLineDetail hS d d d+    hLineDetail hS dL d dR cols = intercalate [hS] $ [dL] : intersperse [d] cols ++ [[dR]]      -- Spacers consisting of columns of seperator elements.     genHSpacers c    = map (flip replicate c) colWidths -    -- Vertical seperator lines-    topLine       = vLineDetail realTopH realTopL realTopC realTopR $ genHSpacers realTopH-    bottomLine    = vLineDetail groupBottomH groupBottomL groupBottomC groupBottomR $ genHSpacers groupBottomH-    groupSepLine  = vLineDetail groupSepH groupSepLC groupSepC groupSepRC $ genHSpacers groupSepH-    headerSepLine = vLineDetail headerSepH headerSepLC headerSepC headerSepRC $ genHSpacers headerSepH+    -- Horizontal seperator lines+    topLine       = hLineDetail realTopH realTopL realTopC realTopR $ genHSpacers realTopH+    bottomLine    = hLineDetail groupBottomH groupBottomL groupBottomC groupBottomR $ genHSpacers groupBottomH+    groupSepLine  = hLineDetail groupSepH groupSepLC groupSepC groupSepRC $ genHSpacers groupSepH+    headerSepLine = hLineDetail headerSepH headerSepLC headerSepC headerSepRC $ genHSpacers headerSepH      -- Vertical content lines-    rowGroupLines = intercalate [groupSepLine] $ map (map (vLine ' ' groupV) . applyRowMods . rows) rGs+    rowGroupLines = intercalate [groupSepLine] $ map (map (hLine ' ' groupV) . applyRowMods . rows) rGs      -- Optional values for the header     (addHeaderLines, fitHeaderIntoCMIs, realTopH, realTopL, realTopC, realTopR) = case optHeaderInfo of         Just (h, headerColSpecs) ->-            let headerLine    = vLine ' ' headerV (zipApply h headerRowMods)+            let headerLine    = hLine ' ' headerV (zipApply h headerRowMods)                 headerRowMods = zipWith3 (\(HeaderColSpec pos optCutMark) cutMark ->                                               columnModifier pos $ fromMaybe cutMark optCutMark                                          )
src/Text/Layout/Table/Justify.hs view
@@ -1,9 +1,8 @@--- | Produce justified text, which is spread over multiple rows, and join it--- with other columns. For a simple cut, 'chunksOf' from the `split` package--- is best suited.+-- | Produce justified text, which is spread over multiple rows. For a simple+-- cut, 'chunksOf' from the `split` package is best suited. {-# LANGUAGE MultiWayIf #-} module Text.Layout.Table.Justify-    ( -- * Justification of text.+    ( -- * Text justification       justify     , justifyText 
src/Text/Layout/Table/Vertical.hs view
@@ -20,17 +20,16 @@ >>> 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 'Text.Layout.Table.layoutToCells' or with-'Text.Layout.Table.rowsG'.+The result is intended to be used with a grid layout function like 'Text.Layout.Table.layoutToCells'. -} colsAsRowsAll :: Position V -> [Col [a]] -> [Row [a]] colsAsRowsAll ps = transpose . vPadAll [] ps -{- | Works like 'columnsAsRowsAll', but every position can be specified on its+{- | Works like 'colsAsRowsAll', but every position can be specified on its    own: ->>> colsAsRows [top, center, bottom] [["a1"], ["b1", "b2", "b3"], ["d3"]]-[["a1","b1",""],["","b2",""],["","b3","d3"]]+>>> colsAsRows [top, center, bottom] [["a1"], ["b1", "b2", "b3"], ["c3"]]+[["a1","b1",""],["","b2",""],["","b3","c3"]] -} colsAsRows :: [Position V] -> [Col [a]] -> [Row [a]] colsAsRows ps = transpose . vPad [] ps
table-layout.cabal view
@@ -6,7 +6,7 @@ -- PVP summary:      +-+------- breaking API changes --                   | | +----- non-breaking API additions --                   | | | +--- code changes with no API change-version:             0.6.0.0+version:             0.6.0.1  synopsis:            Layout text as grid or table.