table-layout 0.1.0.0 → 0.2.0.0
raw patch · 3 files changed
+45/−30 lines, 3 files
Files
- src/Text/Layout/Table.hs +36/−21
- src/Text/Layout/Table/Justify.hs +2/−2
- table-layout.cabal +7/−7
src/Text/Layout/Table.hs view
@@ -25,7 +25,7 @@ -- , rowGroup [["Short text", "100200.5"]] -- ] -- (Just (["Title", "Length"], repeat centerHL))--- [ limitLeftL 20+-- [ fixedLeftL 20 -- , LayoutSpec (Fixed 10) -- CenterPos -- dotAlign@@ -48,8 +48,8 @@ LayoutSpec(..) , defaultL , numL- , limitL- , limitLeftL+ , fixedL+ , fixedLeftL , LenSpec(..) , PosSpec(..) , AlignSpec(..)@@ -114,6 +114,7 @@ -- TODO RowGroup: optional: vertical group labels -- TODO RowGroup: optional: provide extra layout for a RowGroup -- TODO ColModInfo: provide a special version of ensureWidthOfCMI to force header visibility+-- TODO LayoutSpec: add some kind of combinator to construct LayoutSpec values (e.g. via Monoid, see optparse-applicative) import Control.Arrow import Data.List@@ -139,7 +140,7 @@ } deriving Show -- | Determines how long a column will be.-data LenSpec = Expand | Fixed Int deriving Show+data LenSpec = Expand | Fixed Int | ExpandUntil Int | FixedUntil Int deriving Show -- | Determines how a column will be positioned. Note that on an odd number of -- space, centering is left-biased.@@ -179,13 +180,13 @@ numL :: LayoutSpec numL = LayoutSpec Expand RightPos (AlignAtChar $ OccSpec '.' 0) defaultCutMark --- | Limits the column length and positions according to the given 'PosSpec'.-limitL :: Int -> PosSpec -> LayoutSpec-limitL l pS = LayoutSpec (Fixed l) pS NoAlign defaultCutMark+-- | Fixes the column length and positions according to the given 'PosSpec'.+fixedL :: Int -> PosSpec -> LayoutSpec+fixedL l pS = LayoutSpec (Fixed l) pS NoAlign defaultCutMark --- | Limits the column length and positions on the left.-limitLeftL :: Int -> LayoutSpec-limitLeftL i = limitL i LeftPos+-- | Fixes the column length and positions on the left.+fixedLeftL :: Int -> LayoutSpec+fixedLeftL i = fixedL i LeftPos ------------------------------------------------------------------------------- -- Single-cell layout functions.@@ -345,13 +346,30 @@ deriveColModInfos :: [(LenSpec, AlignSpec)] -> [[String]] -> [ColModInfo] deriveColModInfos specs = zipWith ($) (fmap fSel specs) . transpose where- fSel specs = case specs of- (Expand , NoAlign ) -> FillTo . maximum . fmap length- (Expand , AlignAtChar oS) -> FillAligned oS . deriveAlignInfos oS- (Fixed i, NoAlign ) -> const $ FitTo i Nothing- (Fixed i, AlignAtChar oS) -> FitTo i . Just . (,) oS . deriveAlignInfos oS- deriveAlignInfos = foldMap . deriveAlignInfo+ fSel (lenSpec, alignSpec) = case alignSpec of+ NoAlign -> let fitTo i = const $ FitTo i Nothing+ expandUntil f i max = if f (max <= i)+ then FillTo max+ else fitTo i max+ fun = case lenSpec of+ Expand -> FillTo+ Fixed i -> fitTo i+ ExpandUntil i -> expandUntil id i+ FixedUntil i -> expandUntil not i+ in fun . maximum . map length+ AlignAtChar oS -> let fitToAligned i = FitTo i . Just . (,) oS+ fillAligned = FillAligned oS+ expandUntil f i ai = if f (widthAI ai <= i)+ then fillAligned ai+ else fitToAligned i ai+ fun = case lenSpec of+ Expand -> fillAligned+ Fixed i -> fitToAligned i+ ExpandUntil i -> expandUntil id i+ 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@@ -435,15 +453,12 @@ -- Spacers consisting of columns of seperator elements. genHSpacers c = map (flip replicate c) colWidths- hHeaderSpacers = genHSpacers headerSepH- hGroupSpacers = genHSpacers groupSepH - -- Vertical seperator lines topLine = vLineDetail realTopH realTopL realTopC realTopR $ genHSpacers realTopH bottomLine = vLineDetail groupBottomH groupBottomL groupBottomC groupBottomR $ genHSpacers groupBottomH- groupSepLine = groupSepLC : groupSepH : intercalate [groupSepH, groupSepC, groupSepH] hGroupSpacers ++ [groupSepH, groupSepRC]- headerSepLine = vLineDetail headerSepH headerSepLC headerSepC headerSepRC hHeaderSpacers+ groupSepLine = vLineDetail groupSepH groupSepLC groupSepC groupSepRC $ genHSpacers groupSepH+ headerSepLine = vLineDetail headerSepH headerSepLC headerSepC headerSepRC $ genHSpacers headerSepH -- Vertical content lines rowGroupLines = intercalate [groupSepLine] $ map (map (vLine ' ' groupV) . applyRowMods . rows) rGs
src/Text/Layout/Table/Justify.hs view
@@ -1,6 +1,6 @@ -- | Produce justified text, which is spread over multiple rows, and join it--- with other columns. For a simple cut, 'chunksOf' from 'Data.List.Split' is--- the way to go.+-- with other columns. For a simple cut, 'chunksOf' from the `split` package+-- is best suited. {-# LANGUAGE MultiWayIf #-} module Text.Layout.Table.Justify ( justifyTextsAsGrid
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.1.0.0+version: 0.2.0.0 synopsis: Layout text as grid or table. @@ -15,17 +15,17 @@ functions which help in this task from the ground up, although using them is not necessary. It provides the following layout features: .- * Fixed-size and arbitrarily sized columns+ * Fixed-size and arbitrarily sized columns and limiting versions of those .- * Positional alignment of content+ * Positional alignment of content in a column .- * Alignment of text at a character occurence+ * Alignment of content within a column at a character occurence .- * Cut marks show that text has been trimmed+ * Cut marks show that content has been trimmed .- * Building fancy tables with optional headers and user styles+ * Fancy tables with optional headers and user styles .- * Layout text justified over multiple rows+ * Justified text layout over multiple rows -- URL for the project homepage or repository. homepage: https://github.com/muesli4/table-layout