From 6f106c266092d164948f41e9347a4c382eb597aa Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Wed, 17 Jul 2024 20:53:23 -0400 Subject: [PATCH] added brick scaffolding --- app/Main.hs | 7 +++++- hamming.cabal | 8 +++++++ package.yaml | 2 ++ src/Hamming/App.hs | 48 ++++++++++++++++++++++++++++++++++++++++ src/Hamming/App/Types.hs | 48 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 src/Hamming/App.hs create mode 100644 src/Hamming/App/Types.hs diff --git a/app/Main.hs b/app/Main.hs index 8507e77..16fba72 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -21,7 +21,12 @@ License along with this program. If not, see module Main (main) where +import Brick.Main (defaultMain) +import Control.Monad (void) + +import Hamming.App + main :: IO () -main = return () +main = void $ defaultMain mainApp initialState --jl diff --git a/hamming.cabal b/hamming.cabal index a0dfff1..cb55132 100644 --- a/hamming.cabal +++ b/hamming.cabal @@ -22,6 +22,8 @@ extra-source-files: library exposed-modules: Hamming + Hamming.App + Hamming.App.Types other-modules: Paths_hamming autogen-modules: @@ -31,6 +33,8 @@ library ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints build-depends: base >=4.7 && <5 + , brick >=2.1.1 && <2.2 + , mtl >=2.3.1 && <2.4 default-language: Haskell2010 executable hamming @@ -44,7 +48,9 @@ executable hamming ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N build-depends: base >=4.7 && <5 + , brick >=2.1.1 && <2.2 , hamming + , mtl >=2.3.1 && <2.4 default-language: Haskell2010 test-suite hamming-test @@ -61,6 +67,8 @@ test-suite hamming-test ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N build-depends: base >=4.7 && <5 + , brick >=2.1.1 && <2.2 , hamming , hspec >=2.11.9 && <2.12 + , mtl >=2.3.1 && <2.4 default-language: Haskell2010 diff --git a/package.yaml b/package.yaml index 454b2ea..ce19b22 100644 --- a/package.yaml +++ b/package.yaml @@ -20,6 +20,8 @@ description: Please see the README on GitHub at = 4.7 && < 5 +- brick >= 2.1.1 && < 2.2 +- mtl >= 2.3.1 && < 2.4 ghc-options: - -Wall diff --git a/src/Hamming/App.hs b/src/Hamming/App.hs new file mode 100644 index 0000000..70fcaeb --- /dev/null +++ b/src/Hamming/App.hs @@ -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 +. + +|-} + +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 diff --git a/src/Hamming/App/Types.hs b/src/Hamming/App/Types.hs new file mode 100644 index 0000000..188d40a --- /dev/null +++ b/src/Hamming/App/Types.hs @@ -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 +. + +|-} + +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