cleaner event handler for FixCodeEvent
This commit is contained in:
parent
1e37c2c47b
commit
44588c691a
|
@ -24,7 +24,7 @@ License along with this program. If not, see
|
||||||
|
|
||||||
|-}
|
|-}
|
||||||
|
|
||||||
{-# LANGUAGE LambdaCase, OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
module Hamming.App.Events (
|
module Hamming.App.Events (
|
||||||
eventHandler,
|
eventHandler,
|
||||||
|
@ -47,7 +47,7 @@ import Brick.Keybindings
|
||||||
, onEvent
|
, onEvent
|
||||||
)
|
)
|
||||||
import Control.Monad (void)
|
import Control.Monad (void)
|
||||||
import Control.Monad.State.Class (get, gets, modify, put)
|
import Control.Monad.State.Class (gets, modify, put)
|
||||||
import Data.Either (fromRight)
|
import Data.Either (fromRight)
|
||||||
import Graphics.Vty.Input.Events
|
import Graphics.Vty.Input.Events
|
||||||
( Event (EvKey)
|
( Event (EvKey)
|
||||||
|
@ -95,10 +95,7 @@ keyEventHandlers =
|
||||||
, onEvent CheckBitsEvent "Set Check Bits" $
|
, onEvent CheckBitsEvent "Set Check Bits" $
|
||||||
hammingCode %= setCheckBits
|
hammingCode %= setCheckBits
|
||||||
, onEvent FixCodeEvent "Attempt to Correct Errors" $
|
, onEvent FixCodeEvent "Attempt to Correct Errors" $
|
||||||
zoom hammingCode $ get >>= \case
|
zoom hammingCode $ gets correctErrors >>= mapM_ put
|
||||||
Nothing -> return ()
|
|
||||||
Just c -> put c
|
|
||||||
. correctErrors
|
|
||||||
, onEvent ResetEvent "Reset Code" $
|
, onEvent ResetEvent "Reset Code" $
|
||||||
hammingCode .= 0
|
hammingCode .= 0
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user