diff options
| author | Joey Hess <joeyh@joeyh.name> | 2015-01-25 15:16:58 -0400 |
|---|---|---|
| committer | Joey Hess <joeyh@joeyh.name> | 2015-01-25 15:16:58 -0400 |
| commit | 401b857eef13ca7d3f7b8f6b88e9237884fcd906 (patch) | |
| tree | eb4b5c189349b5a86b3b39edbe039956d3a1a3b8 /src/Utility/Table.hs | |
| parent | 1df70ba81ddfbd4ceeb5344793f7714a35706c8f (diff) | |
| parent | cdd88b080af534231aae8a64ef327f0597a5b5b3 (diff) | |
Merge branch 'joeyconfig'
Conflicts:
doc/todo/info_propigation_out_of_nested_properties.mdwn
privdata.joey/privdata.gpg
Diffstat (limited to 'src/Utility/Table.hs')
| -rw-r--r-- | src/Utility/Table.hs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/Utility/Table.hs b/src/Utility/Table.hs index 4e862ff6..20adf40d 100644 --- a/src/Utility/Table.hs +++ b/src/Utility/Table.hs @@ -16,13 +16,14 @@ tableWithHeader header rows = header : map linesep header : rows where linesep = map (const '-') --- | Formats a table to lines, automatically padding rows to the same size. +-- | Formats a table to lines, automatically padding columns to the same size. formatTable :: Table -> [String] -formatTable table = map (\r -> unwords (map pad (zip r rowsizes))) table +formatTable table = map (\r -> unwords (map pad (zip r colsizes))) 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 + colsizes = reverse $ (0:) $ drop 1 $ reverse $ + sumcols (map (map length) table) + sumcols [] = repeat 0 + sumcols [r] = r + sumcols (r1:r2:rs) = sumcols $ map (uncurry max) (zip r1 r2) : rs |
