generate passord form error message
This commit is contained in:
parent
b0487d4d03
commit
8bddf35a1a
|
@ -22,10 +22,13 @@ License along with this program. If not, see
|
||||||
|
|
||||||
-}
|
-}
|
||||||
|
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
module Password.App.Draw (drawFunc) where
|
module Password.App.Draw (drawFunc) where
|
||||||
|
|
||||||
import Brick (Widget, emptyWidget, txt, vBox)
|
import Brick (Widget, emptyWidget, txt, vBox)
|
||||||
import Brick.Forms (renderForm)
|
import Brick.Forms (Form, formState, renderForm)
|
||||||
|
import Data.Text (Text)
|
||||||
import Lens.Micro ((^.))
|
import Lens.Micro ((^.))
|
||||||
|
|
||||||
import Password.App.Types
|
import Password.App.Types
|
||||||
|
@ -33,15 +36,21 @@ import Password.App.Types
|
||||||
-- | Renders the application view
|
-- | Renders the application view
|
||||||
drawFunc :: AppState -> [Widget ResName]
|
drawFunc :: AppState -> [Widget ResName]
|
||||||
drawFunc s = case s^.appMode of
|
drawFunc s = case s^.appMode of
|
||||||
InitMode is -> drawPassForm is
|
InitMode is -> drawPassForm $ is^.setPassForm
|
||||||
_ -> [emptyWidget]
|
_ -> [emptyWidget]
|
||||||
|
|
||||||
drawPassForm :: InitState -> [Widget ResName]
|
drawPassForm :: Form (Text, Text) () ResName -> [Widget ResName]
|
||||||
drawPassForm is =
|
drawPassForm f =
|
||||||
[ vBox
|
[ vBox
|
||||||
[ renderForm $ is^.setPassForm
|
[ renderForm f
|
||||||
, txt $ is^.spfError
|
, txt $ pfText $ formState f
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
pfText :: (Text, Text) -> Text
|
||||||
|
pfText (pass, conf)
|
||||||
|
| pass == "" = "Password cannot be blank."
|
||||||
|
| pass /= conf = "Passwords do not match."
|
||||||
|
| otherwise = ""
|
||||||
|
|
||||||
--jl
|
--jl
|
||||||
|
|
|
@ -41,7 +41,6 @@ module Password.App.Types (
|
||||||
runState,
|
runState,
|
||||||
-- ** InitState
|
-- ** InitState
|
||||||
setPassForm,
|
setPassForm,
|
||||||
spfError,
|
|
||||||
-- ** RunState
|
-- ** RunState
|
||||||
mainPass,
|
mainPass,
|
||||||
-- * Constructors
|
-- * Constructors
|
||||||
|
@ -76,14 +75,13 @@ data AppMode
|
||||||
} -- ^ initialization mode (master password form)
|
} -- ^ initialization mode (master password form)
|
||||||
| RunMode
|
| RunMode
|
||||||
{ _runState :: RunState
|
{ _runState :: RunState
|
||||||
|
-- ^ State of initialized app
|
||||||
} -- ^ Running mode
|
} -- ^ Running mode
|
||||||
|
|
||||||
-- | Application initialization state
|
-- | Application initialization state
|
||||||
data InitState = InitState
|
newtype InitState = InitState
|
||||||
{ _setPassForm :: Form (Text, Text) () ResName
|
{ _setPassForm :: Form (Text, Text) () ResName
|
||||||
-- ^ password form
|
-- ^ password form
|
||||||
, _spfError :: Text
|
|
||||||
-- ^ error message
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | State of the initialized application
|
-- | State of the initialized application
|
||||||
|
@ -121,6 +119,5 @@ newInitState = InitState
|
||||||
]
|
]
|
||||||
("", "")
|
("", "")
|
||||||
)
|
)
|
||||||
""
|
|
||||||
|
|
||||||
--jl
|
--jl
|
||||||
|
|
Loading…
Reference in New Issue
Block a user