make use of .= and %= operators

This commit is contained in:
Jonathan Lamothe 2024-08-09 15:00:57 -04:00
parent 4e5c07a070
commit ee6e2cb8e6

View File

@ -36,8 +36,8 @@ import Graphics.Vty.Input.Events
, Key (..)
, Modifier (MCtrl)
)
import Lens.Micro ((^.), (.~), (%~))
import Lens.Micro.Mtl (zoom)
import Lens.Micro ((^.))
import Lens.Micro.Mtl (zoom, (.=), (%=))
import Hamming
import Hamming.App.Actions
@ -48,7 +48,7 @@ eventHandler :: Handler
eventHandler (VtyEvent (EvKey (KChar 'c') [MCtrl])) = halt
eventHandler (VtyEvent (EvKey (KChar 'q') [])) = halt
eventHandler (VtyEvent (EvKey (KChar 'c') [])) =
modify $ hammingCode %~ setCheckBits
hammingCode %= setCheckBits
eventHandler (VtyEvent (EvKey (KChar 'v') [])) =
zoom hammingCode $ gets correctErrors >>= \case
Just c -> put c
@ -59,28 +59,28 @@ eventHandler e = gets (^.appMode) >>= \case
displayHandler :: Handler
displayHandler (VtyEvent (EvKey (KChar 'e') [])) =
modify $ appMode .~ EditMode initialEditor
appMode .= EditMode initialEditor
displayHandler _ = return ()
editHandler :: Handler
editHandler (VtyEvent (EvKey KEsc [])) =
modify $ appMode .~ DisplayMode
appMode .= DisplayMode
editHandler (VtyEvent (EvKey KUp [])) =
modify $ appMode.editState %~ moveUp
appMode.editState %= moveUp
editHandler (VtyEvent (EvKey (KChar 'k') [])) =
modify $ appMode.editState %~ moveUp
appMode.editState %= moveUp
editHandler (VtyEvent (EvKey KDown [])) =
modify $ appMode.editState %~ moveDown
appMode.editState %= moveDown
editHandler (VtyEvent (EvKey (KChar 'j') [])) =
modify $ appMode.editState %~ moveDown
appMode.editState %= moveDown
editHandler (VtyEvent (EvKey KLeft [])) =
modify $ appMode.editState %~ moveLeft
appMode.editState %= moveLeft
editHandler (VtyEvent (EvKey (KChar 'h') [])) =
modify $ appMode.editState %~ moveLeft
appMode.editState %= moveLeft
editHandler (VtyEvent (EvKey KRight [])) =
modify $ appMode.editState %~ moveRight
appMode.editState %= moveRight
editHandler (VtyEvent (EvKey (KChar 'l') [])) =
modify $ appMode.editState %~ moveRight
appMode.editState %= moveRight
editHandler (VtyEvent (EvKey (KChar 'f') [])) =
modify flipBit
editHandler _ = return ()