Add resizeOrQuit for easy simple event handling

This commit is contained in:
Jonathan Daugherty 2015-06-28 22:38:35 -07:00
parent 52bf9ec288
commit 2e3bef7f8e
2 changed files with 10 additions and 5 deletions

View File

@ -26,7 +26,7 @@ theMap = attrMap defAttr
app :: App () Event
app =
App { appDraw = const [ui]
, appHandleEvent = const halt
, appHandleEvent = resizeOrQuit
, appAttrMap = const theMap
, appChooseCursor = neverShowCursor
, appMakeVtyEvent = id

View File

@ -3,6 +3,7 @@ module Brick.Main
, defaultMain
, customMain
, simpleMain
, resizeOrQuit
, EventM
, Next
@ -71,15 +72,19 @@ defaultMain app st = do
simpleMain :: Widget -> IO ()
simpleMain w =
let app = App { appDraw = const [w]
, appHandleEvent = \e st -> case e of
EvResize _ _ -> continue st
_ -> halt st
, appAttrMap = const $ attrMap def []
, appHandleEvent = resizeOrQuit
, appAttrMap = def
, appMakeVtyEvent = id
, appChooseCursor = neverShowCursor
}
in defaultMain app ()
resizeOrQuit :: Event -> a -> EventM (Next a)
resizeOrQuit e a =
case e of
EvResize _ _ -> continue a
_ -> halt a
data InternalNext a = InternalSuspendAndResume RenderState (IO a)
| InternalHalt a