From 8bddf35a1a755e853bb95e77caa6253925f7133d Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Thu, 12 Sep 2024 20:09:13 -0400 Subject: [PATCH] generate passord form error message --- src/Password/App/Draw.hs | 21 +++++++++++++++------ src/Password/App/Types.hs | 7 ++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/Password/App/Draw.hs b/src/Password/App/Draw.hs index c723c94..1cc6ff2 100644 --- a/src/Password/App/Draw.hs +++ b/src/Password/App/Draw.hs @@ -22,10 +22,13 @@ License along with this program. If not, see -} +{-# LANGUAGE OverloadedStrings #-} + module Password.App.Draw (drawFunc) where import Brick (Widget, emptyWidget, txt, vBox) -import Brick.Forms (renderForm) +import Brick.Forms (Form, formState, renderForm) +import Data.Text (Text) import Lens.Micro ((^.)) import Password.App.Types @@ -33,15 +36,21 @@ import Password.App.Types -- | Renders the application view drawFunc :: AppState -> [Widget ResName] drawFunc s = case s^.appMode of - InitMode is -> drawPassForm is + InitMode is -> drawPassForm $ is^.setPassForm _ -> [emptyWidget] -drawPassForm :: InitState -> [Widget ResName] -drawPassForm is = +drawPassForm :: Form (Text, Text) () ResName -> [Widget ResName] +drawPassForm f = [ vBox - [ renderForm $ is^.setPassForm - , txt $ is^.spfError + [ renderForm f + , txt $ pfText $ formState f ] ] +pfText :: (Text, Text) -> Text +pfText (pass, conf) + | pass == "" = "Password cannot be blank." + | pass /= conf = "Passwords do not match." + | otherwise = "" + --jl diff --git a/src/Password/App/Types.hs b/src/Password/App/Types.hs index c3db0ce..63ce055 100644 --- a/src/Password/App/Types.hs +++ b/src/Password/App/Types.hs @@ -41,7 +41,6 @@ module Password.App.Types ( runState, -- ** InitState setPassForm, - spfError, -- ** RunState mainPass, -- * Constructors @@ -76,14 +75,13 @@ data AppMode } -- ^ initialization mode (master password form) | RunMode { _runState :: RunState + -- ^ State of initialized app } -- ^ Running mode -- | Application initialization state -data InitState = InitState +newtype InitState = InitState { _setPassForm :: Form (Text, Text) () ResName -- ^ password form - , _spfError :: Text - -- ^ error message } -- | State of the initialized application @@ -121,6 +119,5 @@ newInitState = InitState ] ("", "") ) - "" --jl