1module Menu23import Gopher45import Data.Nat6import Data.Strings78-- String used to seperate metadata from primary data in menu entries.9sep : String10sep = " │ "1112-- Returns the maximum amount of characters required to display an entry type.13maxTypeWidth : (List Item) -> Nat14maxTypeWidth = foldr (\(MkItem ty _ _ _), acc => max (length $ show ty) acc) 01516-- Adds spaces as padding to the end of the given String.17padToWidth : String -> Nat -> String18padToWidth str n = if (Strings.length str) >= n19 then str20 else padToWidth (str ++ " ") n2122-- Returns amount of digits required to display number in decimal.23digitsReq : Nat -> Nat24digitsReq n = if n `div` 10 > 025 then 1 + (digitsReq $ n `div` 10)26 else 12728public export29showMenu : (List Item) -> String30showMenu xs = trim $ showMenu' (digitsReq $ length xs) (maxTypeWidth xs) 0 xs31 where32 showItem : Nat -> Item -> String33 showItem max (MkItem ty desc _ _) = (padToWidth (show ty) max) ++ sep ++ desc3435 showMenu' : Nat -> Nat -> Nat -> (List Item) -> String36 showMenu' _ _ _ [] = ""37 showMenu' maxNum maxTy n (x :: xs) = (padToWidth (show n) maxNum) ++38 " " ++ showItem maxTy x ++ "\n" ++39 (showMenu' maxNum maxTy (n + 1) xs)