RCR getch

It would be quite convenient to have a getch method in Ruby.
Any opposition to my suggesting its addition to core?
-r

Roger P. wrote:

It would be quite convenient to have a getch method in Ruby.
Any opposition to my suggesting its addition to core?
-r

$ /usr/local/bin/ruby-1.9.3 -v -rio/console -e ‘p STDIN.gets; p
STDIN.noecho{|f|f.gets("!")}; p STDIN.getch’
ruby 1.9.3dev (2010-07-06 trunk 28554) [x86_64-linux]
hello
“hello\n”
“world!”
“\n”


Nobu Nakada

On Tue, Jul 6, 2010 at 2:43 PM, Nobuyoshi N. [email protected]
wrote:

$ /usr/local/bin/ruby-1.9.3 -v -rio/console -e ‘p STDIN.gets; p
STDIN.noecho{|f|f.gets(“!”)}; p STDIN.getch’
ruby 1.9.3dev (2010-07-06 trunk 28554) [x86_64-linux]
hello
“hello\n”
“world!”
“\n”

uber cool. thank for the tip, nobu.
best regards -botp

$ /usr/local/bin/ruby-1.9.3 -v -rio/console -e ‘p STDIN.gets; p
STDIN.noecho{|f|f.gets("!")}; p STDIN.getch’
ruby 1.9.3dev (2010-07-06 trunk 28554) [x86_64-linux]
hello
“hello\n”
“world!”
“\n”

Excellent. I’m glad this was added then.

This appears to not work on windows is that expected?
-r

Oops I missed a require:

require ‘io/console’
=> true
STDIN.getch

Excellent. I’m glad this was added then.

This appears to not work on windows is that expected?

It does work, and, though it doesn’t get arrow keys, it’s good enough
for my intents and purposes.

NB if you do want arrow keys you’ll want to wrap _getch or _getkbhit,
like rb-readline does. See also [1]…

-r

[1] http://betterlogic.com/roger/?p=2930

For google’s sake, here’s what it does when you don’t first require
io/console:

STDIN.getch
NoMethodError: undefined method getch' for #<IO:<STDIN>> from (irb):1 from C:/installs/ruby_trunk_installed/bin/irb.bat:20:in

Roger P. wrote:

NB if you do want arrow keys you’ll want to wrap _getch or _getkbhit,
like rb-readline does. See also [1]…

-r

[1] http://betterlogic.com/roger/?p=2930

What does it return when arrow keys are hit?


Nobu Nakada

NB if you do want arrow keys you’ll want to wrap _getch or _getkbhit,
like rb-readline does. See also [1]…
What does it return when arrow keys are hit?

224 + (some number like 75 for left arrow). It appears to not track when
the shift key is hit and things like that, though. Not sure if those
are accessible…