enable code corrections

This commit is contained in:
Jonathan Lamothe 2024-08-07 16:43:36 -04:00
parent 3661ae559a
commit 1a085ca16b
3 changed files with 10 additions and 0 deletions

View File

@ -41,6 +41,7 @@ library
base >=4.7 && <5
, brick >=2.1.1 && <2.2
, microlens >=0.4.13.1 && <0.5
, microlens-mtl >=0.2.0.3 && <0.3
, microlens-th >=0.4.3.15 && <0.5
, mtl >=2.3.1 && <2.4
, vty ==6.1.*
@ -60,6 +61,7 @@ executable hamming
, brick >=2.1.1 && <2.2
, hamming
, microlens >=0.4.13.1 && <0.5
, microlens-mtl >=0.2.0.3 && <0.3
, microlens-th >=0.4.3.15 && <0.5
, mtl >=2.3.1 && <2.4
, vty ==6.1.*
@ -88,6 +90,7 @@ test-suite hamming-test
, hamming
, hspec >=2.11.9 && <2.12
, microlens >=0.4.13.1 && <0.5
, microlens-mtl >=0.2.0.3 && <0.3
, microlens-th >=0.4.3.15 && <0.5
, mtl >=2.3.1 && <2.4
, vty ==6.1.*

View File

@ -22,6 +22,7 @@ dependencies:
- base >= 4.7 && < 5
- brick >= 2.1.1 && < 2.2
- microlens >= 0.4.13.1 && < 0.5
- microlens-mtl >= 0.2.0.3 && < 0.3
- microlens-th >= 0.4.3.15 && < 0.5
- mtl >= 2.3.1 && < 2.4
- vty >= 6.1 && < 6.2

View File

@ -30,12 +30,14 @@ module Hamming.App.Events (eventHandler) where
import Brick.Main (halt)
import Brick.Types (BrickEvent (VtyEvent), gets, modify)
import Control.Monad.State.Class (put)
import Graphics.Vty.Input.Events
( Event (EvKey)
, Key (..)
, Modifier (MCtrl)
)
import Lens.Micro ((^.), (.~), (%~))
import Lens.Micro.Mtl (zoom)
import Hamming
import Hamming.App.Actions
@ -46,6 +48,10 @@ eventHandler :: Handler
eventHandler (VtyEvent (EvKey (KChar 'c') [MCtrl])) = halt
eventHandler (VtyEvent (EvKey (KChar 'c') [])) =
modify $ hammingCode %~ setCheckBits
eventHandler (VtyEvent (EvKey (KChar 'v') [])) =
zoom hammingCode $ gets correctErrors >>= \case
Just c -> put c
Nothing -> return ()
eventHandler e = gets (^.appMode) >>= \case
DisplayMode -> displayHandler e
EditMode _ -> editHandler e