From: Dave Burt Date: 2006-06-08T10:44:10+09:00 Subject: Re: pausing until a character is received On 6/8/06, Logan Capaldo wrote: > > On Jun 7, 2006, at 2:17 AM, Dave Burt wrote: > > > Logan Capaldo wrote: > >> What ^C is actually depends on your terminal. If ^C is SIGINT for the > >> terminal, you'll never get ^C in the input stream no matter what > >> you do. > > > > Not true - if you handle the SIGINT, there's no reason why you > > shouldn't get a character in the input stream. Here's an irb session > > ... > > Aha. Well I think our respective operating systems have a difference > of opinion here. Try it on a *NIX. (Note that with a unix terminal > you could have SIGINT be ^P if you wanted). > > ^A (the character) will go through but ^C will not because it is > handled by the terminal, and the terminal simply does a kill(SIGINT) > on the process, it doesn't write to the processes stdin. Interesting. I'm sorry for my blunt denial; I actually even expected this might be the case. So in that case Sy would have to explicitly write it into the input stream if he wanted to get it out, although if he only wants to "pause until a character is received," there's no need. Something like the following (un-tested) begin require "Win32API" def read_char Win32API.new("crtdll", "_getch", [], "L").Call end rescue LoadError def read_char system "stty raw -echo" STDIN.getc ensure system "stty -raw echo" end end trap :INT &begin require 'termios' # http://raa.ruby-lang.org/project/ruby-termios/ c = Termios.tcgetattr(STDIN).cc[Termios::VINTR] proc { STDIN << c } rescue LoadError proc {} end Does that work? Cheers, Dave