Prev: [ANN] RubyInstaller: 1.8.7-p299, 1.9.1-p429 and 1.9.2-rc1 installersand packages released
Next: MiniTest test case execution
From: Roger Pack on 6 Jul 2010 01:25 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/.
From: Nobuyoshi Nakada on 6 Jul 2010 02:43 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/.
From: botp on 6 Jul 2010 03:03 On Tue, Jul 6, 2010 at 2:43 PM, Nobuyoshi Nakada <nobu(a)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" uber cool. thank for the tip, nobu. best regards -botp
From: Roger Pack on 6 Jul 2010 03:32 > $ /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/.
From: Roger Pack on 6 Jul 2010 13:00
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/. |