From: Sy Ali Date: 2006-06-08T15:52:24+09:00 Subject: Re: pausing until a character is received Just for kicks I tried to better understand what's going on with trap. Maybe I misunderstand what it's for, but it doesn't seem to work the way I want. I can't seem to properly trap based on the signal name, and reading through some docs led me to this type of code: Signal.trap(0, lambda { puts "interrupted.." ; exit }) Signal 0 seems to be a generic exit code. I can list the signals with this: Signal.list.each { |i| print i puts "" } but I don't know the correct signal to use. Now I'm going to give up, not just because it's almost 3am but because catching 3 from read_char does the job for me. If/when I end up working with signals I'll definitely need to revisit this stuff. ---- 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 i = 1 until i > 3 a = read_char if a == 3 then puts "Interrupt received. This shouldn't be displayed.\n ... but it does." ; break ; end puts "I received: " + a.to_s i += 1 end puts "This shouldn't display upon interrupt." puts " ... but it always displays" Signal.trap(3, lambda { puts "interrupted.." ; exit })