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