created post-initialization state

This commit is contained in:
Jonathan Lamothe 2024-09-12 19:47:33 -04:00
parent 233a559aaf
commit b0487d4d03
3 changed files with 22 additions and 5 deletions

View File

@ -24,7 +24,7 @@ License along with this program. If not, see
module Password.App.Draw (drawFunc) where module Password.App.Draw (drawFunc) where
import Brick (Widget, txt, vBox) import Brick (Widget, emptyWidget, txt, vBox)
import Brick.Forms (renderForm) import Brick.Forms (renderForm)
import Lens.Micro ((^.)) import Lens.Micro ((^.))
@ -34,6 +34,7 @@ import Password.App.Types
drawFunc :: AppState -> [Widget ResName] drawFunc :: AppState -> [Widget ResName]
drawFunc s = case s^.appMode of drawFunc s = case s^.appMode of
InitMode is -> drawPassForm is InitMode is -> drawPassForm is
_ -> [emptyWidget]
drawPassForm :: InitState -> [Widget ResName] drawPassForm :: InitState -> [Widget ResName]
drawPassForm is = drawPassForm is =

View File

@ -80,6 +80,7 @@ fallbackHandler :: BrickEvent ResName () -> EventM ResName AppState ()
fallbackHandler e = gets (^.appMode) >>= \case fallbackHandler e = gets (^.appMode) >>= \case
InitMode _ -> zoom (appMode.initState.setPassForm) $ InitMode _ -> zoom (appMode.initState.setPassForm) $
handleFormEvent e handleFormEvent e
_ -> return ()
getKeyDispatcher getKeyDispatcher
:: AppState :: AppState

View File

@ -29,6 +29,7 @@ module Password.App.Types (
AppState (..), AppState (..),
AppMode (..), AppMode (..),
InitState (..), InitState (..),
RunState (..),
ResName (..), ResName (..),
-- * Lenses -- * Lenses
-- ** AppState -- ** AppState
@ -37,9 +38,12 @@ module Password.App.Types (
appMode, appMode,
-- ** AppMode -- ** AppMode
initState, initState,
runState,
-- ** InitState -- ** InitState
setPassForm, setPassForm,
spfError, spfError,
-- ** RunState
mainPass,
-- * Constructors -- * Constructors
mkInitialState, mkInitialState,
) where ) where
@ -65,10 +69,14 @@ data AppState = AppState
} }
-- | The applicaiton's mode -- | The applicaiton's mode
newtype AppMode = InitMode data AppMode
{ _initState :: InitState = InitMode
-- ^ Initialization state { _initState :: InitState
} -- ^ Initialization state
} -- ^ initialization mode (master password form)
| RunMode
{ _runState :: RunState
} -- ^ Running mode
-- | Application initialization state -- | Application initialization state
data InitState = InitState data InitState = InitState
@ -78,6 +86,12 @@ data InitState = InitState
-- ^ error message -- ^ error message
} }
-- | State of the initialized application
newtype RunState = RunState
{ _mainPass :: String
-- ^ The main password
}
-- | Resource identifier -- | Resource identifier
data ResName data ResName
= PassField = PassField
@ -88,6 +102,7 @@ concat <$> mapM makeLenses
[ ''AppState [ ''AppState
, ''AppMode , ''AppMode
, ''InitState , ''InitState
, ''RunState
] ]
-- | Builds an initial state -- | Builds an initial state