|
data FieldInput a b n = |
|
FieldInput |
|
{ inputState :: b -- ^ The state of the input field (what's rendered in the screen) |
|
, inputValidator :: b -> Either ErrorMessage a -- ^ A validator function |
|
, inputHelp :: HelpMessage -- ^ The input helpMessage |
|
, inputRender :: Bool |
|
-> ErrorStatus |
|
-> HelpMessage |
|
-> Label |
|
-> b |
|
-> (Widget n -> Widget n) |
|
-> (Widget n, Maybe (Widget n)) -- ^ How to draw the input and optionally an overlay, with focus a help message and input. |
|
-- A extension function can be applied too |
|
, inputHandler :: BrickEvent n () -> EventM n b () -- ^ The handler |
|
} |
|
|
|
makeLensesFor |
|
[ ("inputState", "inputStateL") |
|
, ("inputValidator", "inputValidatorL") |
|
, ("inputName", "inputNameL") |
|
, ("inputHelp", "inputHelpL") |
|
] |
|
''FieldInput |
|
|
|
-- | The MenuField is an existential type which stores a Lens' to a part of the Menu state. |
|
-- In also contains a Field input which internal state is hidden |
|
data MenuField s n where |
|
MenuField :: |
|
{ fieldAccesor :: Lens' s a -- ^ A Lens pointing to some part of the state |
|
, fieldInput :: FieldInput a b n -- ^ The input which modifies the state |
|
, fieldLabel :: Label -- ^ The label |
|
, fieldStatus :: ErrorStatus -- ^ Whether the current is valid or not. |
|
, fieldName :: n |
|
} -> MenuField s n |
|
|
|
isValidField :: MenuField s n -> Bool |
|
isValidField = (== Valid) . fieldStatus |
|
|
|
makeLensesFor |
|
[ ("fieldLabel", "fieldLabelL") |
|
, ("fieldStatus", "fieldStatusL") |
|
] |
|
''MenuField |
ghcup-hs/lib-tui/GHCup/Brick/Widgets/Menu.hs
Lines 111 to 153 in d94ce2a
These types must go. It's impossible to derive or write a lens for
fieldInput.