mirror of
https://github.com/jtdaugherty/brick.git
synced 2024-09-11 15:55:54 +03:00
API: handleEvent now runs in EventM
This commit is contained in:
parent
736a81de97
commit
0f84d19cdf
@ -31,7 +31,7 @@ appEvent d ev =
|
||||
case ev of
|
||||
V.EvKey V.KEsc [] -> M.halt d
|
||||
V.EvKey V.KEnter [] -> M.halt d
|
||||
_ -> M.continue $ T.handleEvent ev d
|
||||
_ -> M.continue =<< T.handleEvent ev d
|
||||
|
||||
initialState :: D.Dialog Choice
|
||||
initialState = D.dialog "dialog" (Just "Title") (Just (0, choices)) 50
|
||||
|
@ -61,7 +61,9 @@ appEvent st ev =
|
||||
case ev of
|
||||
V.EvKey V.KEsc [] -> M.halt st
|
||||
V.EvKey (V.KChar '\t') [] -> M.continue $ switchEditors st
|
||||
_ -> M.continue $ st & currentEditorL st %~ T.handleEvent ev
|
||||
_ -> do
|
||||
e <- T.handleEvent ev (st ^. currentEditorL st)
|
||||
M.continue $ st & currentEditorL st .~ e
|
||||
|
||||
initialState :: St
|
||||
initialState =
|
||||
|
@ -58,7 +58,7 @@ appEvent l e =
|
||||
|
||||
V.EvKey V.KEsc [] -> M.halt l
|
||||
|
||||
ev -> M.continue $ T.handleEvent ev l
|
||||
ev -> M.continue =<< T.handleEvent ev l
|
||||
|
||||
listDrawElement :: Bool -> Int -> Widget
|
||||
listDrawElement sel i =
|
||||
|
@ -69,7 +69,7 @@ data Padding = Pad Int
|
||||
-- | The class of types that provide some basic event-handling.
|
||||
class HandleEvent a where
|
||||
-- | Handle a Vty event
|
||||
handleEvent :: Event -> a -> a
|
||||
handleEvent :: Event -> a -> EventM a
|
||||
|
||||
-- | The monad in which event handlers run.
|
||||
type EventM a = StateT EventState IO a
|
||||
|
@ -68,9 +68,9 @@ suffixLenses ''Dialog
|
||||
instance HandleEvent (Dialog a) where
|
||||
handleEvent ev d =
|
||||
case ev of
|
||||
EvKey (KChar '\t') [] -> nextButtonBy 1 d
|
||||
EvKey KBackTab [] -> nextButtonBy (-1) d
|
||||
_ -> d
|
||||
EvKey (KChar '\t') [] -> return $ nextButtonBy 1 d
|
||||
EvKey KBackTab [] -> return $ nextButtonBy (-1) d
|
||||
_ -> return d
|
||||
|
||||
-- | Create a dialog.
|
||||
dialog :: Name
|
||||
|
@ -72,7 +72,7 @@ instance HandleEvent Editor where
|
||||
EvKey KRight [] -> Z.moveRight
|
||||
EvKey KBS [] -> Z.deletePrevChar
|
||||
_ -> id
|
||||
in applyEdit f ed
|
||||
in return $ applyEdit f ed
|
||||
|
||||
-- | Construct an editor.
|
||||
editor :: Name
|
||||
|
@ -59,7 +59,7 @@ data List e =
|
||||
suffixLenses ''List
|
||||
|
||||
instance HandleEvent (List e) where
|
||||
handleEvent e theList = f theList
|
||||
handleEvent e theList = return $ f theList
|
||||
where
|
||||
f = case e of
|
||||
EvKey KUp [] -> listMoveUp
|
||||
|
Loading…
Reference in New Issue
Block a user