added brick scaffolding

This commit is contained in:
2024-07-17 20:53:23 -04:00
parent 8f6acc6b6b
commit 6f106c2660
5 changed files with 112 additions and 1 deletions

48
src/Hamming/App.hs Normal file
View File

@@ -0,0 +1,48 @@
{-|
Module : Hamming.App
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 (mainApp, initialState) where
import Brick.AttrMap (forceAttrMap)
import Brick.Main (App (..), neverShowCursor)
import Brick.Util (style)
import Control.Monad.State.Class (gets)
import Hamming.App.Types
mainApp :: App AppState () ()
mainApp = App
{ appDraw = \s -> drawFunc (router s) s
, appChooseCursor = neverShowCursor
, appHandleEvent = \e -> gets router >>= flip eventHandler e
, appStartEvent = return ()
, appAttrMap = const $ forceAttrMap $ style 0
}
router :: AppState -> Route
router = undefined
--jl

48
src/Hamming/App/Types.hs Normal file
View File

@@ -0,0 +1,48 @@
{-|
Module : Hamming.App.Types
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.Types (AppState (..), Route (..), initialState) where
import Brick.Types (BrickEvent, EventM, Widget)
import Data.Word (Word16)
-- | The main state of the application
data AppState = AppState
{ hammingCode :: Word16
}
-- | Returns appropriate draw function and event handler for the
-- current application state
data Route = Route
{ drawFunc :: AppState -> [Widget ()]
, eventHandler :: BrickEvent () () -> EventM () AppState ()
}
-- | Initial application state
initialState :: AppState
initialState = AppState 0
--jl