[ANN] HighLine 0.4.0

Hi --

> I get the same result on Windows, so I suspect Ruby is doing some
> stuff behind the scenes. You may want to try my password prompter
> with the getch of the curses libraries on a Unix box just to be sure.

Duh. You're right:

$ ruby -e 'system "stty raw"; p $stdin.getc; syst "stty -raw"'
13

You might not want to use stty in that exact way. From the stty
manpage (on OSX):

Note that since the terminal driver no longer has a single RAW bit, it
is not possible to intuit what flags were set prior to setting raw.
This means that unsetting raw may not put back all the setting that
were previously in effect. To set the terminal into a raw state and
then accurately restore it, the following shell code is recommended:

    save_state=$(stty -g)
    stty raw
    ...
    stty "$save_state"

So the equivalent ruby code:

    state = `stty -g`
    system "stty raw"
    ...
    system "stty #{state}"

cheers,
Mark

···

On 5/7/05, James Edward Gray II <james@grayproductions.net> wrote:

On May 7, 2005, at 8:10 PM, Ryan Leavengood wrote:

That's an option, possibly.

Can you tell me how to read individual characters with termios? I've been messing with it and I can't get that right for anything. I clearly don't know the secret handshake!

On a semi-related angle, is anyone aware of a Unix that isn't going to support the stty hack? Just curious...

James Edward Gray II

···

On May 9, 2005, at 10:18 PM, Andre Nathan wrote:

Hmm. Maybe keep stty as a backup mechanism then... try to require
termios and fall back to stty if it fails. Would that be too ugly?

Hey, that's great to know. Thanks.

Is that going to work the same on other Unix flavors as well?

James Edward Gray II

···

On May 9, 2005, at 9:04 PM, Mark Hubbart wrote:

You might not want to use stty in that exact way. From the stty
manpage (on OSX):

In Message-Id: <D99ECD6A-8AFA-4383-A1EC-E67EF8676B91@grayproductions.net>
James Edward Gray II <james@grayproductions.net> writes:

Can you tell me how to read individual characters with termios? I've
been messing with it and I can't get that right for anything. I
clearly don't know the secret handshake!

Uhm, is the following URL useful?
<http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/48407&gt;

# Well that's an old and brief article so probably you should make
# sure both ruby-termios things and underlying termios function.

In modern Unixen stty are commonly implemented with termios, so you
can almost always do what you want to do with stty by using termios.

···

--
kjana@dm4lab.to May 11, 2005
It is never late to mend.

Hi,

> You might not want to use stty in that exact way. From the stty
> manpage (on OSX):

Hey, that's great to know. Thanks.

Is that going to work the same on other Unix flavors as well?

It works on my webhost's Debian system. It seems it's just dumping and
restoring the settings, so it should be safe on all platforms. Setting
"raw" actually sets several other flags, and unsetting "raw" unsets
those same flags. So if someone has turned on or off some of those
flags, those settings would be lost if you do "raw" followed by
"-raw". I think :slight_smile:

cheers,
Mark

···

On 5/9/05, James Edward Gray II <james@grayproductions.net> wrote:

On May 9, 2005, at 9:04 PM, Mark Hubbart wrote:

Update: setting "raw" seems to be overkill. It might keep the OS from
converting linefeeds and such. Here's the method I'm using in a
project I'm working on now:

  def no_echo
    state = `stty -g`
    system "stty -echo cbreak"
    yield
  ensure
    system "stty #{state}"
  end
  
  no_echo{gets} #==>"test\n"

Using raw, it reads the "enter" key as a carriage return, and gets
doesn't work as expected.

cheers,
Mark

···

On 5/9/05, James Edward Gray II <james@grayproductions.net> wrote:

On May 9, 2005, at 9:04 PM, Mark Hubbart wrote:

> You might not want to use stty in that exact way. From the stty
> manpage (on OSX):

Hey, that's great to know. Thanks.

Yes, this helped a lot, thank you. (Sorry for my delayed response.)

I have evaluated this and I still prefer using stty here. For now, HighLine will go that way. However, I promise to revisit the issue as soon as someone makes a good case against it. :slight_smile:

James Edward Gray II

···

On May 10, 2005, at 10:22 AM, YANAGAWA Kazuhisa wrote:

In Message-Id: <D99ECD6A-8AFA-4383-A1EC-E67EF8676B91@grayproductions.net>
James Edward Gray II <james@grayproductions.net> writes:

Can you tell me how to read individual characters with termios? I've
been messing with it and I can't get that right for anything. I
clearly don't know the secret handshake!

Uhm, is the following URL useful?
<http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/48407&gt;

# Well that's an old and brief article so probably you should make
# sure both ruby-termios things and underlying termios function.

-a will list the current settings in human readable form, ie, on my system
$ stty -a
speed 9600 baud; rows 24; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^H; kill = ^U; eof = ^D; eol = M-^?; eol2 = M-^?;
start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V;
flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc ixany imaxbel
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe -echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke

J.

···

On 10/05/2005, at 1:45 PM, Mark Hubbart wrote:

Is that going to work the same on other Unix flavors as well?

It works on my webhost's Debian system. It seems it's just dumping and
restoring the settings, so it should be safe on all platforms. Setting
"raw" actually sets several other flags, and unsetting "raw" unsets
those same flags. So if someone has turned on or off some of those
flags, those settings would be lost if you do "raw" followed by
"-raw". I think :slight_smile:

Thanks for the tips, but HighLine actually counts on this. :slight_smile:

James Edward Gray II

···

On May 9, 2005, at 11:51 PM, Mark Hubbart wrote:

Update: setting "raw" seems to be overkill. It might keep the OS from
converting linefeeds and such. Here's the method I'm using in a
project I'm working on now:

  def no_echo
    state = `stty -g`
    system "stty -echo cbreak"
    yield
  ensure
    system "stty #{state}"
  end

  no_echo{gets} #==>"test\n"

Using raw, it reads the "enter" key as a carriage return, and gets
doesn't work as expected.