added brick framework

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

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