github.com/apcera/util@v0.0.0-20180322191801-7a50bc84ee48/str/term_unix.go (about)

     1  // Copyright 2012 Apcera Inc. All rights reserved.
     2  
     3  // +build cgo,!windows,!linux
     4  
     5  package str
     6  
     7  // Above may add freebsd after we test it there.
     8  // When you change the above make sure to change term_other.go
     9  
    10  /*
    11  #include <unistd.h>
    12  */
    13  import "C"
    14  
    15  import (
    16  	"os"
    17  )
    18  
    19  // May move to util/file? For now is here because it's the only
    20  // one used by colors.
    21  func IsTerminal(file *os.File) bool {
    22  	rv, err := C.isatty(C.int(file.Fd()))
    23  	if err != nil {
    24  		return false
    25  	}
    26  	if rv != 0 {
    27  		return true
    28  	}
    29  	return false
    30  }