diff --git a/src/Hamming/App/Types.hs b/src/Hamming/App/Types.hs index 267cf8a..e3527b0 100644 --- a/src/Hamming/App/Types.hs +++ b/src/Hamming/App/Types.hs @@ -30,7 +30,15 @@ module Hamming.App.Types ( -- * AppState AppState (..), -- ** Lenses + appMode, hammingCode, + -- * AppMode + AppMode (..), + -- * EditState, + EditState (..), + -- ** Lenses + rowNum, + colNum, -- * Other Types ResName, Event, @@ -46,7 +54,21 @@ import Lens.Micro.TH (makeLenses) -- | The main state of the application data AppState = AppState - { _hammingCode :: Word16 + { _appMode :: AppMode + , _hammingCode :: Word16 + } + +-- | The application's main mode +data AppMode + = DisplayMode + | EditMode EditState + +-- | The state of the editor +data EditState = EditState + { _rowNum :: Int + -- ^ The selected row number + , _colNum :: Int + -- ^ The selected column } -- | Identifies a resource @@ -61,10 +83,13 @@ type Action a = EventM ResName AppState a -- | Event handler type Handler = Event -> Action () -makeLenses ''AppState +concat <$> mapM makeLenses + [ ''AppState + , ''EditState + ] -- | Initial application state initialState :: AppState -initialState = AppState 0 +initialState = AppState DisplayMode 0 --jl diff --git a/test/Hamming/App/Widgets/InternalSpec.hs b/test/Hamming/App/Widgets/InternalSpec.hs index 11def99..fa893dc 100644 --- a/test/Hamming/App/Widgets/InternalSpec.hs +++ b/test/Hamming/App/Widgets/InternalSpec.hs @@ -44,16 +44,16 @@ hammingW'Spec = describe "hammingW'" $ mapM_ it ("should be " ++ show numExpRows) $ numActRows `shouldBe` numExpRows mapM_ - ( \(rowNum, actRow, expRow) -> let + ( \(row, actRow, expRow) -> let numActCols = length actRow numExpCols = length expRow - in context ("row " ++ show rowNum) $ do + in context ("row " ++ show row) $ do context "number of columns" $ it ("should be " ++ show numExpCols) $ numActCols `shouldBe` numExpCols mapM_ - ( \(colNum, actBit, expBit) -> - context ("column " ++ show colNum) $ + ( \(col, actBit, expBit) -> + context ("column " ++ show col) $ it ("should be " ++ show expBit) $ actBit `shouldBe` expBit ) $ zip3 [(0 :: Int)..] actRow expRow