broke event handler off into Hamming.App.Events and added more types

This commit is contained in:
Jonathan Lamothe 2024-07-20 20:57:31 -04:00
parent 3e742cb6e7
commit 4ea2185243
4 changed files with 56 additions and 9 deletions

View File

@ -24,6 +24,7 @@ library
Hamming Hamming
Hamming.App Hamming.App
Hamming.App.Draw Hamming.App.Draw
Hamming.App.Events
Hamming.App.Types Hamming.App.Types
Hamming.App.Widgets Hamming.App.Widgets
Hamming.App.Widgets.Internal Hamming.App.Widgets.Internal

View File

@ -27,11 +27,11 @@ License along with this program. If not, see
module Hamming.App (mainApp, initialState) where module Hamming.App (mainApp, initialState) where
import Brick.AttrMap (forceAttrMap) import Brick.AttrMap (forceAttrMap)
import Brick.Main (App (..), halt, neverShowCursor) import Brick.Main (App (..), neverShowCursor)
import Brick.Types (BrickEvent, EventM)
import Brick.Util (style) import Brick.Util (style)
import Hamming.App.Draw import Hamming.App.Draw
import Hamming.App.Events
import Hamming.App.Types import Hamming.App.Types
mainApp :: App AppState () ResName mainApp :: App AppState () ResName
@ -43,9 +43,4 @@ mainApp = App
, appAttrMap = const $ forceAttrMap $ style 0 , appAttrMap = const $ forceAttrMap $ style 0
} }
eventHandler
:: BrickEvent ResName ()
-> EventM ResName AppState ()
eventHandler = const halt
--jl --jl

37
src/Hamming/App/Events.hs Normal file
View File

@ -0,0 +1,37 @@
{-|
Module : Hamming.App.Events
Description : Utilities for working with Hamming codes
Copyright : (C) Jonathan Lamothe
License : AGPL-3.0-or-later
Maintainer : jonathan@jlamothe.net
Stability : experimental
Portability : POSIX
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public
License along with this program. If not, see
<https://www.gnu.org/licenses/>.
|-}
module Hamming.App.Events (eventHandler) where
import Brick.Main (halt)
import Hamming.App.Types
-- | Handles an event
eventHandler :: Handler
eventHandler = const halt
--jl

View File

@ -27,16 +27,20 @@ License along with this program. If not, see
{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TemplateHaskell #-}
module Hamming.App.Types ( module Hamming.App.Types (
-- * Application State -- * AppState
AppState (..), AppState (..),
-- ** Lenses -- ** Lenses
hammingCode, hammingCode,
-- * Resource Name -- * Other Types
ResName, ResName,
Event,
Action,
Handler,
-- * Constructors -- * Constructors
initialState, initialState,
) where ) where
import Brick.Types (BrickEvent, EventM)
import Data.Word (Word16) import Data.Word (Word16)
import Lens.Micro.TH (makeLenses) import Lens.Micro.TH (makeLenses)
@ -45,8 +49,18 @@ data AppState = AppState
{ _hammingCode :: Word16 { _hammingCode :: Word16
} }
-- | Identifies a resource
type ResName = () type ResName = ()
-- | An application event
type Event = BrickEvent ResName ()
-- | Performs an action within the application
type Action a = EventM ResName AppState a
-- | Event handler
type Handler = Event -> Action ()
makeLenses ''AppState makeLenses ''AppState
-- | Initial application state -- | Initial application state