Created
August 26, 2016 11:44
-
-
Save RobbieClarken/b235456b5404d030162c0e715c045965 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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