packages feed

simple-tabular (empty) → 0.1.0.0

raw patch · 4 files changed

+157/−0 lines, 4 filesdep +basesetup-changed

Dependencies added: base

Files

+ COPYING view
@@ -0,0 +1,25 @@+Copyright © 2011 Bart Massey++[This program is licensed under the "MIT License"]++Permission is hereby granted, free of charge, to any person+obtaining a copy of this software and associated+documentation files (the "Software"), to deal in the+Software without restriction, including without limitation+the rights to use, copy, modify, merge, publish, distribute,+sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so,+subject to the following conditions:++The above copyright notice and this permission notice shall+be included in all copies or substantial portions of the+Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY+KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR+PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS+OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR+OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ Text/SimpleTabular.hs view
@@ -0,0 +1,62 @@+-- Copyright © 2011 Bart Massey+-- [This program is licensed under the "MIT License"]+-- Please see the file COPYING in the source+-- distribution of this software for license terms.++-- | Format fields in a tabular fashion. This is not+--   nearly as sophisticated as the "tabular" package+--   on hackage (http://hackage.haskell.org/package/tabular),+--   but may be simpler to use and extend.++module Text.SimpleTabular (tabular)+where++import Data.List++-- | Given a format string whose characters are 'l', 'r' and+--   'c' for left-justified, right-justified and centered+--   columns, and a list of rows, each row consisting of+--   columns of strings to be formatted, emit a+--   properly-formatted matrix. Short rows will be padded to+--   the size of the longest row with empty strings before+--   the data is applied to the format string, at which+--   point the number of columns per row must match.+tabular :: String -> [[String]] -> String+tabular fmt tableau =+  let rawCols = +        transpose $ padRows tableau+        where +          padRows rows =+            map (padRow $ maximum $ map length rows) rows+            where+              padRow l row =+                row ++ replicate (l - length row) ""+      in+  let padCols = +        padCol fmt rawCols+        where+          padCol (c : cs) (col : cols)+            | c `elem` "lrc" =+              let w = maximum $ map length col+                  cols' = padCol cs cols+                  in+              let Just padf = +                    lookup c [+                      ('l', padLeft),+                      ('r', padRight),+                      ('c', padCenter) ]+                    where+                      padLeft s = +                        s ++ replicate (w - length s) ' '+                      padRight s = +                        replicate (w - length s) ' ' ++ s+                      padCenter s =+                        let dw = w - length s in+                        let hdw = dw `div` 2 in+                        replicate hdw ' ' ++ s ++ replicate (dw - hdw) ' '+                  in+              map padf col : cols'+          padCol "" [] = []+          padCol _ _ = error "tabular data error"+      in+   unlines $ map unwords $ transpose padCols
+ simple-tabular.cabal view
@@ -0,0 +1,68 @@+-- Initial simple-tabular.cabal generated by cabal init.  For further +-- documentation, see http://haskell.org/cabal/users-guide/++-- The name of the package.+name:                simple-tabular++-- The package version.  See the Haskell package versioning policy (PVP) +-- for standards guiding when and how versions should be incremented.+-- http://www.haskell.org/haskellwiki/Package_versioning_policy+-- PVP summary:      +-+------- breaking API changes+--                   | | +----- non-breaking API additions+--                   | | | +--- code changes with no API change+version:             0.1.0.0++-- A short (one-line) description of the package.+synopsis:            Simple tabular-text formatter++-- A longer description of the package.+description:         This package has a simplistic formatter+                     that accepts a troff-style column descriptor+                     and a list of lists of strings, and produces+                     a string consisting of a formatted table.++-- URL for the project homepage or repository.+homepage:            http://github.com/BartMassey/simple-tabular++-- The license under which the package is released.+license:             MIT++-- The file containing the license text.+license-file:        COPYING++-- The package author(s).+author:              Bart Massey++-- An email address to which users can send suggestions, bug reports, and +-- patches.+maintainer:          bart@cs.pdx.edu++-- A copyright notice.+-- copyright:           ++category:            Text++build-type:          Simple++-- Constraint on the version of Cabal needed to build this package.+cabal-version:       >=1.8++source-repository head+    type:            git+    location:        http://github.com/BartMassey/simple-tabular.git++source-repository this+    type:            git+    location:        http://github.com/BartMassey/simple-tabular.git+    tag:             v0.1++library+  -- Modules exported by the library.+  exposed-modules:     Text.SimpleTabular+  +  -- Modules included in this library but not exported.+  -- other-modules:       +  +  -- Other library packages from which modules are imported.+  build-depends:       base ==4.5.*+