New submission from Ben Franksen <[email protected]>:

2 patches for repository https://darcs.net/screened:

patch c11d6fe8356cd25d295f270c749f57975a2a5e52
Author: Ben Franksen <[email protected]>
Date:   Fri Jul  7 10:44:48 CEST 2023
  * allow user to cancel command when prompted about long comment

patch 7e496315c91c3a4205673b49936f7889ad53afb3
Author: Ben Franksen <[email protected]>
Date:   Fri Jul  7 11:11:17 CEST 2023
  * fix in Darcs.UI.Prompt: show default help only if we have a default

----------
files: allow-user-to-cancel-command-when-prompted-about-long-comment.dpatch, 
patch-preview.txt
messages: 24145
nosy: bfrk
status: needs-screening
title: allow user to cancel command when prompt... (and 1 more)

__________________________________
Darcs bug tracker <[email protected]>
<https://bugs.darcs.net/patch2441>
__________________________________
[allow user to cancel command when prompted about long comment
Ben Franksen <[email protected]>**20230707084448
 Ignore-this: f79a18ff1ca1fd0a9a2310a811d9d9923c5604de82a129c56b43420bd14fce4197446f783ffc103e
] hunk ./src/Darcs/UI/PatchHeader.hs 44
+import Darcs.UI.Prompt ( promptYornorq )
hunk ./src/Darcs/UI/PatchHeader.hs 52
-import Darcs.Util.Prompt ( PromptConfig(..), askUser, promptChar, promptYorn )
+import Darcs.Util.Prompt ( PromptConfig(..), askUser, promptChar )
hunk ./src/Darcs/UI/PatchHeader.hs 188
-  prompt_long_comment oldname =
-    do let verb = case m_old of Nothing -> "add a"; Just _ -> "edit the"
-       y <- promptYorn $ "Do you want to "++verb++" long comment?"
-       if y then get_log_using_editor oldname
-            else return (oldname, default_log, Nothing)
+  prompt_long_comment oldname = do
+    let verb = case m_old of { Nothing -> "add a"; Just _ -> "edit the" }
+        edit = get_log_using_editor oldname
+        no_edit = return (oldname, default_log, Nothing)
+        prompt = "Do you want to " ++ verb ++ " long comment?"
+    promptYornorq prompt (verb ++ " long comment") edit no_edit
hunk ./src/Darcs/UI/Prompt.hs 6
+    , promptYornorq
hunk ./src/Darcs/UI/Prompt.hs 11
+import System.Exit ( exitSuccess )
hunk ./src/Darcs/UI/Prompt.hs 54
+
+-- | Prompt the user for a yes or no or cancel
+promptYornorq :: String -> String -> IO a -> IO a -> IO a
+promptYornorq prompt verb yes no =
+    runPrompt (PromptConfig prompt verb choices Nothing)
+  where
+    quit = putStrLn "Command cancelled." >> exitSuccess
+    choices =
+      [ [ PromptChoice 'y' True yes ("yes, do " ++ verb)
+        , PromptChoice 'n' True no ("no, don't " ++ verb)
+        , PromptChoice 'q' True quit "quit (cancel command)"
+        ]
+      ]

[fix in Darcs.UI.Prompt: show default help only if we have a default
Ben Franksen <[email protected]>**20230707091117
 Ignore-this: 53904b23064c6be7a2c99978ae36a96ab0d40cbbcbb33a5f1668f222f378f9acaf4912fc0d44379c
] hunk ./src/Darcs/UI/Prompt.hs 29
-helpFor :: String -> [[PromptChoice a]] -> String
-helpFor jn choices =
+helpFor :: String -> [[PromptChoice a]] -> Maybe Char -> String
+helpFor jn choices def =
hunk ./src/Darcs/UI/Prompt.hs 36
-    , ""
-    , "<Space>: accept the current default (which is capitalized)"
-    ]
+    ] ++ defaultHelp
hunk ./src/Darcs/UI/Prompt.hs 39
+    defaultHelp =
+      case def of
+        Nothing -> []
+        Just _ ->
+          [ ""
+          , "<Space>: accept the current default (which is capitalized)"
+          ]
hunk ./src/Darcs/UI/Prompt.hs 58
-    Nothing -> putStrLn (helpFor pVerb pChoices) >> runPrompt pcfg
+    Nothing -> putStrLn (helpFor pVerb pChoices pDefault) >> runPrompt pcfg

Attachment: allow-user-to-cancel-command-when-prompted-about-long-comment.dpatch
Description: application/darcs-patch

_______________________________________________
darcs-devel mailing list
[email protected]
https://lists.darcs.net/mailman/listinfo/darcs-devel

Reply via email to