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
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 =

View File

@ -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

View File

@ -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