1 {-# LANGUAGE NoOverloadedLists #-}
2 module Symantic.Compta.View where
4 import Data.String (String)
5 import Data.Semigroup (Semigroup(..))
6 import Prelude (Int, max)
7 import Symantic.Compta.Lang
8 import qualified Data.List as List
9 import Text.Show (Show(..))
10 --import qualified Symantic.Document as Doc
13 table :: [[String]] -> String
14 table cells = List.unlines (List.map show rows)
19 (maxCols, maxWidths, rows) = List.foldr go (0, List.repeat 0, []) cells
21 go :: [String] -> (Int, [Int], [[String]]) -> (Int, [Int], [[String]])
22 go row (accMaxCols, accMaxWidths, accRows) =
23 ( max accMaxCols (List.length row)
24 , List.zipWith max accMaxWidths (List.map List.length row <> List.repeat 0)
25 , List.take maxCols (List.zipWith align row maxWidths) : accRows