toggle between display/edit modes

This commit is contained in:
Jonathan Lamothe 2024-07-31 20:01:47 -04:00
parent cc6afa222d
commit 417a8691e8

View File

@ -24,15 +24,18 @@ License along with this program. If not, see
|-}
{-# LANGUAGE LambdaCase #-}
module Hamming.App.Events (eventHandler) where
import Brick.Main (halt)
import Brick.Types (BrickEvent (VtyEvent))
import Brick.Types (BrickEvent (VtyEvent), gets, modify)
import Graphics.Vty.Input.Events
( Event (EvKey)
, Key (KChar)
, Key (KChar, KEsc)
, Modifier (MCtrl)
)
import Lens.Micro ((^.), (.~))
import Hamming.App.Types
@ -40,6 +43,18 @@ import Hamming.App.Types
eventHandler :: Handler
eventHandler (VtyEvent (EvKey (KChar 'c') [MCtrl])) = halt
eventHandler (VtyEvent (EvKey (KChar 'q') [])) = halt
eventHandler _ = return ()
eventHandler e = gets (^.appMode) >>= \case
DisplayMode -> displayHandler e
EditMode _ -> editHandler e
displayHandler :: Handler
displayHandler (VtyEvent (EvKey (KChar 'e') [])) =
modify $ appMode .~ EditMode initialEditor
displayHandler _ = return ()
editHandler :: Handler
editHandler (VtyEvent (EvKey KEsc [])) =
modify $ appMode .~ DisplayMode
editHandler _ = return ()
--jl