Skip to content

Instantly share code, notes, and snippets.

@rakesh-patnaik
Created March 13, 2017 16:37
Show Gist options
  • Save rakesh-patnaik/442949af441766987223092ad6c51cb6 to your computer and use it in GitHub Desktop.
Save rakesh-patnaik/442949af441766987223092ad6c51cb6 to your computer and use it in GitHub Desktop.
import termios, fcntl, sys, os
fd = sys.stdin.fileno()
oldterm = termios.tcgetattr(fd)
newattr = termios.tcgetattr(fd)
newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
termios.tcsetattr(fd, termios.TCSANOW, newattr)
oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)
try:
while 1:
try:
c = sys.stdin.read(1)
print "You say {} but I say {}'.format(repr(c), repr(chr(ord(c) + 1)))
except IOError: pass
finally:
termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment