implemented editStateL
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user