ruby - STDIN.getch as a non block event (it's possible?) -


i'm trying read character instantly command line without use of enter. ruby (ruby 1.9.3p374) code i'm using following:

require 'io/console'  ch = stdin.getch puts ch 

until everithing working fine want put code inside infinite loop doing other stuff,

loop   puts "..doing stuff.."   ch = stdin.getch   if ch == 'q'     break   end end 

but code force press key between each printing. want behaviour similar stdin.read_nonblock method without having press enter key after pressing 1 char.

basically want print "..doing stuff.." until press key on keyboard don't want use enter.

any appreciated. thanks

you use built-in curses library handle interaction. it's powerful , used construct keyboard-driven tools such text editors.

the alternative use select poll if stdin readable. terminal might in line-buffered state, you'd need adjust before single keystrokes received. curses can handle you.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -