-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | High level, generic library for interrogative user interfaces -- -- wizards is a package designed for the quick and painless -- development of interrogative programs, which revolve around a -- "dialogue" with the user, who is asked a series of questions in a -- sequence much like an installation wizard. -- -- Everything from interactive system scripts, to installation wizards, -- to full-blown shells can be implemented with the support of -- wizards. -- -- It is developed transparently on top of a free monad, which separates -- out the semantics of the program from any particular interface. A -- variety of backends exist, including console-based -- System.Console.Wizard.Haskeline and -- System.Console.Wizard.BasicIO, and the pure -- System.Console.Wizard.Pure. It is also possible to write your -- own backends, or extend existing back-ends with new features. While -- both built-in IO backends operate on a console, there is no reason why -- wizards cannot also be used for making GUI wizard interfaces. -- -- See the github page for examples on usage: -- -- http://www.github.com/liamoc/wizards -- -- For creating backends, the module -- System.Console.Wizard.Internal has a brief tutorial. @package wizards @version 1.0 module System.Console.Wizard.Internal -- | A Wizard b a is a conversation with the user via back-end -- b that will result in a data type a, or may fail. A -- Wizard is made up of one or more "primitives" (see below), -- composed using the Applicative, Monad and -- Alternative instances. The Alternative instance is, as -- you might expect, a maybe-style cascade. If the first wizard fails, -- the next one is tried. mzero can be used to induce failure -- directly. -- -- The 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 free -- monad built from some coproduct of functors, each of which is a -- primitive action. newtype Wizard backend a Wizard :: (MaybeT (Free backend) a) -> Wizard backend a -- | A string for a prompt type PromptString = String -- | Coproduct of two functors data (:+:) f g w Inl :: (f w) -> :+: f g w Inr :: (g w) -> :+: f g w -- | Subsumption of two functors. You shouldn't define any of your own -- instances of this when writing back-ends, rely only on -- GeneralizedNewtypeDeriving. class (Functor sub, Functor sup) => :<: sub sup -- | Injection function for free monads, see "Data Types a la Carte" from -- Walter Swierstra, -- http://www.cs.ru.nl/~W.Swierstra/Publications/DataTypesALaCarte.pdf inject :: g :<: f => g (Free f a) -> Free f a -- | A class for implementing actions on a backend. E.g Run IO Output -- provides an interpreter for the Output action in the IO monad. class Run a b runAlgebra :: Run a b => b (a v) -> a v -- | Run a wizard using some back-end. run :: (Functor f, Monad b, Run b f) => Wizard f a -> b (Maybe a) data Output w Output :: String -> w -> Output w data OutputLn w OutputLn :: String -> w -> OutputLn w data Line w Line :: PromptString -> (String -> w) -> Line w data LinePrewritten w LinePrewritten :: PromptString -> String -> String -> (String -> w) -> LinePrewritten w data Password w Password :: PromptString -> (Maybe Char) -> (String -> w) -> Password w data Character w Character :: PromptString -> (Char -> w) -> Character w data ArbitraryIO w ArbitraryIO :: (IO a) -> (a -> w) -> ArbitraryIO w instance [overlap ok] Functor backend => Monad (Wizard backend) instance [overlap ok] Functor backend => Functor (Wizard backend) instance [overlap ok] Functor backend => Applicative (Wizard backend) instance [overlap ok] Functor backend => Alternative (Wizard backend) instance [overlap ok] Functor backend => MonadPlus (Wizard backend) instance [overlap ok] (Functor f, Functor g) => Functor (f :+: g) instance [overlap ok] Functor Output instance [overlap ok] Functor OutputLn instance [overlap ok] Functor Line instance [overlap ok] Functor Character instance [overlap ok] Functor LinePrewritten instance [overlap ok] Functor Password instance [overlap ok] Functor ArbitraryIO instance [overlap ok] (Run b f, Run b g) => Run b (f :+: g) instance [overlap ok] (Functor f, Functor g, Functor h, f :<: g) => f :<: (h :+: g) instance [overlap ok] (Functor f, Functor g) => f :<: (f :+: g) instance [overlap ok] Functor f => f :<: f module System.Console.Wizard -- | A Wizard b a is a conversation with the user via back-end -- b that will result in a data type a, or may fail. A -- Wizard is made up of one or more "primitives" (see below), -- composed using the Applicative, Monad and -- Alternative instances. The Alternative instance is, as -- you might expect, a maybe-style cascade. If the first wizard fails, -- the next one is tried. mzero can be used to induce failure -- directly. -- -- The 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 free -- monad built from some coproduct of functors, each of which is a -- primitive action. newtype Wizard backend a Wizard :: (MaybeT (Free backend) a) -> Wizard backend a -- | A string for a prompt type PromptString = String -- | Run a wizard using some back-end. run :: (Functor f, Monad b, Run b f) => Wizard f a -> b (Maybe a) -- | Subsumption of two functors. You shouldn't define any of your own -- instances of this when writing back-ends, rely only on -- GeneralizedNewtypeDeriving. class (Functor sub, Functor sup) => :<: sub sup -- | Coproduct of two functors data (:+:) f g w data Line w -- | Read one line of input from the user. Cannot fail (but may throw -- exceptions, depending on the backend). line :: Line :<: b => PromptString -> Wizard b String data LinePrewritten w -- | Read one line of input, with some default text already present, before -- and/or after the editing cursor. linePrewritten :: LinePrewritten :<: b => PromptString -> String -> String -> Wizard b String data Password w -- | Read one line of password input, with an optional mask character. password :: Password :<: b => PromptString -> Maybe Char -> Wizard b String data Character w -- | Read a single character only from input. Cannot fail (but may throw -- exceptions, depending on the backend). character :: Character :<: b => PromptString -> Wizard b Char data Output w -- | Output a string. Does not fail. output :: Output :<: b => String -> Wizard b () data OutputLn w -- | Output a string followed by a newline. Does not fail. outputLn :: OutputLn :<: b => String -> Wizard b () data ArbitraryIO w -- | Retry produces a wizard that will retry the entire conversation again -- if it fails. It is simply retry x = x <|> retry x. retry :: Functor b => Wizard b a -> Wizard b a -- | Same as retry, except an error message can be specified. retryMsg :: OutputLn :<: b => String -> Wizard b a -> Wizard b a -- | x `defaultTo` y will return y if x fails, -- e.g parseRead line `defaultTo` 0. defaultTo :: Functor b => Wizard b a -> a -> Wizard b a -- | Like fmap, except the function may be partial (Nothing -- causes the wizard to fail). parser :: Functor b => (a -> Maybe c) -> Wizard b a -> Wizard b c -- | validator p causes a wizard to fail if the output value does -- not satisfy the predicate p. validator :: Functor b => (a -> Bool) -> Wizard b a -> Wizard b a -- | Simply validator (not . null), makes a wizard fail if it gets -- an empty string. nonEmpty :: Functor b => Wizard b [a] -> Wizard b [a] -- | Makes a wizard fail if it gets an ordered quantity outside of the -- given range. inRange :: (Ord a, Functor b) => (a, a) -> Wizard b a -> Wizard b a -- | Simply parser readP. Attaches a simple read parser -- to a Wizard. parseRead :: (Read a, Functor b) => Wizard b String -> Wizard b a -- | Translate a maybe value into wizard success/failure. liftMaybe :: Functor b => Maybe a -> Wizard b a -- | Ensures that a maybe value satisfies a given predicate. ensure :: (a -> Bool) -> a -> Maybe a -- | A read-based parser for the parser modifier. readP :: Read a => String -> Maybe a instance [overlap ok] ArbitraryIO :<: b => MonadIO (Wizard b) module System.Console.Wizard.Haskeline -- | The Haskeline back-end will throw this exception if EOF is encountered -- when it is not expected. Specifically, when actions such as -- getInputLine return Nothing. data UnexpectedEOF UnexpectedEOF :: UnexpectedEOF -- | Haskeline supports all the following features completely. data Haskeline a -- | A simple identity function, used to restrict types if the type -- inferred by GHC is too general. You could achieve the same effect with -- a type signature, but this is slightly less typing. haskeline :: Wizard Haskeline a -> Wizard Haskeline a -- | Modifies a wizard so that it will run with different Haskeline -- Settings to the top level input monad. withSettings :: WithSettings :<: b => Settings IO -> Wizard b a -> Wizard b a data WithSettings w WithSettings :: (Settings IO) -> w -> WithSettings w instance [overlap ok] Typeable UnexpectedEOF instance [overlap ok] Show UnexpectedEOF instance [overlap ok] Functor WithSettings instance [overlap ok] Output :<: Haskeline instance [overlap ok] OutputLn :<: Haskeline instance [overlap ok] Line :<: Haskeline instance [overlap ok] Character :<: Haskeline instance [overlap ok] LinePrewritten :<: Haskeline instance [overlap ok] Password :<: Haskeline instance [overlap ok] ArbitraryIO :<: Haskeline instance [overlap ok] WithSettings :<: Haskeline instance [overlap ok] Functor Haskeline instance [overlap ok] Run (InputT IO) Haskeline instance [overlap ok] Run (InputT IO) WithSettings instance [overlap ok] Run (InputT IO) ArbitraryIO instance [overlap ok] Run (InputT IO) Password instance [overlap ok] Run (InputT IO) LinePrewritten instance [overlap ok] Run (InputT IO) Character instance [overlap ok] Run (InputT IO) Line instance [overlap ok] Run (InputT IO) OutputLn instance [overlap ok] Run (InputT IO) Output instance [overlap ok] Exception UnexpectedEOF module System.Console.Wizard.BasicIO -- | The BasicIO backend supports only simple input and output. -- Support for Password and LinePrewritten features can be -- added with a shim from Shim. data BasicIO a -- | A simple identity function, used to restrict types if the type -- inferred by GHC is too general. You could achieve the same effect with -- a type signature, but this is slightly less typing. basicIO :: Wizard BasicIO a -> Wizard BasicIO a instance [overlap ok] Output :<: BasicIO instance [overlap ok] OutputLn :<: BasicIO instance [overlap ok] Line :<: BasicIO instance [overlap ok] Character :<: BasicIO instance [overlap ok] ArbitraryIO :<: BasicIO instance [overlap ok] Functor BasicIO instance [overlap ok] Run IO BasicIO instance [overlap ok] Run IO ArbitraryIO instance [overlap ok] Run IO Character instance [overlap ok] Run IO Line instance [overlap ok] Run IO OutputLn instance [overlap ok] Run IO Output module System.Console.Wizard.Pure -- | The Pure backend supports only simple input and output. Support -- for Password and LinePrewritten features can be added -- with a shim from System.Console.Wizard.Shim. data Pure a -- | Thrown if the wizard ever unexpectedly runs out of input. data UnexpectedEOI UnexpectedEOI :: UnexpectedEOI -- | Run a wizard in the Pure backend runPure :: Wizard Pure a -> String -> (Maybe a, String) -- | The pure backend is actually just a simple state monad, with the -- following state. type PureState = ([String], Seq Char) instance [overlap ok] Typeable UnexpectedEOI instance [overlap ok] Show UnexpectedEOI instance [overlap ok] Output :<: Pure instance [overlap ok] OutputLn :<: Pure instance [overlap ok] Line :<: Pure instance [overlap ok] Character :<: Pure instance [overlap ok] Functor Pure instance [overlap ok] Run (State PureState) Pure instance [overlap ok] Run (State PureState) Character instance [overlap ok] Run (State PureState) Line instance [overlap ok] Run (State PureState) OutputLn instance [overlap ok] Run (State PureState) Output instance [overlap ok] Exception UnexpectedEOI