about summary refs log tree commit diff
path: root/users/grfn/xanthous/src/Xanthous/App/Prompt.hs
diff options
context:
space:
mode:
Diffstat (limited to 'users/grfn/xanthous/src/Xanthous/App/Prompt.hs')
-rw-r--r--users/grfn/xanthous/src/Xanthous/App/Prompt.hs25
1 files changed, 24 insertions, 1 deletions
diff --git a/users/grfn/xanthous/src/Xanthous/App/Prompt.hs b/users/grfn/xanthous/src/Xanthous/App/Prompt.hs
index 911f869612..0397e590e7 100644
--- a/users/grfn/xanthous/src/Xanthous/App/Prompt.hs
+++ b/users/grfn/xanthous/src/Xanthous/App/Prompt.hs
@@ -5,6 +5,8 @@ module Xanthous.App.Prompt
   , clearPrompt
   , prompt
   , prompt_
+  , stringPromptWithDefault
+  , stringPromptWithDefault_
   , confirm_
   , confirm
   , menu
@@ -123,7 +125,7 @@ prompt msgPath params cancellable cb = do
     SPointOnMap -> do
       charPos <- use characterPosition
       pure . Just $ mkPointOnMapPrompt cancellable charPos cb
-    SStringPrompt -> pure . Just $ mkPrompt cancellable pt cb
+    SStringPrompt -> pure . Just $ mkStringPrompt cancellable cb
     SConfirm -> pure . Just $ mkPrompt cancellable pt cb
     SDirectionPrompt -> pure . Just $ mkPrompt cancellable pt cb
     SContinue -> pure . Just $ mkPrompt cancellable pt cb
@@ -138,6 +140,27 @@ prompt_
   -> AppM ()
 prompt_ msg = prompt msg $ object []
 
+stringPromptWithDefault
+  :: forall (params :: Type). (ToJSON params)
+  => [Text]                                -- ^ Message key
+  -> params                                -- ^ Message params
+  -> PromptCancellable
+  -> Text                                  -- ^ Prompt default
+  -> (PromptResult 'StringPrompt -> AppM ()) -- ^ Prompt promise handler
+  -> AppM ()
+stringPromptWithDefault msgPath params cancellable def cb = do
+  msg <- Messages.message msgPath params
+  let p = mkStringPromptWithDefault cancellable def cb
+  promptState .= WaitingPrompt msg p
+
+stringPromptWithDefault_
+  :: [Text]                                -- ^ Message key
+  -> PromptCancellable
+  -> Text                                  -- ^ Prompt default
+  -> (PromptResult 'StringPrompt -> AppM ()) -- ^ Prompt promise handler
+  -> AppM ()
+stringPromptWithDefault_ msg = stringPromptWithDefault msg $ object []
+
 confirm
   :: ToJSON params
   => [Text] -- ^ Message key