From 4ea2185243c85a6e1925b0a5501163b20b65bcbe Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Sat, 20 Jul 2024 20:57:31 -0400 Subject: [PATCH] broke event handler off into `Hamming.App.Events` and added more types --- hamming.cabal | 1 + src/Hamming/App.hs | 9 ++------- src/Hamming/App/Events.hs | 37 +++++++++++++++++++++++++++++++++++++ src/Hamming/App/Types.hs | 18 ++++++++++++++++-- 4 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 src/Hamming/App/Events.hs diff --git a/hamming.cabal b/hamming.cabal index ce11308..709194e 100644 --- a/hamming.cabal +++ b/hamming.cabal @@ -24,6 +24,7 @@ library Hamming Hamming.App Hamming.App.Draw + Hamming.App.Events Hamming.App.Types Hamming.App.Widgets Hamming.App.Widgets.Internal diff --git a/src/Hamming/App.hs b/src/Hamming/App.hs index c7dc80e..d5d25e5 100644 --- a/src/Hamming/App.hs +++ b/src/Hamming/App.hs @@ -27,11 +27,11 @@ License along with this program. If not, see module Hamming.App (mainApp, initialState) where import Brick.AttrMap (forceAttrMap) -import Brick.Main (App (..), halt, neverShowCursor) -import Brick.Types (BrickEvent, EventM) +import Brick.Main (App (..), neverShowCursor) import Brick.Util (style) import Hamming.App.Draw +import Hamming.App.Events import Hamming.App.Types mainApp :: App AppState () ResName @@ -43,9 +43,4 @@ mainApp = App , appAttrMap = const $ forceAttrMap $ style 0 } -eventHandler - :: BrickEvent ResName () - -> EventM ResName AppState () -eventHandler = const halt - --jl diff --git a/src/Hamming/App/Events.hs b/src/Hamming/App/Events.hs new file mode 100644 index 0000000..1763423 --- /dev/null +++ b/src/Hamming/App/Events.hs @@ -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 +. + +|-} + +module Hamming.App.Events (eventHandler) where + +import Brick.Main (halt) + +import Hamming.App.Types + +-- | Handles an event +eventHandler :: Handler +eventHandler = const halt + +--jl diff --git a/src/Hamming/App/Types.hs b/src/Hamming/App/Types.hs index d34ded7..267cf8a 100644 --- a/src/Hamming/App/Types.hs +++ b/src/Hamming/App/Types.hs @@ -27,16 +27,20 @@ License along with this program. If not, see {-# LANGUAGE TemplateHaskell #-} module Hamming.App.Types ( - -- * Application State + -- * AppState AppState (..), -- ** Lenses hammingCode, - -- * Resource Name + -- * Other Types ResName, + Event, + Action, + Handler, -- * Constructors initialState, ) where +import Brick.Types (BrickEvent, EventM) import Data.Word (Word16) import Lens.Micro.TH (makeLenses) @@ -45,8 +49,18 @@ data AppState = AppState { _hammingCode :: Word16 } +-- | Identifies a resource 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 -- | Initial application state