Browse Source

Move the askUntil confirmation function into m

tags/v0.2.2.0
Peter J. Jones 4 years ago
parent
commit
28e6c4b820
4 changed files with 19 additions and 9 deletions
  1. 6
    3
      TODO
  2. 2
    2
      examples/simple.hs
  3. 5
    0
      src/System/Console/Byline/Internal/Byline.hs
  4. 6
    4
      src/System/Console/Byline/Primary.hs

+ 6
- 3
TODO View File

@@ -2,14 +2,17 @@
#+title: To-Do List

* Before First Release
** TODO Don't loop (in `askUntil`) if running in non-interactive (file) mode
** TODO `askWithMenuRepeatedly` should do the right thing if reading from a file
** TODO When rendering colors directly via `ask`, don't use color codes on Windows
** TODO Put the `askUntil` confirmation function into the `Byline m a` monad
** TODO Use TERMINFO to figure out if we can use rgb colors
** TODO Downgrade full rgb colors to the default terminal colors
** TODO Restore exception safety in `runByline` and `withCompletionFunc`
- I'm not using `runInputT` anymore so we don't get MonadException either
** DONE Don't loop (in `askUntil`) if running in non-interactive (file) mode
CLOSED: [2015-05-14 Thu 17:00]
** DONE `askWithMenuRepeatedly` should do the right thing if reading from a file
CLOSED: [2015-05-14 Thu 17:01]
** DONE Put the `askUntil` confirmation function into the `Byline m a` monad
CLOSED: [2015-05-14 Thu 17:11]
** DONE Restore the ability to change the completion function
CLOSED: [2015-05-14 Thu 15:23]
** DONE Simplify the interface by aborting on EOF

+ 2
- 2
examples/simple.hs View File

@@ -46,8 +46,8 @@ main = void $ runByline $ do
--------------------------------------------------------------------------------
-- | Example confirmation function that requires the input to be three
-- or more characters long.
atLeastThreeChars :: Text -> Either Stylized Text
atLeastThreeChars input =
atLeastThreeChars :: Text -> IO (Either Stylized Text)
atLeastThreeChars input = return $
if Text.length input < 3
then Left "You can do better."
else Right input

+ 5
- 0
src/System/Console/Byline/Internal/Byline.hs View File

@@ -16,6 +16,7 @@ module System.Console.Byline.Internal.Byline
( Byline (..)
, Env (..)
, eof
, liftOuter
, liftInputT
, runByline
) where
@@ -73,6 +74,10 @@ defEnv state mode comp =
eof :: (Monad m) => Byline m a
eof = Byline $ lift (MaybeT $ return Nothing)

--------------------------------------------------------------------------------
liftOuter :: (Monad m) => m a -> Byline m a
liftOuter = Byline . lift . lift

--------------------------------------------------------------------------------
-- | Lift an 'InputT' action into 'Byline'.
liftInputT :: (MonadIO m) => H.InputT IO a -> Byline m a

+ 6
- 4
src/System/Console/Byline/Primary.hs View File

@@ -110,14 +110,16 @@ askPassword prompt maskchr = do
-- 'sayLn'). When an acceptable answer from 'ask' is received, the
-- confirmation function should return it with 'Right'.
askUntil :: (MonadIO m)
=> Stylized -- ^ The prompt.
-> Maybe Text -- ^ Optional default answer.
-> (Text -> Either Stylized Text) -- ^ Confirmation function.
=> Stylized -- ^ The prompt.
-> Maybe Text -- ^ Optional default answer.
-> (Text -> m (Either Stylized Text)) -- ^ Confirmation function.
-> Byline m Text
askUntil prompt defans confirm = go where
go = do
answer <- ask prompt defans
case confirm answer of
check <- liftOuter (confirm answer)

case check of
Left msg -> sayLn msg >> go
Right result -> return result


Loading…
Cancel
Save