Created
August 5, 2011 16:15
-
-
Save fadeev/1127889 to your computer and use it in GitHub Desktop.
Get a single character from the console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From the Highline gem, https://github.com/JEG2/highline | |
def get_character( input = STDIN ) | |
raw_no_echo_mode | |
begin | |
input.getbyte | |
ensure | |
restore_mode | |
end | |
end | |
def raw_no_echo_mode | |
@state = `stty -g` | |
system "stty raw -echo -icanon isig" | |
end | |
def restore_mode | |
system "stty #{@state}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment