From: jjenning@... (jared l. jennings) Date: 2001-08-14T00:06:47+09:00 Subject: [ruby-talk:19640] Re: reading characters without waiting for carriage return On Sun, Aug 12, 2001 at 10:04:14PM +0900, ts wrote: > >>>>> "R" == RodZilla writes: > R> I need to read keystrokes from the console or data from a serial port > R> without having to wait for a carriage return... > > Perhaps something like [ruby-talk:9108] > http://www.ruby-talk.com/9108 Perhaps this would be a good time to release my ruby-tty extension... it's complete and documented but untested. But it ought to work. Unfortunately like the [ruby-talk:9108] solution, it's not guaranteed to be very portable. I've only built it on Linux; it should work with minor modifications on other Unices, but on Windows you're probably dead in the water as far as ruby-tty is concerned. http://ruby-audiofile.sourceforge.net/download/ruby-tty-0.2.tar.gz with my extension the way to do the same thing as in [ruby-talk:9108] would be: #---- require 'tty' tty = File.open("/dev/tty").extend tty stty_save = tty.save tty.make_raw begin print "quit by hitting q\r\n" while c = STDIN.getc and c != ?q p [c, c.chr] print "\r" end ensure tty.load stty_save end tty.close #---- not much shorter, but no backquotes or anything. -- A rock pile ceases to be a rock pile the moment a single man contemplates it, bearing within him the image of a cathedral. -- Antoine de Saint-Exupery