API: handleEvent now runs in EventM

This commit is contained in:
Jonathan Daugherty 2015-08-19 19:52:34 -07:00
parent 736a81de97
commit 0f84d19cdf
7 changed files with 11 additions and 9 deletions

View File

@ -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

View File

@ -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 =

View File

@ -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 =

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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