implenented strPrompt

This commit is contained in:
Jonathan Lamothe 2019-08-24 21:15:50 -04:00
parent f2cfe3b37b
commit 2a2189c7d1

View File

@ -23,6 +23,7 @@ module Mtlstats.Prompt (
-- * Prompt Functions -- * Prompt Functions
drawPrompt, drawPrompt,
promptHandler, promptHandler,
strPrompt,
numPrompt, numPrompt,
-- * Individual prompts -- * Individual prompts
homeScorePrompt, homeScorePrompt,
@ -63,6 +64,20 @@ promptHandler p (C.EventSpecialKey (C.KeyFunction k)) =
promptFunctionKey p k promptFunctionKey p k
promptHandler _ _ = return () promptHandler _ _ = return ()
-- | Builds a string prompt
strPrompt
:: String
-- ^ The prompt string
-> (String -> Action ())
-- ^ The callback function for the result
-> Prompt
strPrompt pStr act = Prompt
{ promptDrawer = drawSimplePrompt pStr
, promptCharCheck = const True
, promptAction = act
, promptFunctionKey = const $ return ()
}
-- | Builds a numeric prompt -- | Builds a numeric prompt
numPrompt numPrompt
:: String :: String
@ -71,7 +86,7 @@ numPrompt
-- ^ The callback function for the result -- ^ The callback function for the result
-> Prompt -> Prompt
numPrompt pStr act = Prompt numPrompt pStr act = Prompt
{ promptDrawer = \s -> C.drawString $ pStr ++ s ^. inputBuffer { promptDrawer = drawSimplePrompt pStr
, promptCharCheck = isDigit , promptCharCheck = isDigit
, promptAction = \inStr -> forM_ (readMaybe inStr) act , promptAction = \inStr -> forM_ (readMaybe inStr) act
, promptFunctionKey = const $ return () , promptFunctionKey = const $ return ()
@ -84,3 +99,6 @@ homeScorePrompt = numPrompt "Home score: " $
awayScorePrompt :: Prompt awayScorePrompt :: Prompt
awayScorePrompt = numPrompt "Away score: " $ awayScorePrompt = numPrompt "Away score: " $
modify . (progMode . awayScoreL ?~) modify . (progMode . awayScoreL ?~)
drawSimplePrompt :: String -> ProgState -> C.Update ()
drawSimplePrompt pStr s = C.drawString $ pStr ++ s ^. inputBuffer