Copyright | (c) 2010 Galois, Inc. |
---|---|
License | BSD-style (see the file libraries/base/LICENSE) |
Maintainer | John Launchbury, john@galois.com |
Stability | experimental |
Portability | concurrency |
Safe Haskell | None |
Language | Haskell98 |
A low-tech concurrent interface to the console. When multiple threads want input, they send messages to the console with the format
<thread-id>:request
The user supplies input to any requesting thread in a similar way:
<thread-id>:response
At any time, the user can enter !!
to obtain a listing of all the
active prompts. Any input not of either of these forms is discarded.
example :: IO () example = setupStdinout processes processes :: IO () processes = do forkIO $ (prompt "Enter something" >> return ()) forkIO $ (prompt "Something else" >> return ()) prompt "quit" -- When the main thread dies, return () -- the whole interaction ends
- setupStdInOut :: IO a -> IO a
- prompt :: HasFork io => String -> io String
- putStrLine :: MonadIO io => String -> io ()
Documentation
setupStdInOut :: IO a -> IO a Source
setupStdInOut
establishes the context for prompt
, by running
a daemon while its argument is executing. The daemon is terminated
once the argument to setupStdInOut
finishes.
prompt :: HasFork io => String -> io String Source
prompt
is the main user level function of the module. The function
prints its argument on stdout, prefixed by its process number. The user
similarly selects the recipient by prefixing the process number,
e.g. "23:". Active prompts will reprompt when !! is entered.
putStrLine :: MonadIO io => String -> io () Source
putStrLine
sends output to stdout, ensuring that lines are whole
and uninterrupted (including the final newline).