Skip to content

Instantly share code, notes, and snippets.

@imcomking
Created August 25, 2016 06:19
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 imcomking/38661f4eaf4005bdfe49cb9cf89113fe to your computer and use it in GitHub Desktop.
Save imcomking/38661f4eaf4005bdfe49cb9cf89113fe to your computer and use it in GitHub Desktop.
class _GetchUnix:
def __init__(self):
import tty, sys
def __call__(self):
import sys, tty, termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
getch = _GetchUnix()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment