[Haskell-cafe] Re: syscall, sigpause and EINTR on Mac OSX

Glynn Clements glynn at gclements.plus.com
Sun Dec 11 20:20:11 EST 2005

Joel Reymont wrote:

> > This should be enough reason to scan  for keyboard events instead.
> > There is no guarantee that SIGINT would be sent only by keyboard.
> import System.Posix.Signals
> main =
>      do installHandler sigINT Ignore Nothing
>         x <- getChar
>         if x == '\ETX'
>            then do print "Gotcha!"
>            else do print "Try again!"
>                    main
> This does not work for ^C. Can it actually be done? Of course I can  
> just read "q" but that would be too simple :-).

You have to put the terminal into "raw" mode to be able to read any
character which is normally processed by the TTY driver, e.g.:

	import System.Posix.Terminal

	atts <- getTerminalAttributes (handleToFd stdin)
	let atts' = withoutMode atts ProcessInput
	setTerminalAttributes (handleToFd stdin) atts' Immediately

This disables all input processing, e.g. line-editing and CR->LF
translation (i.e. pressing the Enter/Return key will result in CR, not

Remember to set it back before exiting.

Glynn Clements <glynn at gclements.plus.com>

More information about the Haskell-Cafe mailing list