Try getting current tty through stdin and stdout

When the program is run without being connected to a tty, it fails because
os.ttyname raises an error. So when not connected to a tty, we ignore the
error.

We also try getting the tty name through stdin and stdout.