Commit | Line | Data |
---|---|---|
967c39ef MM |
1 | module Formatter where |
2 | import Data.List | |
3 | ||
4 | padWith :: a -> Int -> [a] -> [a] | |
5 | padWith _ 0 l = l | |
6 | padWith e n [] = replicate n e | |
7 | padWith e (n+1) (h:t) = h:(padWith e n t) | |
8 | ||
9 | formatTable :: [[String]] -> String | |
10 | formatTable cells = | |
11 | let columnWidths = map (\col -> maximum $ map length col) | |
12 | $ transpose cells in | |
13 | intercalate "\n" $ | |
14 | map (\row -> | |
15 | let rowCells = zipWith (padWith ' ') columnWidths row in | |
16 | intercalate " " rowCells | |
17 | ) cells |