get a single char of input
suggest changeUnlike 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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents