Skip to content

Instantly share code, notes, and snippets.

@fadeev
Created August 5, 2011 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fadeev/1127889 to your computer and use it in GitHub Desktop.
Save fadeev/1127889 to your computer and use it in GitHub Desktop.
Get a single character from the console
# 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