From b0487d4d03b5f75ab4db33262cc2692ca860f366 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Thu, 12 Sep 2024 19:47:33 -0400 Subject: [PATCH] created post-initialization state --- src/Password/App/Draw.hs | 3 ++- src/Password/App/Event.hs | 1 + src/Password/App/Types.hs | 23 +++++++++++++++++++---- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Password/App/Draw.hs b/src/Password/App/Draw.hs index 2c98637..c723c94 100644 --- a/src/Password/App/Draw.hs +++ b/src/Password/App/Draw.hs @@ -24,7 +24,7 @@ License along with this program. If not, see module Password.App.Draw (drawFunc) where -import Brick (Widget, txt, vBox) +import Brick (Widget, emptyWidget, txt, vBox) import Brick.Forms (renderForm) import Lens.Micro ((^.)) @@ -34,6 +34,7 @@ import Password.App.Types drawFunc :: AppState -> [Widget ResName] drawFunc s = case s^.appMode of InitMode is -> drawPassForm is + _ -> [emptyWidget] drawPassForm :: InitState -> [Widget ResName] drawPassForm is = diff --git a/src/Password/App/Event.hs b/src/Password/App/Event.hs index b8f7cbc..4f43486 100644 --- a/src/Password/App/Event.hs +++ b/src/Password/App/Event.hs @@ -80,6 +80,7 @@ fallbackHandler :: BrickEvent ResName () -> EventM ResName AppState () fallbackHandler e = gets (^.appMode) >>= \case InitMode _ -> zoom (appMode.initState.setPassForm) $ handleFormEvent e + _ -> return () getKeyDispatcher :: AppState diff --git a/src/Password/App/Types.hs b/src/Password/App/Types.hs index 91b8343..c3db0ce 100644 --- a/src/Password/App/Types.hs +++ b/src/Password/App/Types.hs @@ -29,6 +29,7 @@ module Password.App.Types ( AppState (..), AppMode (..), InitState (..), + RunState (..), ResName (..), -- * Lenses -- ** AppState @@ -37,9 +38,12 @@ module Password.App.Types ( appMode, -- ** AppMode initState, + runState, -- ** InitState setPassForm, spfError, + -- ** RunState + mainPass, -- * Constructors mkInitialState, ) where @@ -65,10 +69,14 @@ data AppState = AppState } -- | The applicaiton's mode -newtype AppMode = InitMode - { _initState :: InitState - -- ^ Initialization state - } +data AppMode + = InitMode + { _initState :: InitState + -- ^ Initialization state + } -- ^ initialization mode (master password form) + | RunMode + { _runState :: RunState + } -- ^ Running mode -- | Application initialization state data InitState = InitState @@ -78,6 +86,12 @@ data InitState = InitState -- ^ error message } +-- | State of the initialized application +newtype RunState = RunState + { _mainPass :: String + -- ^ The main password + } + -- | Resource identifier data ResName = PassField @@ -88,6 +102,7 @@ concat <$> mapM makeLenses [ ''AppState , ''AppMode , ''InitState + , ''RunState ] -- | Builds an initial state