code: func (h *hijackedIOStreamer) stream(ctx context.Context) error {
  	restoreInput, err := h.setupInput()
  	if err != nil {
  		return fmt.Errorf("unable to setup input stream: %s", err)
  	}
  
  	defer restoreInput()
  
  	outputDone := h.beginOutputStream(restoreInput)
  	inputDone, detached := h.beginInputStream(restoreInput)
  
  	select {
  	case err := <-outputDone:
  		return err
  	case <-inputDone:
  		// Input stream has closed.
  		if h.outputStream != nil || h.errorStream != nil {
  			// Wait for output to complete streaming.
  			select {
  			case err := <-outputDone:
  				return err
  			case <-ctx.Done():
  				return ctx.Err()
  			}
  		}
  		return nil
  	case err := <-detached:
  		// Got a detach key sequence.
  		return err
  	case <-ctx.Done():
  		return ctx.Err()
  	}
  }
docs: // stream handles setting up the IO and then begins streaming stdin/stdout
  // to/from the hijacked connection, blocking until it is either done reading
  // output, the user inputs the detach key sequence when in TTY mode, or when
  // the given context is cancelled.