get a single char of input

suggest change

Unlike gets.chomp, this does not wait for a newline.

Require the standard-library extension first:

require 'io/console'

Then a helper method can be written:

def get_char
  input = STDIN.getch
  control_c_code = "\u0003"
  exit(1) if input == control_c_code
  input
end

Exit if Ctrl+C is pressed. getch returns "\u0003" for that key instead of raising Interrupt.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents