packages feed

simple-prompt 0.2.0.1 → 0.2.1

raw patch · 5 files changed

+24/−19 lines, 5 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- SimplePrompt.Internal: timedInput :: MonadIO m => InputT m a -> InputT m a
+ SimplePrompt.Internal: clearedInput :: MonadIO m => InputT m a -> InputT m a

Files

ChangeLog.md view
@@ -1,9 +1,13 @@ # Revision history for simple-prompt +## 0.2.1 (2023-08-09)+- do not trim spaces for yesNo and yesNoDefault+- Internal: timedInput renamed to clearedInput+ ## 0.2.0 (2023-05-28) - new API using haskeline and MonadIO - prompt ignores buffered stdin lines if it returns in milliseconds-- promptEnter replaces Prompt_+- promptEnter replaces prompt_ - new functions: promptEnter, promptInitial, promptNonEmpty, promptPassword - yesNo and yesNoDefault replace yesno - internal haskeline functions in SimplePrompt.Internal: including
README.md view
@@ -19,4 +19,4 @@ functional haskeline InputT monad transformer-based prompt functions:  - `runPrompt`, `getPrompt*`-- `untilInput`, `mapInput`, `timedInput`, `nonEmptyInput`.+- `untilInput`, `mapInput`, `clearedInput`, `nonEmptyInput`.
simple-prompt.cabal view
@@ -1,5 +1,5 @@ name:                simple-prompt-version:             0.2.0.1+version:             0.2.1 synopsis:            Simple commandline text prompt functions description:         The library provides prompt functions for reading user input:@@ -23,7 +23,7 @@                      || == 8.8.4                      || == 8.10.7                      || == 9.0.2-                     || == 9.2.7+                     || == 9.2.8                      || == 9.4.5  source-repository head
src/SimplePrompt.hs view
@@ -13,23 +13,23 @@   ) where  import Control.Monad (void)-import Data.List.Extra (lower, trim)+import Data.List.Extra (lower)  import SimplePrompt.Internal  #include "monadconstraint.h"  -- FIXME use haveTerminalUI ?--- | prompt which drops buffered input (using timedInput)+-- | prompt which drops buffered input (using clearedInput) -- -- Ignores buffered input lines (ie if input line gotten in under 5ms) prompt :: MONADCONSTRAINT => String -> m String-prompt = runPrompt . timedInput . getPromptLine+prompt = runPrompt . clearedInput . getPromptLine  -- FIXME non-empty?--- | reads string with initial input (using timedInput)+-- | reads string with initial input (using clearedInput) promptInitial :: MONADCONSTRAINT => String -> String -> m String-promptInitial s = runPrompt . timedInput . getPromptInitial s+promptInitial s = runPrompt . clearedInput . getPromptInitial s  -- | reads string with buffering promptBuffered :: MONADCONSTRAINT => String -> m String@@ -46,12 +46,12 @@ -- | prompt for character key promptChar :: MONADCONSTRAINT => String -> m Char promptChar =-  runPrompt . timedInput . getPromptChar+  runPrompt . clearedInput . getPromptChar  -- | prompt for Enter key promptEnter :: MONADCONSTRAINT => String -> m () promptEnter =-  void . runPrompt . untilInput (== "") . timedInput . getPromptLine+  void . runPrompt . untilInput (== "") . clearedInput . getPromptLine  -- | Yes-No prompt (accepts only {y,n,yes,no} case-insensitive) yesNo :: MONADCONSTRAINT => String -> m Bool@@ -59,21 +59,21 @@   runPrompt . mapInput maybeYN . getPromptLine $ desc ++ "? [y/n]"   where     maybeYN inp =-      case trim (lower inp) of+      case lower inp of         "y" -> Just True         "yes" -> Just True         "n" -> Just False         "no" -> Just False         _ ->  Nothing --- | Yes-No prompt with default (uses timedInput)+-- | Yes-No prompt with default (uses clearedInput) yesNoDefault :: MONADCONSTRAINT => Bool -> String -> m Bool yesNoDefault yes desc =-  runPrompt . mapInput maybeYN' . timedInput . getPromptLine $+  runPrompt . mapInput maybeYN' . clearedInput . getPromptLine $   desc ++ "? " ++ if yes then "[Y/n]" else "[y/N]"   where     maybeYN' inp =-      case trim (lower inp) of+      case lower inp of         "" -> Just yes         "y" -> Just True         "yes" -> Just True
src/SimplePrompt/Internal.hs view
@@ -10,7 +10,7 @@   untilInput,   mapInput,   nonEmptyInput,-  timedInput,+  clearedInput,   MonadIO, #if MIN_VERSION_haskeline(0,8,0)   MonadMask@@ -81,8 +81,9 @@ nonEmptyInput = untilInput (not . null)  -- | repeat prompt if input returned within milliseconds-timedInput :: MonadIO m => InputT m a -> InputT m a-timedInput prompter = do+-- This prevents buffered stdin lines from being used.+clearedInput :: MonadIO m => InputT m a -> InputT m a+clearedInput prompter = do   start <- liftIO getCurrentTime   input <- prompter   end <- liftIO getCurrentTime@@ -90,5 +91,5 @@   if diff < 0.005     then do     outputStrLn $ "ignoring buffered input: " ++ show diff ++ " too quick"-    timedInput prompter+    clearedInput prompter     else return input