mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-21 07:01:41 +03:00
f0aa65791b
* CHANGELOG text clarification * Dialing in config/options * Yet more dialing in of config/options * Refactor output writers * YAML output for more commands
46 lines
635 B
Go
46 lines
635 B
Go
package cli
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/mattn/go-isatty"
|
|
"golang.org/x/term"
|
|
)
|
|
|
|
// isTerminal returns true if w is a terminal.
|
|
func isTerminal(w io.Writer) bool {
|
|
switch v := w.(type) {
|
|
case *os.File:
|
|
return term.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
|
|
}
|