47
@Jay gave a great answer, but there are two problems:
A simple fix for that is to save previous tty state and use following parameters:
-icanon - disable canonical input (ERASE and KILL processing);isig - enable the checking of characters against the special control characters INTR, QUIT, and SUSP.In the end you would have a function like this:
def get_char
state = `stty -g`
`stty raw -echo -icanon isig`
STDIN.getc.chr
ensure
`stty #{state}`
end