packages feed

simple-prompt 0.2.3 → 0.2.4

raw patch · 4 files changed

+28/−9 lines, 4 files

Files

ChangeLog.md view
@@ -1,5 +1,8 @@ # Revision history for simple-prompt +## 0.2.4 (2025-12-28)+- yesNo[Default]: only append "?" if missing+ ## 0.2.3 (2024-06-13) - getGenericPrompt: adapt prompt suffix for final newline or colon - clearedInput no longer prints short duration for any buffered input
README.md view
@@ -21,3 +21,9 @@  - `runPrompt`, `getPrompt*` - `untilInput`, `mapInput`, `clearedInput`, `nonEmptyInput`.++## Usage examples+Since it basically runs in the IO monad usage is pretty simple.++For explicit examples search for `import SimplePrompt` in consumer packages:+dl-fedora, fbrnch, hkgr, rhbzquery, select-rpms, stack-clean-old
simple-prompt.cabal view
@@ -1,5 +1,5 @@ name:                simple-prompt-version:             0.2.3+version:             0.2.4 synopsis:            Simple commandline text prompt functions description:         The library provides prompt functions for reading user input:@@ -10,7 +10,7 @@ license-file:        LICENSE author:              Jens Petersen <juhpetersen@gmail.com> maintainer:          Jens Petersen <juhpetersen@gmail.com>-copyright:           2023-2024  Jens Petersen <juhpetersen@gmail.com>+copyright:           2023-2025  Jens Petersen <juhpetersen@gmail.com> category:            System homepage:            https://github.com/juhp/simple-prompt bug-reports:         https://github.com/juhp/simple-prompt/issues@@ -25,8 +25,10 @@                      || == 9.0.2                      || == 9.2.8                      || == 9.4.8-                     || == 9.6.5-                     || == 9.8.2+                     || == 9.6.7+                     || == 9.8.4+                     || == 9.10.3+                     || == 9.12.2  source-repository head   type:                git
src/SimplePrompt.hs view
@@ -14,7 +14,8 @@   ) where  import Control.Monad (void)-import Data.List.Extra (lower)+import Data.List.Extra (lower, trimEnd)+import Safe import System.Console.Haskeline (waitForAnyKey)  import SimplePrompt.Internal@@ -33,7 +34,7 @@ promptInitial :: MONADCONSTRAINT => String -> String -> m String promptInitial s = runPrompt . clearedInput . getPromptInitial s --- | reads string with buffering+-- | reads string including any buffered input promptBuffered :: MONADCONSTRAINT => String -> m String promptBuffered = runPrompt . getPromptLine @@ -63,7 +64,7 @@ -- | Yes-No prompt (accepts only {y,n,yes,no} case-insensitive) yesNo :: MONADCONSTRAINT => String -> m Bool yesNo desc =-  runPrompt . mapInput maybeYN . getPromptLine $ desc ++ "? [y/n]"+  runPrompt . mapInput maybeYN . getPromptLine $ appendQuestion desc ++ " [y/n]"   where     maybeYN inp =       case lower inp of@@ -73,11 +74,18 @@         "no" -> Just False         _ ->  Nothing +appendQuestion :: String -> String+appendQuestion desc =+  case lastMay (trimEnd desc) of+    Just '?' -> desc+    _ -> desc ++ "?"+ -- | Yes-No prompt with default (uses `clearedInput`)-yesNoDefault :: MONADCONSTRAINT => Bool -> String -> m Bool+yesNoDefault :: MONADCONSTRAINT => Bool -- ^ True => [Y/n], False => [y,N]+             -> String -> m Bool yesNoDefault yes desc =   runPrompt . mapInput maybeYN' . clearedInput . getPromptLine $-  desc ++ "? " ++ if yes then "[Y/n]" else "[y/N]"+  appendQuestion desc ++ " " ++ if yes then "[Y/n]" else "[y/N]"   where     maybeYN' inp =       case lower inp of