sq/cli/ioutilz.go
2020-08-06 11:58:47 -06:00

46 lines
654 B
Go

package cli
import (
"io"
"os"
"github.com/mattn/go-isatty"
"golang.org/x/crypto/ssh/terminal"
)
// isTerminal returns true if w is a terminal.
func isTerminal(w io.Writer) bool {
switch v := w.(type) {
case *os.File:
return terminal.IsTerminal(int(v.Fd()))
default:
return false
}
}
// isColorTerminal returns true if w is a colorable terminal.
func isColorTerminal(w io.Writer) bool {
if w == nil {
return false
}
if !isTerminal(w) {
return false
}
if os.Getenv("TERM") == "dumb" {
return false
}
f, ok := w.(*os.File)
if !ok {
return false
}
if isatty.IsCygwinTerminal(f.Fd()) {
return false
}
return true
}