pad menu selections to same width
This commit is contained in:
parent
72b6f05700
commit
d6ae171dc8
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user