github.com/buildpacks/pack@v0.33.3-0.20240516162812-884dd1837311/internal/term/term.go (about) 1 package term 2 3 import ( 4 "io" 5 6 "golang.org/x/term" 7 ) 8 9 // InvalidFileDescriptor based on https://golang.org/src/os/file_unix.go?s=2183:2210#L57 10 const InvalidFileDescriptor = ^(uintptr(0)) 11 12 // IsTerminal returns whether a writer is a terminal 13 func IsTerminal(w io.Writer) (uintptr, bool) { 14 if f, ok := w.(hasDescriptor); ok { 15 termFd := f.Fd() 16 isTerm := term.IsTerminal(int(termFd)) 17 return termFd, isTerm 18 } 19 20 return InvalidFileDescriptor, false 21 } 22 23 type hasDescriptor interface { 24 Fd() uintptr 25 }