diff --git a/src/Mtlstats/Types/Menu.hs b/src/Mtlstats/Types/Menu.hs index 2de5055..b0cdb31 100644 --- a/src/Mtlstats/Types/Menu.hs +++ b/src/Mtlstats/Types/Menu.hs @@ -39,6 +39,7 @@ module Mtlstats.Types.Menu ( import Lens.Micro ((^.)) import Lens.Micro.TH (makeLenses) +import Mtlstats.Format import Mtlstats.Types -- | Defines a menu @@ -65,8 +66,15 @@ makeLenses ''Menu makeLenses ''MenuItem instance Show (Menu a) where - show m = m ^. menuTitle ++ "\n\n" ++ items - where items = unlines $ map show $ m ^. menuItems + show m = unlines + $ [ m^.menuTitle + , "" + ] + ++ body + where + body = map (left width) items + width = maximum $ map length items + items = map show $ m^.menuItems instance Show (MenuItem a) where show i = [i ^. miKey] ++ ": " ++ i ^. miDescription diff --git a/test/Types/MenuSpec.hs b/test/Types/MenuSpec.hs index 6b95dc4..6247b64 100644 --- a/test/Types/MenuSpec.hs +++ b/test/Types/MenuSpec.hs @@ -37,11 +37,11 @@ showSpec :: Spec showSpec = describe "show" $ it "should display correctly" $ let menu = Menu "Foo" () - [ MenuItem '1' "Item 1" $ return () - , MenuItem '2' "Item 2" $ return () + [ MenuItem '1' "foo" $ return () + , MenuItem '2' "bar baz" $ return () ] expected = "Foo\n\n\ - \1: Item 1\n\ - \2: Item 2\n" + \1: foo \n\ + \2: bar baz\n" in show menu `shouldBe` expected