python how to reversetty.setraw(sys.stdin) 1

python how to reversetty.setraw(sys.stdin)

fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
    tty.setraw(fd)
    data = "stuff" # whatever it is you need doing
    return data
finally:
    termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)

Here is what the above code is Doing:
1. Get the file descriptor for the terminal.
2. Get the current terminal settings.
3. Set the terminal to raw mode.
4. Do whatever you need to do.
5. Restore the terminal settings.

Similar Posts