Skip to content

Instantly share code, notes, and snippets.

@thomasballinger
Created December 28, 2015 00:21
Show Gist options
  • Save thomasballinger/e80f242a8fc7252376b5 to your computer and use it in GitHub Desktop.
Save thomasballinger/e80f242a8fc7252376b5 to your computer and use it in GitHub Desktop.
import tty
import termios
import sys
class Cbreak(object):
def __enter__(self):
self.original_stty = termios.tcgetattr(sys.stdin)
tty.setcbreak(sys.stdin, termios.TCSANOW)
def __exit__(self, *args):
termios.tcsetattr(sys.stdin, termios.TCSANOW, self.original_stty)
if __name__ == '__main__':
with Cbreak():
print 'no enter required'
print sys.stdin.read(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment