module Control.Wire.Session
(
stepWire,
testWire
)
where
import Control.Arrow
import Control.Monad
import Control.Wire.Classes
import Control.Wire.Types
import System.IO
stepWire ::
Arrow (>~)
=> Wire e (>~) a b
-> (a >~ (Either e b, Wire e (>~) a b))
stepWire = toGen
testWire ::
forall a e (>~). (ArrowApply (>~), ArrowIO (>~), Show e)
=> Int
-> (() >~ a)
-> (Wire e (>~) a String >~ ())
testWire int getInput =
proc w' -> loop -< (int, w')
where
loop :: (Int, Wire e (>~) a String) >~ ()
loop =
proc (n', w') -> do
let n = let nn = succ n' in if nn >= int then 0 else nn
inp <- getInput -< ()
(mstr, w) <- stepWire w' -<< inp
arrIO -<
when (n' == 0) $ do
putStr "\r\027[K"
putStr (either (("Inhibited: " ++) . show) id mstr)
hFlush stdout
loop -< (n, w)