- newtype Wizard backend a = Wizard (MaybeT (RecPrompt (WizardAction backend)) a)
- type PromptString = String
- line :: PromptString -> Wizard b String
- linePrewritten :: PromptString -> String -> String -> Wizard b String
- password :: PromptString -> Maybe Char -> Wizard b String
- character :: PromptString -> Wizard b Char
- output :: String -> Wizard b ()
- outputLn :: String -> Wizard b ()
- retry :: Wizard b a -> Wizard b a
- retryMsg :: String -> Wizard b a -> Wizard b a
- defaultTo :: Wizard b a -> a -> Wizard b a
- parser :: (a -> Maybe c) -> Wizard b a -> Wizard b c
- validator :: (a -> Bool) -> Wizard b a -> Wizard b a
- nonEmpty :: Wizard b [a] -> Wizard b [a]
- inRange :: Ord a => (a, a) -> Wizard b a -> Wizard b a
- parseRead :: Read a => Wizard b String -> Wizard b a
- liftMaybe :: Maybe a -> Wizard b a
- ensure :: (a -> Bool) -> a -> Maybe a
- readP :: Read a => String -> Maybe a
Wizard a is a conversation with the user that will result in a data type
a, or may fail.
Wizard is made up of one or more "primitives" (see below), composed using the
Alternative instances. The
Alternative instance is, as you might expect, a maybe-style cascade.
If the first wizard fails, the next one is tried.
Wizard constructor is exported here for use when developing backends, but it is better for end-users to
simply pretend that
Wizard is an opaque data type. Don't depend on this unless you have no other choice.
Wizards are, internally, just a maybe transformer over a prompt monad for each primitive action.
Primitives are the basic building blocks for
wizards. Use these functions to produce wizards that
ask for input from the user, or output information.
Text to the left of the cursor
Text to the right of the cursor
|-> Wizard b String|
Read one line of input, with some default text already present, before and/or after the editing cursor. Backends are not required to display this default text, or position the cursor anywhere, it is merely a suggestion.
Read one line of password input, with an optional mask character. The exact masking behavior of the password may vary from backend to backend. The masking character does not have to be honoured.
Output a string followed by a newline, if the backend used supports such output.
Modifiers change the behaviour of existing wizards.
Retry produces a wizard that will retry the entire conversation again if it fails.
Conceptually, it could thought of as
retry x = x <|> retry x, however it also prints
a user-friendly error message in the event of failure.
retry, except the error message can be specified.
x `defaultTo` y will return
x fails, e.g
parseRead line `defaultTo` 0.
validator p w causes a wizard to fail if the output value does not satisfy the predicate
validator (not . null), makes a wizard fail if it gets an empty string.
Makes a wizard fail if it gets an ordered quantity outside of the given range.
parser readP. Attaches a simple
read parser to a