module Main where
import Network.Libev
import Foreign.C.Types
-- This is the watcher callback
stdinCallback :: EvLoopPtr -> EvIoPtr -> CInt -> IO ()
stdinCallback loop watcher events = do
r <- getLine
case r of
"exit" -> evIoStop loop watcher
_ -> print $ "You said: " ++ r
main :: IO ()
main = do
-- Use the default event loop
loop <- evDefaultLoop 0
-- Create a watcher
watcher <- mkEvIo
-- mkIoCallback translates our Haskell callback to a function
-- callable from foreign code
cback <- mkIoCallback stdinCallback
-- Initialize an IO watcher that responds to EV_READ events on STDIN
let stdin = 0 in evIoInit watcher cback stdin ev_read
-- Start the watcher
evIoStart loop watcher
-- Now wait for events to arrive
evLoop loop 0
print "Exiting..."