packages feed

table-layout 0.9.0.0 → 0.9.0.1

raw patch · 8 files changed

+68/−28 lines, 8 filesdep ~base

Dependency ranges changed: base

Files

CHANGELOG.md view
@@ -2,6 +2,18 @@  ## [Unreleased] +## [0.9.0.1] - 2020-06-14++### Added++- Provide functions for concatenation `concatRow`, `concatLines`, and+  `concatGrid`. (#10)++### Fixed++- Fix an error with `applyCutInfo` that created a string of wrong length in+  case the cut mark was of unequal length and the view was outside of the cell.+  ## [0.9.0.0] - 2020-04-10 
README.md view
@@ -10,7 +10,7 @@ * Columns can be positionally aligned as `left`, `right` or `center`. * Columns may also be aligned at certain character occurence with respect to the other cells of that column. One such purpose is to display floating point numbers. -Those specifications are then applied to a list of rows (currently only `String` is supported).+Those specifications are then applied to a list of rows. A row is simply a list of a cell. A cell is a type that implements the `Cell` type class.  Typically cells are rendered as a grid, but it is also possible to render tables with simulated lines, including styling support. Such tables can use optional headers and multiple lines per cell. Multi-line content can be aligned vertically, with respect to the other horizontally adjacent cells, and text can be rendered justified. @@ -55,11 +55,17 @@ * `altLines` will apply the given function in an alternating pattern. E.g., color every second row grey. * `checkeredCells` will checker cells with 2 different functions. -A good way to use this would be the [ansi-terminal package][], provided you are using a terminal to output your text.+A good way to use this would be the [ansi-terminal package][], provided you are using a terminal to output your text. Another way to introduce color into cells is the `Formatted` type:+```+> :set -XOverloadedStrings+> let red s = formatted "\ESC[31m" s "\ESC[0m"+> gridString [def, numCol] [["Jim", "1203"], ["Jane", "523"], ["Jack", red "-959000"]]+```+This way the color can depend on the cell content.  ### Table layout -For more complex data grids do not offer as much visibility. Sometimes we want to explicitly display a table, e.g., as output in a database application. `tableLines` and `tableString` are used to create a table.+For more complex data, grids do not offer as much visibility. Sometimes we want to explicitly display a table, for example, as output in a database application. `tableLines` and `tableString` are used to create a table.  ``` hs putStrLn $ tableString [def , numCol]@@ -69,8 +75,9 @@                        , rowG ["Jane", "162.2"]                        ] ```-A row group is a group of rows which form one cell. This means that each line of a group is not visually seperated from the other ones. In addition we specify the style and an optional header. By default the header is not visible. This will yield the following result:+A row group is a group of rows which are not visually separated from each other. Thus multiple rows form one cell. +In addition we specify the style and an optional header. By default the header is not visible. This will yield the following result: ``` ╭──────┬────────╮ │ Jack │ 184.74 │@@ -133,6 +140,8 @@  ## Get in contact -Please report issues and suggestions to the GitHub page. I'm always open for feedback (good and bad).+* Report issues and suggestions to the GitHub page.+* Any kind of feedback is welcome.+* Contributions are much appreciated. Contact me first for bigger changes.  [ansi-terminal package]: http://hackage.haskell.org/package/ansi-terminal
src/Text/Layout/Table.hs view
@@ -46,6 +46,9 @@     , grid     , gridLines     , gridString+    , concatRow+    , concatLines+    , concatGrid        -- * Grid modification functions     , altLines@@ -175,6 +178,20 @@ -- character. gridString :: Cell a => [ColSpec] -> [Row a] -> String gridString specs = concatLines . gridLines specs++concatLines :: StringBuilder b => [b] -> b+concatLines = mconcat . intersperse (charB '\n')++-- | Concatenates a row with a given amount of spaces.+concatRow+    :: StringBuilder b+    => Int+    -> Row b+    -> b+concatRow n bs = mconcat $ intersperse (replicateCharB n ' ') bs++concatGrid :: StringBuilder b => Int -> [Row b] -> b+concatGrid n = concatLines . fmap (concatRow n)  ------------------------------------------------------------------------------- -- Grid modification functions
src/Text/Layout/Table/Cell.hs view
@@ -208,9 +208,9 @@         let spacesB' = spacesB . surplusSpace         in spacesB' lCA <> buildCell c <> spacesB' rCA     MarkRightCI                       ->-        spacesB (max 0 $ availSpace - leftLen) <> applyRightMark availSpace+        spacesB (max 0 $ availSpace - rightLen) <> applyRightMark availSpace     MarkLeftCI                        ->-        applyLeftMark availSpace <> spacesB (max 0 $ availSpace - rightLen)+        applyLeftMark availSpace <> spacesB (max 0 $ availSpace - leftLen)   where     leftLen = length $ leftMark cm     rightLen = length $ rightMark cm
src/Text/Layout/Table/Primitives/Basic.hs view
@@ -3,7 +3,6 @@ module Text.Layout.Table.Primitives.Basic     ( -- * String-related tools       spaces-    , concatLines        -- ** Filling     , fillLeft'@@ -34,9 +33,6 @@  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/Primitives/Table.hs view
@@ -1,5 +1,6 @@ -- | This module provides primitives for generating tables. Tables are generated--- line by line thus the functions in this module produce+-- line by line thus the functions in this module produce 'StringBuilder's that+-- contain a line. module Text.Layout.Table.Primitives.Table where  import           Data.List
table-layout.cabal view
@@ -6,29 +6,30 @@ -- PVP summary:      +-+------- breaking API changes --                   | | +----- non-breaking API additions --                   | | | +--- code changes with no API change-version:             0.9.0.0+version:             0.9.0.1 -synopsis:            Layout text as grid or table.+synopsis:            Format tabular data as grid or table.  description:         -    `table-layout` is a library for text-based table layout. It provides several-    functions and types which help in this task from the ground up. Although,-    using all of them is not necessary. It provides the following layout-    features:+    `table-layout` is a library for text-based table layout and cell formatting+    with the following features:     .-    * Fixed-size and arbitrarily sized columns and limiting versions of those+    * Set a policy for each column to determine the width.     .-    * Positional alignment of content in a column+    * Position content in a column at a certain position.     .-    * Alignment of content within a column at a character occurence+    * Align content in a column at a character occurence.     .-    * Cut marks show that content has been trimmed+    * Highlight trimmed content with cut marks.     .-    * Fancy tables with optional headers and user styles+    * Draw fancy tables with optional headers and user styles.     .-    * Justified text and vertically aligned column layout over multiple rows+    * Automatically justify text and create multi-line table cells.     .-    A small tutorial is provided in the `README.md` file.+    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.  -- URL for the project homepage or repository. homepage:              https://github.com/muesli4/table-layout@@ -88,7 +89,7 @@                        MultiWayIf      -- Other library packages from which modules are imported.-  build-depends:       base >=4.9 && <4.14,+  build-depends:       base >=4.9 && <4.15,                        data-default-class >=0.1.1 && < 0.2,                        data-default-instances-base ==0.1.* @@ -99,7 +100,7 @@  executable table-layout-test-styles   main-is:             Test.hs-  build-depends:       base >=4.9 && <4.14,+  build-depends:       base >=4.9 && <4.15,                        data-default-class >=0.1.1 && < 0.2,                        data-default-instances-base ==0.1.*   hs-source-dirs:      src@@ -134,7 +135,7 @@   type:                exitcode-stdio-1.0   hs-source-dirs:      test-suite, src   main-is:             Spec.hs-  build-depends:       base >=4.9 && <4.14,+  build-depends:       base >=4.9 && <4.15,                        QuickCheck >=2.8 && < 2.14,                        HUnit >=1.3,                        data-default-class >=0.1.1 && < 0.2,
test-suite/TestSpec.hs view
@@ -99,6 +99,9 @@         it "mark left 2" $ apply3 MarkLeftCI 2 "" `shouldBe` "<."         it "mark left 3" $ apply3 MarkLeftCI 4 "a" `shouldBe` "<.. " +        it "uneven mark left" $ applyCutInfo MarkLeftCI unevenCM 5 5 "12345" `shouldBe` "<    "+        it "uneven mark right" $ applyCutInfo MarkRightCI unevenCM 5 5 "12345" `shouldBe` "  -->"+     describe "viewRange" $ do         -- "     :     "         -- "    "@@ -154,6 +157,7 @@         it "justify" $ justify 3 ["not", "now"] `shouldBe` ["not", "now"]   where     customCM = doubleCutMark "<.." "..>"+    unevenCM = doubleCutMark "<" "-->"     occS     = predOccSpec (== ':')      hposG    = elements [left, center, right]