Class: Chomper
- Inherits:
-
Object
- Object
- Chomper
- Defined in:
- lib/ruby_drills/chomper.rb
Class Method Summary collapse
-
.get_char ⇒ Object
Allows ‘Press any key to continue’ to work without requiring return.
Class Method Details
.get_char ⇒ Object
Allows ‘Press any key to continue’ to work without requiring return.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ruby_drills/chomper.rb', line 5 def self.get_char begin # save previous tty state state = `stty -g` # -icanon - disable canonical input (ERASE and KILL processing) # sig - checking characters against control characters INTR, QUIT, and SUSP `stty raw -echo -icanon isig` begin # do / while since using the arrow keys results in multi-byte input # that gets left in the stdin buffer. STDIN.getc.chr end while $stdin.ready? ensure # restore the default tty state `stty #{state}` end end |