parent
95d1cc62ea
commit
ee7135dbfd
|
@ -16,14 +16,14 @@ tableWithHeader header rows = header : map linesep header : rows
|
||||||
where
|
where
|
||||||
linesep = map (const '-')
|
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 -> [String]
|
||||||
formatTable table = map (\r -> unwords (map pad (zip r rowsizes))) table
|
formatTable table = map (\r -> unwords (map pad (zip r colsizes))) table
|
||||||
where
|
where
|
||||||
pad (cell, size) = cell ++ take (size - length cell) padding
|
pad (cell, size) = cell ++ take (size - length cell) padding
|
||||||
padding = repeat ' '
|
padding = repeat ' '
|
||||||
rowsizes = reverse $ (0:) $ drop 1 $ reverse $
|
colsizes = reverse $ (0:) $ drop 1 $ reverse $
|
||||||
sumrows (map (map length) table)
|
sumcols (map (map length) table)
|
||||||
sumrows [] = repeat 0
|
sumcols [] = repeat 0
|
||||||
sumrows [r] = r
|
sumcols [r] = r
|
||||||
sumrows (r1:r2:rs) = sumrows $ map (uncurry max) (zip r1 r2) : rs
|
sumcols (r1:r2:rs) = sumcols $ map (uncurry max) (zip r1 r2) : rs
|
||||||
|
|
Loading…
Reference in New Issue