Skip to content

Instantly share code, notes, and snippets.

@thomwiggers
Created October 14, 2012 14:34
Show Gist options
  • Save thomwiggers/3888771 to your computer and use it in GitHub Desktop.
Save thomwiggers/3888771 to your computer and use it in GitHub Desktop.
horz :: AlignV -> [Text] -> Text
horz av ts = Text LeftH av 0 0 (unlines (foldr addList [] (equalizeLists [] mahlines)))
where
mahlines = map (lines . show) ts
maxLenList = maxLength mahlines
equalizeLists list [] = list
equalizeLists list (l:ls)
| length l == maxLenList = equalizeLists (list++l) ls
| av == TopV
= equalizeLists list ((l++[replicate (length (head l)) ' ']):ls)
| av == CenterV && (length l + 2) <= maxLenList
= equalizeLists list (([replicate (length (head l)) ' '] ++ l
++[replicate (length (head l)) ' ']):ls)
| av == CenterV
= equalizeLists list ((l++[replicate (length (head l)) ' ']):ls)
| av == BottomV
= equalizeLists list (([replicate (length (head l)) ' ']++l):ls)
addList :: [[a]] -> [[a]] -> [[a]]
addList left right
| length left == length right = addList' left right []
| otherwise = error "list lengths not equal"
where
addList' [] [] acc = acc
addList' [] _ _ = error "not equal len l < r"
addList' _ [] _ = error "not equal len l > r"
addList' (l:eft) (r:ight) acc = addList' eft ight (acc ++ [l++r])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment