code: def _tty_stdio(cls, env):
      
      # If all stdio is a tty, there's only one logical I/O device (the tty device). This happens to
      # be addressable as a file in OSX and Linux, so we take advantage of that and directly open the
      # character device for output redirection - eliminating the need to directly marshall any
      # interactive stdio back/forth across the socket and permitting full, correct tty control with
      # no middle-man.
      stdin_ttyname, stdout_ttyname, stderr_ttyname = NailgunProtocol.ttynames_from_env(env)
      assert stdin_ttyname == stdout_ttyname == stderr_ttyname, (
        'expected all stdio ttys to be the same, but instead got: {}\n'
        'please file a bug at http://github.com/pantsbuild/pants'
        .format([stdin_ttyname, stdout_ttyname, stderr_ttyname])
      )
      with open(stdin_ttyname, 'rb+', 0) as tty:
        tty_fileno = tty.fileno()
        with stdio_as(stdin_fd=tty_fileno, stdout_fd=tty_fileno, stderr_fd=tty_fileno):
          def finalizer():
            termios.tcdrain(tty_fileno)
          yield finalizer
docs: Handles stdio redirection in the case of all stdio descriptors being the same tty.