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 ((^.))
|
||||||
import Lens.Micro.TH (makeLenses)
|
import Lens.Micro.TH (makeLenses)
|
||||||
|
|
||||||
|
import Mtlstats.Format
|
||||||
import Mtlstats.Types
|
import Mtlstats.Types
|
||||||
|
|
||||||
-- | Defines a menu
|
-- | Defines a menu
|
||||||
|
@ -65,8 +66,15 @@ makeLenses ''Menu
|
||||||
makeLenses ''MenuItem
|
makeLenses ''MenuItem
|
||||||
|
|
||||||
instance Show (Menu a) where
|
instance Show (Menu a) where
|
||||||
show m = m ^. menuTitle ++ "\n\n" ++ items
|
show m = unlines
|
||||||
where items = unlines $ map show $ m ^. menuItems
|
$ [ m^.menuTitle
|
||||||
|
, ""
|
||||||
|
]
|
||||||
|
++ body
|
||||||
|
where
|
||||||
|
body = map (left width) items
|
||||||
|
width = maximum $ map length items
|
||||||
|
items = map show $ m^.menuItems
|
||||||
|
|
||||||
instance Show (MenuItem a) where
|
instance Show (MenuItem a) where
|
||||||
show i = [i ^. miKey] ++ ": " ++ i ^. miDescription
|
show i = [i ^. miKey] ++ ": " ++ i ^. miDescription
|
||||||
|
|
|
@ -37,11 +37,11 @@ showSpec :: Spec
|
||||||
showSpec = describe "show" $
|
showSpec = describe "show" $
|
||||||
it "should display correctly" $ let
|
it "should display correctly" $ let
|
||||||
menu = Menu "Foo" ()
|
menu = Menu "Foo" ()
|
||||||
[ MenuItem '1' "Item 1" $ return ()
|
[ MenuItem '1' "foo" $ return ()
|
||||||
, MenuItem '2' "Item 2" $ return ()
|
, MenuItem '2' "bar baz" $ return ()
|
||||||
]
|
]
|
||||||
expected =
|
expected =
|
||||||
"Foo\n\n\
|
"Foo\n\n\
|
||||||
\1: Item 1\n\
|
\1: foo \n\
|
||||||
\2: Item 2\n"
|
\2: bar baz\n"
|
||||||
in show menu `shouldBe` expected
|
in show menu `shouldBe` expected
|
||||||
|
|
Loading…
Reference in New Issue
Block a user