added brick framework

This commit is contained in:
Jonathan Lamothe 2024-08-21 16:56:36 -04:00
parent f02aa25bb9
commit eed428e7ba
5 changed files with 132 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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:

59
src/Abacus/App.hs Normal file
View File

@ -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
<https://www.gnu.org/licenses/>.
-}
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

60
src/Abacus/App/Types.hs Normal file
View File

@ -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
<https://www.gnu.org/licenses/>.
-}
{-# 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