github.com/sfdevops1/terrra4orm@v0.11.12-beta1/helper/wrappedstreams/streams.go (about)

     1  // Package wrappedstreams provides access to the standard OS streams
     2  // (stdin, stdout, stderr) even if wrapped under panicwrap.
     3  package wrappedstreams
     4  
     5  import (
     6  	"os"
     7  
     8  	"github.com/mitchellh/panicwrap"
     9  )
    10  
    11  // Stdin returns the true stdin of the process.
    12  func Stdin() *os.File {
    13  	stdin := os.Stdin
    14  	if panicwrap.Wrapped(nil) {
    15  		stdin = wrappedStdin
    16  	}
    17  
    18  	return stdin
    19  }
    20  
    21  // Stdout returns the true stdout of the process.
    22  func Stdout() *os.File {
    23  	stdout := os.Stdout
    24  	if panicwrap.Wrapped(nil) {
    25  		stdout = wrappedStdout
    26  	}
    27  
    28  	return stdout
    29  }
    30  
    31  // Stderr returns the true stderr of the process.
    32  func Stderr() *os.File {
    33  	stderr := os.Stderr
    34  	if panicwrap.Wrapped(nil) {
    35  		stderr = wrappedStderr
    36  	}
    37  
    38  	return stderr
    39  }
    40  
    41  // These are the wrapped standard streams. These are setup by the
    42  // platform specific code in initPlatform.
    43  var (
    44  	wrappedStdin  *os.File
    45  	wrappedStdout *os.File
    46  	wrappedStderr *os.File
    47  )
    48  
    49  func init() {
    50  	// Initialize the platform-specific code
    51  	initPlatform()
    52  }