Use stdout to get and set terminal attributes
The current code uses stdin
to get and set terminal attributes. Unfortunately this doesn't work when stdin isn't connected to the TTY (e.g. it's a pipe). For example: some_program | less
(in this situation, less
's stdin can't be set to raw mode, but its stdout and TTY can be).
This change allows programs to use a raw terminal even if they're taking stdin through a pipe. If stdout is a pipe then this will still fail, though.
Edited by Michael Bradshaw