From 2a2189c7d1f538f346e677647be552120ad4d426 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Sat, 24 Aug 2019 21:15:50 -0400 Subject: [PATCH] implenented strPrompt --- src/Mtlstats/Prompt.hs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Mtlstats/Prompt.hs b/src/Mtlstats/Prompt.hs index 5c69ec4..cd66019 100644 --- a/src/Mtlstats/Prompt.hs +++ b/src/Mtlstats/Prompt.hs @@ -23,6 +23,7 @@ module Mtlstats.Prompt ( -- * Prompt Functions drawPrompt, promptHandler, + strPrompt, numPrompt, -- * Individual prompts homeScorePrompt, @@ -63,6 +64,20 @@ promptHandler p (C.EventSpecialKey (C.KeyFunction k)) = promptFunctionKey p k 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 numPrompt :: String @@ -71,7 +86,7 @@ numPrompt -- ^ The callback function for the result -> Prompt numPrompt pStr act = Prompt - { promptDrawer = \s -> C.drawString $ pStr ++ s ^. inputBuffer + { promptDrawer = drawSimplePrompt pStr , promptCharCheck = isDigit , promptAction = \inStr -> forM_ (readMaybe inStr) act , promptFunctionKey = const $ return () @@ -84,3 +99,6 @@ homeScorePrompt = numPrompt "Home score: " $ awayScorePrompt :: Prompt awayScorePrompt = numPrompt "Away score: " $ modify . (progMode . awayScoreL ?~) + +drawSimplePrompt :: String -> ProgState -> C.Update () +drawSimplePrompt pStr s = C.drawString $ pStr ++ s ^. inputBuffer