Skip to content

Instantly share code, notes, and snippets.

@RobbieClarken
Created August 26, 2016 11:44
Show Gist options
  • Save RobbieClarken/b235456b5404d030162c0e715c045965 to your computer and use it in GitHub Desktop.
Save RobbieClarken/b235456b5404d030162c0e715c045965 to your computer and use it in GitHub Desktop.
import sys
from select import select
import tty
import termios
import atexit
def disable_line_buffering():
original_tty_attrs = termios.tcgetattr(sys.stdin)
def restore_tty_attributes():
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, original_tty_attrs)
atexit.register(restore_tty_attributes)
tty.setcbreak(sys.stdin.fileno())
disable_line_buffering()
while True:
readable_objs, _, _ = select([sys.stdin], [], [])
for readable_obj in readable_objs:
print(readable_obj.read(1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment