From 76d2600fcfe079f4b35488f4693801b85341edee Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Sat, 7 Sep 2024 15:34:10 -0400 Subject: [PATCH] initialize random number generator --- app/Main.hs | 3 ++- passman.cabal | 3 ++- src/Password/App.hs | 8 +++++--- src/Password/App/Types.hs | 43 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 src/Password/App/Types.hs diff --git a/app/Main.hs b/app/Main.hs index 835bec2..2d82a8a 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -26,8 +26,9 @@ import Brick (defaultMain) import Control.Monad (void) import Password.App +import Password.App.Types main :: IO () -main = void $ defaultMain passmanApp () +main = void $ mkInitialState >>= defaultMain passmanApp --jl diff --git a/passman.cabal b/passman.cabal index 368497b..267cd3d 100644 --- a/passman.cabal +++ b/passman.cabal @@ -4,7 +4,7 @@ cabal-version: 2.2 -- -- see: https://github.com/sol/hpack -- --- hash: 235d7c20ee589946f5e0cd199cca106191a300f9f24b023a6ef074c197c9861b +-- hash: d742af1f90e36896cfb5979f267f1ef87b81fb7e603c8c72ccc0c8e7a382a408 name: passman version: 0.3.1.1 @@ -27,6 +27,7 @@ library exposed-modules: Password Password.App + Password.App.Types other-modules: Paths_passman autogen-modules: diff --git a/src/Password/App.hs b/src/Password/App.hs index 1f10905..07c76d6 100644 --- a/src/Password/App.hs +++ b/src/Password/App.hs @@ -36,8 +36,10 @@ import Brick , style ) +import Password.App.Types + -- | The main application -passmanApp :: App () () () +passmanApp :: App AppState () () passmanApp = App { appDraw = drawFunc , appChooseCursor = neverShowCursor @@ -46,10 +48,10 @@ passmanApp = App , appAttrMap = const $ attrMap (style 0) [] } -drawFunc :: () -> [Widget ()] +drawFunc :: AppState -> [Widget ()] drawFunc = const [emptyWidget] -eventHandler :: BrickEvent () () -> EventM () () () +eventHandler :: BrickEvent () () -> EventM () AppState () eventHandler = const halt --jl diff --git a/src/Password/App/Types.hs b/src/Password/App/Types.hs new file mode 100644 index 0000000..24bb549 --- /dev/null +++ b/src/Password/App/Types.hs @@ -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 +. + +-} + +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