[#3006] mismatched quotation — "stevan apter" <apter@...>

ruby documentation uses a punctuation convention i've never seen

13 messages 2000/05/27

[ruby-talk:02995] Re: Problem with getc under UNIX with ruby 1.4.3

From: kjana@... (YANAGAWA Kazuhisa)
Date: 2000-05-26 04:37:46 UTC
List: ruby-talk #2995
In message <s92d498c.016@email1.cuna.com>
DDouthitt@cuna.com writes:

> I would have expected output to look like this:
> 
> # ./test.rb
> 59
> #
> 
> That is - no echo, instant response, no carriage return needed - or
> put another way, just as if you used "getc" (crunch!).
> 
> Can someone straighten me out here?

That's caused by terminal driver.  Not ruby's bug.  In general unix
like systems do line buffering for tty input, that is, an input string
is not passed to a program until a newline is entered.  Same for echo.

So if you want to get your desired result, you need to 1) disable
kernel buffering and 2) disable echo.  Of course you should restore
tty settings on an exit of your program.


For example:

    # get current tty settings.
    s = File.popen("stty -g")

    # set tty mode 'raw', which implies no echo, no buffering and more.
    system("stty raw")

    p $<.getc

    # restore tty settings.
    system("stty #{s}")'

NOTE: This code fragment is not for a real program but a experiment.
      You should study curses module or termios/termio/sgtty ioctl to
      achieve your purpose.

-- 
kjana@os.xaxon.ne.jp                                   May 26, 2000
Haste makes waste.

In This Thread