From ffce0d6a1c5eb0b03702d0b161e4747e12adb7f5 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Sat, 7 Sep 2024 18:30:25 -0400 Subject: [PATCH] render the master password form --- passman.cabal | 3 ++- src/Password/App.hs | 10 +++------ src/Password/App/Draw.hs | 46 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 src/Password/App/Draw.hs diff --git a/passman.cabal b/passman.cabal index 267cd3d..a2b8727 100644 --- a/passman.cabal +++ b/passman.cabal @@ -4,7 +4,7 @@ cabal-version: 2.2 -- -- see: https://github.com/sol/hpack -- --- hash: d742af1f90e36896cfb5979f267f1ef87b81fb7e603c8c72ccc0c8e7a382a408 +-- hash: 1fb75b25a67b68f60aa6fa054876daeef931fac289d7f62c2b455533ab282fba name: passman version: 0.3.1.1 @@ -27,6 +27,7 @@ library exposed-modules: Password Password.App + Password.App.Draw Password.App.Types other-modules: Paths_passman diff --git a/src/Password/App.hs b/src/Password/App.hs index a30cc4c..d5ec309 100644 --- a/src/Password/App.hs +++ b/src/Password/App.hs @@ -28,29 +28,25 @@ import Brick ( App (..) , BrickEvent , EventM - , Widget , attrMap - , emptyWidget , halt - , neverShowCursor + , showFirstCursor , style ) +import Password.App.Draw import Password.App.Types -- | The main application passmanApp :: App AppState () ResName passmanApp = App { appDraw = drawFunc - , appChooseCursor = neverShowCursor + , appChooseCursor = showFirstCursor , appHandleEvent = eventHandler , appStartEvent = return () , appAttrMap = const $ attrMap (style 0) [] } -drawFunc :: AppState -> [Widget ResName] -drawFunc = const [emptyWidget] - eventHandler :: BrickEvent ResName () -> EventM ResName AppState () eventHandler = const halt diff --git a/src/Password/App/Draw.hs b/src/Password/App/Draw.hs new file mode 100644 index 0000000..2c98637 --- /dev/null +++ b/src/Password/App/Draw.hs @@ -0,0 +1,46 @@ +{-| + +Module: Password.App.Draw +Description: widget drawing functions +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.Draw (drawFunc) where + +import Brick (Widget, txt, vBox) +import Brick.Forms (renderForm) +import Lens.Micro ((^.)) + +import Password.App.Types + +-- | Renders the application view +drawFunc :: AppState -> [Widget ResName] +drawFunc s = case s^.appMode of + InitMode is -> drawPassForm is + +drawPassForm :: InitState -> [Widget ResName] +drawPassForm is = + [ vBox + [ renderForm $ is^.setPassForm + , txt $ is^.spfError + ] + ] + +--jl