implemented editStateL

This commit is contained in:
2024-07-26 20:35:54 -04:00
parent e20dda8c9f
commit 408e0f0f82
5 changed files with 121 additions and 4 deletions
+18 -3
View File
@@ -24,7 +24,7 @@ License along with this program. If not, see
|-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE LambdaCase, TemplateHaskell #-}
module Hamming.App.Types (
-- * Application state data
@@ -35,6 +35,8 @@ module Hamming.App.Types (
hammingCode,
-- ** AppMode
AppMode (..),
-- *** Lenses
editStateL,
-- ** EditState,
EditState (..),
-- *** Lenses
@@ -52,18 +54,20 @@ module Hamming.App.Types (
import Brick.Types (BrickEvent, EventM)
import Data.Word (Word16)
import Lens.Micro (Lens', lens)
import Lens.Micro.TH (makeLenses)
-- | The main state of the application
data AppState = AppState
{ _appMode :: AppMode
, _hammingCode :: Word16
}
} deriving (Eq, Show)
-- | The application's main mode
data AppMode
= DisplayMode
| EditMode EditState
deriving (Eq, Show)
-- | The state of the editor
data EditState = EditState
@@ -71,7 +75,7 @@ data EditState = EditState
-- ^ The selected row number
, _colNum :: Int
-- ^ The selected column
}
} deriving (Eq, Show)
-- | Identifies a resource
type ResName = ()
@@ -90,6 +94,17 @@ concat <$> mapM makeLenses
, ''EditState
]
editStateL :: Lens' AppMode (Maybe EditState)
editStateL = lens
( \case
DisplayMode -> Nothing
EditMode s -> Just s
)
( const $ \case
Just s -> EditMode s
Nothing -> DisplayMode
)
-- | Initial application state
initialState :: AppState
initialState = AppState DisplayMode 0