mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-20 22:51:35 +03:00
db55986980
- Support for ingest cache, download cache, and progress bars.
53 lines
851 B
Go
53 lines
851 B
Go
//go:build !windows
|
|
|
|
package cli
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
|
|
"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.
|
|
// It respects [NO_COLOR], [FORCE_COLOR] and TERM=dumb environment variables.
|
|
//
|
|
// [NO_COLOR]: https://no-color.org/
|
|
// [FORCE_COLOR]: https://force-color.org/
|
|
func isColorTerminal(w io.Writer) bool {
|
|
if os.Getenv("NO_COLOR") != "" {
|
|
return false
|
|
}
|
|
if os.Getenv("FORCE_COLOR") != "" {
|
|
return true
|
|
}
|
|
if os.Getenv("TERM") == "dumb" {
|
|
return false
|
|
}
|
|
|
|
if w == nil {
|
|
return false
|
|
}
|
|
|
|
f, ok := w.(*os.File)
|
|
if !ok {
|
|
return false
|
|
}
|
|
|
|
if !term.IsTerminal(int(f.Fd())) {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|