wip: switching from ncurses to brick

This commit is contained in:
2023-05-30 17:49:35 -04:00
parent 458554bef2
commit 227401461b
32 changed files with 400 additions and 446 deletions
+25 -16
View File
@@ -24,7 +24,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
module Mtlstats.Types (
-- * Types
Controller (..),
Renderer,
Action,
Handler,
ProgState (..),
ProgMode (..),
GameState (..),
@@ -52,7 +54,7 @@ module Mtlstats.Types (
progMode,
dbName,
inputBuffer,
scrollOffset,
scroller,
-- ** ProgMode Lenses
gameStateL,
createPlayerStateL,
@@ -195,7 +197,8 @@ module Mtlstats.Types (
gsAverage
) where
import Control.Monad.Trans.State (StateT)
import Brick.Main (ViewportScroll, viewportScroll)
import Brick.Types (BrickEvent, EventM, Widget)
import Data.Aeson
( FromJSON
, ToJSON
@@ -213,22 +216,28 @@ import Data.Aeson
import Data.Char (toUpper)
import Data.List (find, isInfixOf)
import qualified Data.Map as M
import Graphics.Vty.Input.Events (Key, Modifier)
import Lens.Micro (Lens', lens, (&), (^.), (.~))
import Lens.Micro.TH (makeLenses)
import qualified UI.NCurses as C
import Mtlstats.Config
-- | Controls the program flow
data Controller = Controller
{ drawController :: ProgState -> C.Update C.CursorMode
-- ^ The drawing phase
, handleController :: C.Event -> Action Bool
{ drawController :: Renderer
-- ^ The drawing routine
, handleController :: Handler ()
-- ^ The event handler
}
-- | Renders a view based on a "ProgState"
type Renderer = ProgState -> Widget ()
-- | Action which maintains program state
type Action a = StateT ProgState C.Curses a
type Action a = EventM () ProgState a
-- | Handles an event
type Handler a = BrickEvent () () -> Action a
-- | Represents the program state
data ProgState = ProgState
@@ -240,8 +249,8 @@ data ProgState = ProgState
-- ^ The name of the database file
, _inputBuffer :: String
-- ^ Buffer for user input
, _scrollOffset :: Int
-- ^ The scrolling offset for the display
, _scroller :: ViewportScroll ()
-- ^ Scroller for the reports
}
-- | The program mode
@@ -532,13 +541,13 @@ data GameStats = GameStats
-- | Defines a user prompt
data Prompt = Prompt
{ promptDrawer :: ProgState -> C.Update ()
{ drawPrompt :: ProgState -> Widget ()
-- ^ Draws the prompt to the screen
, promptProcessChar :: Char -> String -> String
-- ^ Modifies the string based on the character entered
, promptAction :: String -> Action ()
-- ^ Action to perform when the value is entered
, promptSpecialKey :: C.Key -> Action ()
, promptSpecialKey :: Key -> [Modifier] -> Action ()
-- ^ Action to perform when a special key is pressed
}
@@ -786,11 +795,11 @@ esmSubModeL = lens
-- | Constructor for a 'ProgState'
newProgState :: ProgState
newProgState = ProgState
{ _database = newDatabase
, _progMode = TitleScreen
, _dbName = ""
, _inputBuffer = ""
, _scrollOffset = 0
{ _database = newDatabase
, _progMode = TitleScreen
, _dbName = ""
, _inputBuffer = ""
, _scroller = viewportScroll ()
}
-- | Constructor for a 'GameState'