[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

getch equivalent of method in ruby ?

Googy

9/13/2006 6:21:00 AM

Hi,

I need to read some interactive input from keyboard and I am look for
getch (c equivalent) of method in ruby.

Thanks in advance.

8 Answers

Tobias Numiranta

9/13/2006 6:41:00 AM

0

Hi, try STDIN.getc. You maybe want to call system("stty raw") before.

Googy wrote:
> Hi,
>
> I need to read some interactive input from keyboard and I am look for
> getch (c equivalent) of method in ruby.
>
> Thanks in advance.

Paul Lutus

9/13/2006 7:03:00 AM

0

Googy wrote:

> Hi,
>
> I need to read some interactive input from keyboard and I am look for
> getch (c equivalent) of method in ruby.

Since you mention "getch()", which is non-standard and only available on the
Windows platform, I have to say there is no equivalent to it in any
portable languages. Another poster recommends manipulating the input stream
on Linux or another Unix, and if you have this option, that is an obvious
way to go, but it isn't portable between platforms.

The is no platform-portable keystroke-by-keystroke input method.

--
Paul Lutus
http://www.ara...

Lincoln Anderson

9/13/2006 7:04:00 AM

0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Googy wrote:
> Hi,
>
> I need to read some interactive input from keyboard and I am look for
> getch (c equivalent) of method in ruby.
>
> Thanks in advance.
>
>
>
I think it is 'gets'. Chech ruby-doc.org and examples in the
Pragmatic Programmer's Ruby book.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail....

iD8DBQFFB60dKte2c0P8BH0RAtnFAJsEoJXhjkbWcKynwqkaitECvq7iqgCfRblK
RjpPXeehroreTeQk/Zpm3R4=
=IJMV
-----END PGP SIGNATURE-----


Michael W. Ryder

9/13/2006 7:08:00 AM

0

Paul Lutus wrote:
> Googy wrote:
>
>> Hi,
>>
>> I need to read some interactive input from keyboard and I am look for
>> getch (c equivalent) of method in ruby.
>
> Since you mention "getch()", which is non-standard and only available on the
> Windows platform, I have to say there is no equivalent to it in any
> portable languages. Another poster recommends manipulating the input stream
> on Linux or another Unix, and if you have this option, that is an obvious
> way to go, but it isn't portable between platforms.
>
> The is no platform-portable keystroke-by-keystroke input method.
>

Curses is platform-portable, uses getch() to get keystrokes, and works
with Ruby.

Paul Lutus

9/13/2006 7:18:00 AM

0

Michael W. Ryder wrote:

> Paul Lutus wrote:
>> Googy wrote:
>>
>>> Hi,
>>>
>>> I need to read some interactive input from keyboard and I am look for
>>> getch (c equivalent) of method in ruby.
>>
>> Since you mention "getch()", which is non-standard and only available on
>> the Windows platform, I have to say there is no equivalent to it in any
>> portable languages. Another poster recommends manipulating the input
>> stream on Linux or another Unix, and if you have this option, that is an
>> obvious way to go, but it isn't portable between platforms.
>>
>> The is no platform-portable keystroke-by-keystroke input method.
>>
>
> Curses is platform-portable, uses getch() to get keystrokes, and works
> with Ruby.

I'll flesh out my reply. There is no platform-portable
keystroke-by-keystroke input method that doesn't require an external
utility to get around this limitation, and that takes a different form on
each platform that you try to implement it on.

--
Paul Lutus
http://www.ara...

Michael W. Ryder

9/13/2006 7:31:00 AM

0

Paul Lutus wrote:
> Michael W. Ryder wrote:
>
>> Paul Lutus wrote:
>>> Googy wrote:
>>>
>>>> Hi,
>>>>
>>>> I need to read some interactive input from keyboard and I am look for
>>>> getch (c equivalent) of method in ruby.
>>> Since you mention "getch()", which is non-standard and only available on
>>> the Windows platform, I have to say there is no equivalent to it in any
>>> portable languages. Another poster recommends manipulating the input
>>> stream on Linux or another Unix, and if you have this option, that is an
>>> obvious way to go, but it isn't portable between platforms.
>>>
>>> The is no platform-portable keystroke-by-keystroke input method.
>>>
>> Curses is platform-portable, uses getch() to get keystrokes, and works
>> with Ruby.
>
> I'll flesh out my reply. There is no platform-portable
> keystroke-by-keystroke input method that doesn't require an external
> utility to get around this limitation, and that takes a different form on
> each platform that you try to implement it on.
>

????? Curses is a library that works the same on all platforms. There
is no need to learn anything new to use it under windows, Unix, etc.
Business Basic (or BBX) included the ability to input single characters
over 30 years ago and the same programs and files worked on machines
from PCs to dedicated minicomputers to mainframes. I know that Business
Basic will not work with Ruby but the implementation is not that hard.

Paul Lutus

9/13/2006 8:17:00 AM

0

Michael W. Ryder wrote:

> Paul Lutus wrote:
>> Michael W. Ryder wrote:
>>
>>> Paul Lutus wrote:
>>>> Googy wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> I need to read some interactive input from keyboard and I am look for
>>>>> getch (c equivalent) of method in ruby.
>>>> Since you mention "getch()", which is non-standard and only available
>>>> on the Windows platform, I have to say there is no equivalent to it in
>>>> any portable languages. Another poster recommends manipulating the
>>>> input stream on Linux or another Unix, and if you have this option,
>>>> that is an obvious way to go, but it isn't portable between platforms.
>>>>
>>>> The is no platform-portable keystroke-by-keystroke input method.
>>>>
>>> Curses is platform-portable, uses getch() to get keystrokes, and works
>>> with Ruby.
>>
>> I'll flesh out my reply. There is no platform-portable
>> keystroke-by-keystroke input method that doesn't require an external
>> utility to get around this limitation, and that takes a different form on
>> each platform that you try to implement it on.
>>
>
> ????? Curses is a library that works the same on all platforms.

Look into it, as I just did.

> There is no need to learn anything new to use it under windows, Unix, etc.

This is simply not true. It can almost always be done, but it is by no means
point and click. It is an external library that takes different forms and
names on different platforms, and if the Ruby application is expected to be
seamlessly platform-portable, then it is best not to rely on the existence
of something like getch().

--
Paul Lutus
http://www.ara...

James Gray

9/13/2006 1:45:00 PM

0

On Sep 13, 2006, at 2:05 AM, Paul Lutus wrote:

> The is no platform-portable keystroke-by-keystroke input method.

HighLine has a method you can use for this though. The code for that
is in one file and pure Ruby, so vendor that and you're all set.

James Edward Gray II