From eed428e7bacc1447b0792bbf8c316a5070842dc9 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Wed, 21 Aug 2024 16:56:36 -0400 Subject: [PATCH] added `brick` framework --- abacus.cabal | 5 ++++ app/Main.hs | 8 +++++- package.yaml | 1 + src/Abacus/App.hs | 59 ++++++++++++++++++++++++++++++++++++++++ src/Abacus/App/Types.hs | 60 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 src/Abacus/App.hs create mode 100644 src/Abacus/App/Types.hs diff --git a/abacus.cabal b/abacus.cabal index 7d38211..3559688 100644 --- a/abacus.cabal +++ b/abacus.cabal @@ -20,6 +20,8 @@ extra-source-files: library exposed-modules: Abacus + Abacus.App + Abacus.App.Types Abacus.Internal other-modules: Paths_abacus @@ -30,6 +32,7 @@ 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 , microlens-platform >=0.4.3.5 && <0.5 default-language: Haskell2010 @@ -45,6 +48,7 @@ executable abacus build-depends: abacus , base >=4.7 && <5 + , brick >=2.1.1 && <2.2 , microlens-platform >=0.4.3.5 && <0.5 default-language: Haskell2010 @@ -62,6 +66,7 @@ test-suite abacus-test build-depends: abacus , base >=4.7 && <5 + , brick >=2.1.1 && <2.2 , hspec >=2.11.9 && <2.12 , microlens-platform >=0.4.3.5 && <0.5 default-language: Haskell2010 diff --git a/app/Main.hs b/app/Main.hs index a9b6b08..faa4273 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -21,7 +21,13 @@ License along with this program. If not, see module Main (main) where +import Brick (defaultMain) +import Control.Monad (void) + +import Abacus.App +import Abacus.App.Types + main :: IO () -main = return () +main = void $ defaultMain mainApp initialState --jl diff --git a/package.yaml b/package.yaml index bc226e0..cc8ae38 100644 --- a/package.yaml +++ b/package.yaml @@ -20,6 +20,7 @@ description: Please see README.md dependencies: - base >= 4.7 && < 5 +- brick >= 2.1.1 && < 2.2 - microlens-platform >= 0.4.3.5 && < 0.5 ghc-options: diff --git a/src/Abacus/App.hs b/src/Abacus/App.hs new file mode 100644 index 0000000..cda3f48 --- /dev/null +++ b/src/Abacus/App.hs @@ -0,0 +1,59 @@ +{-| + +Module : Abacus.App +Description : Applicaiton framework +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 Abacus.App (mainApp) where + +import Brick + ( App (..) + , BrickEvent + , EventM + , Widget + , attrMap + , emptyWidget + , halt + , neverShowCursor + , style + ) + +import Abacus.App.Types + +-- | Main application +mainApp :: App AppState () () +mainApp = App + { appDraw = drawFunc + , appChooseCursor = neverShowCursor + , appHandleEvent = eventHandler + , appStartEvent = return () + , appAttrMap = const $ attrMap (style 0) [] + } + +drawFunc :: AppState -> [Widget ()] +drawFunc = const [emptyWidget] + +eventHandler :: BrickEvent () () -> EventM () AppState () +eventHandler = const halt + +--jl diff --git a/src/Abacus/App/Types.hs b/src/Abacus/App/Types.hs new file mode 100644 index 0000000..52c0dfd --- /dev/null +++ b/src/Abacus/App/Types.hs @@ -0,0 +1,60 @@ +{-| + +Module : Abacus.App.Types +Description : Applicaiton types for applicaiton UI +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 +. + +-} + +{-# LANGUAGE TemplateHaskell #-} + +module Abacus.App.Types ( + AppState (..), + -- * Lenses + abacus, + rungNum, + -- * Constructor + initialState, + ) where + +import Data.Maybe (fromJust) +import Lens.Micro.Platform (makeLenses) + +import Abacus + +-- | Main applicaiton state +data AppState = AppState + { _abacus :: Abacus + -- ^ The abacus data + , _rungNum :: Int + -- ^ The selected rung number + } deriving (Eq, Show) + +makeLenses ''AppState + +-- | Initial application state +initialState :: AppState +initialState = AppState + { _abacus = fromJust $ newAbacus 10 10 + , _rungNum = 0 + } + +--jl