initialize random number generator

This commit is contained in:
Jonathan Lamothe 2024-09-07 15:34:10 -04:00
parent 11870423ed
commit 76d2600fcf
4 changed files with 52 additions and 5 deletions

View File

@ -26,8 +26,9 @@ import Brick (defaultMain)
import Control.Monad (void) import Control.Monad (void)
import Password.App import Password.App
import Password.App.Types
main :: IO () main :: IO ()
main = void $ defaultMain passmanApp () main = void $ mkInitialState >>= defaultMain passmanApp
--jl --jl

View File

@ -4,7 +4,7 @@ cabal-version: 2.2
-- --
-- see: https://github.com/sol/hpack -- see: https://github.com/sol/hpack
-- --
-- hash: 235d7c20ee589946f5e0cd199cca106191a300f9f24b023a6ef074c197c9861b -- hash: d742af1f90e36896cfb5979f267f1ef87b81fb7e603c8c72ccc0c8e7a382a408
name: passman name: passman
version: 0.3.1.1 version: 0.3.1.1
@ -27,6 +27,7 @@ library
exposed-modules: exposed-modules:
Password Password
Password.App Password.App
Password.App.Types
other-modules: other-modules:
Paths_passman Paths_passman
autogen-modules: autogen-modules:

View File

@ -36,8 +36,10 @@ import Brick
, style , style
) )
import Password.App.Types
-- | The main application -- | The main application
passmanApp :: App () () () passmanApp :: App AppState () ()
passmanApp = App passmanApp = App
{ appDraw = drawFunc { appDraw = drawFunc
, appChooseCursor = neverShowCursor , appChooseCursor = neverShowCursor
@ -46,10 +48,10 @@ passmanApp = App
, appAttrMap = const $ attrMap (style 0) [] , appAttrMap = const $ attrMap (style 0) []
} }
drawFunc :: () -> [Widget ()] drawFunc :: AppState -> [Widget ()]
drawFunc = const [emptyWidget] drawFunc = const [emptyWidget]
eventHandler :: BrickEvent () () -> EventM () () () eventHandler :: BrickEvent () () -> EventM () AppState ()
eventHandler = const halt eventHandler = const halt
--jl --jl

43
src/Password/App/Types.hs Normal file
View File

@ -0,0 +1,43 @@
{-|
Module: Password.App.Types
Description: data types used by the application
Copyright: (C) Jonathan Lamothe
License: LGPLv3 (or later)
Maintainer: jonathan@jlamothe.net
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program. If not, see
<https://www.gnu.org/licenses/>.
-}
module Password.App.Types (
AppState (..),
mkInitialState
) where
import Control.Monad.IO.Class (MonadIO)
import System.Random (StdGen, initStdGen)
-- | The application state
newtype AppState = AppState
{ _randGen :: StdGen
-- ^ The random number generator
} deriving (Eq, Show)
-- | Builds an initial state
mkInitialState :: MonadIO m => m AppState
mkInitialState = AppState <$> initStdGen
--jl