It would be quite convenient to have a getch method in Ruby.
Any opposition to my suggesting its addition to core?
-r
···
--
Posted via http://www.ruby-forum.com/.
It would be quite convenient to have a getch method in Ruby.
Any opposition to my suggesting its addition to core?
-r
--
Posted via http://www.ruby-forum.com/.
Roger Pack 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
--
Posted via http://www.ruby-forum.com/\.
uber cool. thank for the tip, nobu.
best regards -botp
On Tue, Jul 6, 2010 at 2:43 PM, Nobuyoshi Nakada <nobu@ruby-lang.org> 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"
$ /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
--
Posted via http://www.ruby-forum.com/\.
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 `<main>'
--
Posted via http://www.ruby-forum.com/\.
Roger Pack wrote:
NB if you *do* want arrow keys you'll want to wrap _getch or _getkbhit,
like rb-readline does. See also [1]..-r
What does it return when arrow keys are hit?
--
Nobu Nakada
--
Posted via http://www.ruby-forum.com/\.
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...
--
Posted via http://www.ruby-forum.com/\.