github.com/git-lfs/git-lfs@v2.5.2+incompatible/subprocess/pty.go (about)

     1  package subprocess
     2  
     3  import (
     4  	"io"
     5  	"os"
     6  	"os/exec"
     7  )
     8  
     9  // Tty is a convenience wrapper to allow pseudo-TTYs on *nix systems, create with NewTty()
    10  // Do not use any of the struct members directly, call the Stderr() and Stdout() methods
    11  // Remember to call Close() when finished
    12  type Tty struct {
    13  	cmd    *exec.Cmd
    14  	outpty *os.File
    15  	outtty *os.File
    16  	errpty *os.File
    17  	errtty *os.File
    18  }
    19  
    20  func (t *Tty) Close() {
    21  	if t.outtty != nil {
    22  		t.outtty.Close()
    23  		t.outtty = nil
    24  	}
    25  	if t.errtty != nil {
    26  		t.errtty.Close()
    27  		t.errtty = nil
    28  	}
    29  }
    30  
    31  func (t *Tty) Stdout() (io.ReadCloser, error) {
    32  	if t.outpty != nil {
    33  		return t.outpty, nil
    34  	} else {
    35  		return t.cmd.StdoutPipe()
    36  	}
    37  }
    38  
    39  func (t *Tty) Stderr() (io.ReadCloser, error) {
    40  	if t.errpty != nil {
    41  		return t.errpty, nil
    42  	} else {
    43  		return t.cmd.StderrPipe()
    44  	}
    45  }