packages feed

table-layout 0.5.1.1 → 0.5.2.0

raw patch · 7 files changed

+88/−29 lines, 7 filesdep ~data-default-class

Dependency ranges changed: data-default-class

Files

src/Text/Layout/Table.hs view
@@ -35,6 +35,23 @@ -- │ Short text           │ …200.5     │ -- ╰──────────────────────┴────────────╯ --+-- Using justified text and 'RowGroup's to group multiple rows together to form one cell:+--+-- >>> putStrLn $ layoutTableToString [rowGroup $ columnsAsGrid center [justifyText 50 txt, [show $ length txt]]]+--                                    (Just (["Text", "Length"], repeat def))+--                                    [fixedLeftCol 50, numCol]+--                                    asciiS+-- +----------------------------------------------------+--------++-- |                        Text                        | Length |+-- +----------------------------------------------------+--------++-- | Lorem  ipsum dolor sit amet, consetetur sadipscing |        |+-- | elitr,  sed  diam nonumy eirmod tempor invidunt ut |        |+-- | labore  et  dolore  magna  aliquyam erat, sed diam |        |+-- | voluptua.  At  vero  eos  et  accusam et justo duo |    295 |+-- | dolores et ea rebum. Stet clita kasd gubergren, no |        |+-- | sea  takimata  sanctus  est  Lorem ipsum dolor sit |        |+-- | amet.                                              |        |+-- +----------------------------------------------------+--------+ {-# LANGUAGE RecordWildCards #-} module Text.Layout.Table     ( -- * Layout combinators@@ -166,7 +183,7 @@  -- | Fixes the column length and positions according to the given 'Position'. fixedCol :: Int -> Position H -> ColSpec-fixedCol l pS = column (Fixed l) pS def def+fixedCol l pS = column (fixed l) pS def def  -- | Fixes the column length and positions on the left. fixedLeftCol :: Int -> ColSpec@@ -313,8 +330,12 @@                     toCutLfromR      = negate $ min 0 widthL                     toCutRfromL      = max 0 $ negate widthR                     (markL, funL)    = if lenL > widthL-                                       then (applyMarkLeftWith cms, take (widthL - toCutRfromL) . drop (lenL - widthL))-                                       else (id                   , fillLeft (widthL - toCutRfromL) . take (lenL - toCutRfromL))+                                       then ( applyMarkLeft+                                            , take (widthL - toCutRfromL) . drop (lenL - widthL)+                                            )+                                       else ( id+                                            , fillLeft (widthL - toCutRfromL) . take (lenL - toCutRfromL)+                                            )                     (markR, funR)    = if lenR > widthR                                        then (applyMarkRight, take widthR)                                        else (id            , fillRight widthR)@@ -323,6 +344,7 @@     fitRight       = fitRightWith cms     fitLeft        = fitLeftWith cms     applyMarkRight = applyMarkRightWith cms+    applyMarkLeft  = applyMarkLeftWith cms  -- | Specifies how a column should be modified. data ColModInfo = FillAligned OccSpec AlignInfo@@ -451,7 +473,7 @@ -- | Behaves like 'layoutToCells' but produces a 'String' by joining with the -- newline character. layoutToString :: [Row String] -> [ColSpec] -> String-layoutToString tab specs = intercalate "\n" $ layoutToLines tab specs+layoutToString tab specs = concatLines $ layoutToLines tab specs  ------------------------------------------------------------------------------- -- Grid modifier functions@@ -472,17 +494,6 @@ -- Advanced layout ------------------------------------------------------------------------------- --- | Construct a row group from a list of rows.-rowGroup :: [Row String] -> RowGroup-rowGroup = RowGroup---- | Header columns are usually centered.-instance Default HeaderColSpec where-    def = headerColumn center Nothing--headerColumn :: Position H -> Maybe CutMark -> HeaderColSpec-headerColumn = HeaderColSpec- -- | Layouts a good-looking table with a optional header. Note that specifying -- fewer layout specifications than columns or vice versa will result in not -- showing them.@@ -551,7 +562,7 @@                     -> [ColSpec]                     -> TableStyle                     -> String-layoutTableToString rGs optHeaderInfo specs = intercalate "\n" . layoutTableToLines rGs optHeaderInfo specs+layoutTableToString rGs optHeaderInfo specs = concatLines . layoutTableToLines rGs optHeaderInfo specs   -------------------------------------------------------------------------------
src/Text/Layout/Table/Internal.hs view
@@ -1,19 +1,31 @@ module Text.Layout.Table.Internal where  import Data.Default.Class+import Data.Default.Instances.Base  import Text.Layout.Table.Position import Text.Layout.Table.Primitives.Basic  -- | Groups rows together, which are not seperated from each other.-data RowGroup = RowGroup-              { rows     :: [[String]] -              }+newtype RowGroup = RowGroup+                 { rows     :: [[String]] +                 } +-- | Construct a row group from a list of rows.+rowGroup :: [Row String] -> RowGroup+rowGroup = RowGroup+ -- | Specifies how a header is layout, by omitting the cut mark it will use the -- one specified in the 'Text.Layout.Primitives.Column.ColSpec' like the other -- cells in that column. data HeaderColSpec = HeaderColSpec (Position H) (Maybe CutMark)++headerColumn :: Position H -> Maybe CutMark -> HeaderColSpec+headerColumn = HeaderColSpec++-- | Header columns are usually centered.+instance Default HeaderColSpec where+    def = headerColumn center def  -- | An alias for lists, conceptually for values with a horizontal arrangement. type Row a = [a]
src/Text/Layout/Table/Justify.hs view
@@ -7,11 +7,14 @@     , justifyWordListsAsGrid     , justifyText     , justify-    , dimorphicSummands-    , dimorphicSummandsBy+       -- * Vertical alignment of whole columns     , columnsAsGrid     , vpadCols++    -- * Helpers+    , dimorphicSummands+    , dimorphicSummandsBy     ) where  import Control.Arrow@@ -32,6 +35,7 @@ justifyWordListsAsGrid :: [(Int, [String])] -> [Row String] justifyWordListsAsGrid = columnsAsGrid top . fmap (uncurry justify) +-- TODO put in fitting module {- | Merges multiple columns together and merges them to a valid grid without    holes. The following example clarifies this: @@ -93,7 +97,7 @@     go y (y' : ys) = f y : go y' ys  dimorphicSpaces :: Int -> Int -> [String]-dimorphicSpaces = dimorphicSummandsBy $ flip replicate ' '+dimorphicSpaces = dimorphicSummandsBy spaces  -- | 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
src/Text/Layout/Table/Position/Internal.hs view
@@ -3,9 +3,9 @@ import Data.Default.Class  -- | Specifies a position relative from a beginning.-data Position orientation = Start | Center | End deriving Show+data Position orientation = Start | Center | End deriving (Show, Eq) -instance Default (Position o) where+instance Default (Position orientation) where     def = Start  -- | Horizontal orientation.
src/Text/Layout/Table/Primitives/Basic.hs view
@@ -10,6 +10,7 @@        -- * String-related tools     , spaces+    , concatLines        -- ** Filling     , fillLeft'@@ -38,6 +39,7 @@ -- TODO rename cut marks (they are too long)  import Data.Default.Class+import Data.List  -- | 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.@@ -69,6 +71,9 @@  spaces :: Int -> String spaces = flip replicate ' '++concatLines :: [String] -> String+concatLines = intercalate "\n"  fillStart' :: a -> Int -> Int -> [a] -> [a] fillStart' x i lenL l = replicate (i - lenL) x ++ l
src/Text/Layout/Table/Style.hs view
@@ -35,7 +35,7 @@             { headerSepH   = '='             , headerSepLC  = ':'             , headerSepRC  = ':'-            , headerSepC   = '|'+            , headerSepC   = ':'             , headerTopL   = '.'             , headerTopR   = '.'             , headerTopC   = '.'@@ -170,3 +170,30 @@ -- | Uses bold lines with exception of group seperators, which are striped slim. unicodeBoldStripedS :: TableStyle unicodeBoldStripedS = unicodeBoldS { groupSepH = '-', groupSepC = '┃', groupSepLC = '┃', groupSepRC = '┃' }++-- | Draw every line with a double frame.+unicodeDoubleFrameS :: TableStyle+unicodeDoubleFrameS = TableStyle+                    { headerSepH   = '═'+                    , headerSepLC  = '╠'+                    , headerSepRC  = '╣'+                    , headerSepC   = '╬'+                    , headerTopL   = '╔'+                    , headerTopR   = '╗'+                    , headerTopC   = '╦'+                    , headerTopH   = '═'+                    , headerV      = '║'+                    , groupV       = '║'+                    , groupSepH    = '═'+                    , groupSepC    = '╬'+                    , groupSepLC   = '╠'+                    , groupSepRC   = '╣'+                    , groupTopC    = '╦'+                    , groupTopL    = '╔'+                    , groupTopR    = '╗'+                    , groupTopH    = '═'+                    , groupBottomC = '╩'+                    , groupBottomL = '╚'+                    , groupBottomR = '╝'+                    , groupBottomH = '═'+                    }
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.5.1.1+version:             0.5.2.0  synopsis:            Layout text as grid or table. @@ -73,7 +73,7 @@      -- Other library packages from which modules are imported.   build-depends:       base >=4.8 && <4.9,-                       data-default-class >=0.0.1 && < 0.1,+                       data-default-class ==0.0.*,                        data-default-instances-base ==0.1.*    hs-source-dirs:      src@@ -84,7 +84,7 @@ executable table-layout-test-styles   main-is:             Test.hs   build-depends:       base >=4.8 && <4.9,-                       data-default-class >=0.0.1 && < 0.1,+                       data-default-class ==0.0.*,                        data-default-instances-base ==0.1.*   hs-source-dirs:      src   other-modules:       Text.Layout.Table@@ -98,7 +98,7 @@                        --Cabal,                        QuickCheck >=2.8 && < 2.9,                        HUnit ==1.3.*,-                       data-default-class >=0.0.1 && < 0.1,+                       data-default-class ==0.0.*,                        data-default-instances-base ==0.1.*,                        hspec