FormDemo: add radio button example

This commit is contained in:
Jonathan Daugherty 2017-12-26 19:58:20 -08:00
parent 0654305a44
commit 81727f46ce

View File

@ -16,12 +16,15 @@ import Brick.Widgets.Center
data Name = Edit1 data Name = Edit1
| Edit2 | Edit2
| Password | Password
| YesRadio
| NoRadio
deriving (Eq, Ord, Show) deriving (Eq, Ord, Show)
data FormState = data FormState =
FormState { _field1 :: Int FormState { _field1 :: Int
, _field2 :: Int , _field2 :: Int
, _fieldPassword :: T.Text , _fieldPassword :: T.Text
, _radio :: Bool
} }
deriving (Show) deriving (Show)
@ -35,6 +38,10 @@ mkForm =
`withHelper` (\w -> str "Edit 2: " <+> w) `withHelper` (\w -> str "Edit 2: " <+> w)
, editPasswordField fieldPassword Password , editPasswordField fieldPassword Password
`withHelper` (\w -> str "Password: " <+> w) `withHelper` (\w -> str "Password: " <+> w)
, radioField radio [ (True, YesRadio, "Yes")
, (False, NoRadio, "No")
]
`withHelper` (\w -> str "Okay? " <+> w)
] ]
theMap :: AttrMap theMap :: AttrMap
@ -42,6 +49,7 @@ theMap = attrMap defAttr
[ (editAttr, white `on` black) [ (editAttr, white `on` black)
, (editFocusedAttr, black `on` yellow) , (editFocusedAttr, black `on` yellow)
, (invalidFormInputAttr, white `on` red) , (invalidFormInputAttr, white `on` red)
, (focusedRadioAttr, black `on` yellow)
] ]
app :: App (Form FormState e Name) e Name app :: App (Form FormState e Name) e Name
@ -60,6 +68,6 @@ app =
main :: IO () main :: IO ()
main = do main = do
let f = mkForm $ FormState 10 20 "" let f = mkForm $ FormState 10 20 "" False
f' <- defaultMain app f f' <- defaultMain app f
print $ formState f' print $ formState f'