diff options
| author | Joey Hess <joeyh@debian.org> | 2014-07-09 22:11:31 -0400 |
|---|---|---|
| committer | Joey Hess <joeyh@debian.org> | 2014-07-09 22:11:31 -0400 |
| commit | f118c369d3240b656e4fef77b6efc758b3f714eb (patch) | |
| tree | 0a3e0c6e134680e35665364b2cd6895863bcc990 /src/Utility/Table.hs | |
| parent | 17b21794a72f6cfaddda321d6f2cbdb87ce3dee0 (diff) | |
| parent | 82da31b3e0e9acdfbca4c48eb12ab1f28515ba10 (diff) | |
Record propellor (0.8.1) in archive suite sid
Diffstat (limited to 'src/Utility/Table.hs')
| -rw-r--r-- | src/Utility/Table.hs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/Utility/Table.hs b/src/Utility/Table.hs new file mode 100644 index 00000000..910038e8 --- /dev/null +++ b/src/Utility/Table.hs @@ -0,0 +1,28 @@ +{- text based table generation + - + - Copyright 2014 Joey Hess <joey@kitenet.net> + - + - License: BSD-2-clause + -} + +module Utility.Table where + +type Table = [[String]] + +-- | A table with a header that is set off with lines under each +-- header item. +tableWithHeader :: [String] -> [[String]] -> Table +tableWithHeader header rows = header : map linesep header : rows + where + linesep = map (const '-') + +-- | Formats a table to lines, automatically padding rows to the same size. +formatTable :: Table -> [String] +formatTable table = map (\r -> unwords (map pad (zip r rowsizes))) table + where + pad (cell, size) = cell ++ take (size - length cell) padding + padding = repeat ' ' + rowsizes = sumrows (map (map length) table) + sumrows [] = repeat 0 + sumrows [r] = r + sumrows (r1:r2:rs) = sumrows $ map (uncurry max) (zip r1 r2) : rs |
