module System.Console.Wizard.BasicIO
( BasicIO
, runBasicIO
) where
import System.Console.Wizard
import System.Console.Wizard.Internal
import Control.Monad.Trans
import Control.Monad.Prompt
import Control.Monad.Trans.Maybe
import Control.Applicative((<$>))
import Data.Typeable
data BasicIO (m :: * -> *) r = ArbitraryIO (IO r)
runBasicIO :: Wizard BasicIO a -> IO (Maybe a)
runBasicIO (Wizard (MaybeT c)) = runRecPromptM f c
where f :: WizardAction BasicIO (RecPrompt (WizardAction BasicIO) ) c -> IO c
f (Line s) = getLine
f (Character s) = getChar
f (Password s m) = getLine
f (LinePreset s f b) = getLine
f (Output s) = putStr s
f (OutputLn s) = putStrLn s
f (Backend (ArbitraryIO a)) = a
instance MonadIO (Wizard BasicIO) where
liftIO = prompt . Backend . ArbitraryIO