pranshuparmar--witr
36b3af2e3d
PR Check / Code Quality: Format (push) Failing after 1s
PR Check / Code Quality: Lint (darwin) (push) Failing after 0s
PR Check / Code Quality: Lint (freebsd) (push) Failing after 1s
PR Check / Code Quality: Lint (windows) (push) Failing after 1s
PR Check / Code Quality: Lint (linux) (push) Failing after 1s
PR Check / Security: Vulnerability Scan (push) Failing after 0s
Update Documentation / update-docs (push) Failing after 2s
PR Check / Code Quality: Vendor (push) Failing after 1s
PR Check / Code Quality: Coverage (push) Failing after 0s
PR Check / Tests: Unit (macos-latest) (push) Has been cancelled
PR Check / Tests: Unit (ubuntu-24.04) (push) Has been cancelled
PR Check / Tests: Unit (ubuntu-24.04-arm) (push) Has been cancelled
PR Check / Tests: Unit (windows-latest) (push) Has been cancelled
34 行
1021 B
Go
34 行
1021 B
Go
package app
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/mattn/go-isatty"
|
|
)
|
|
|
|
// useColor reports whether CLI output should be colorized for the given writer.
|
|
// Color is enabled only when the user hasn't disabled it (--no-color or the
|
|
// NO_COLOR convention) AND the destination is an interactive terminal — so
|
|
// piping or redirecting to a file yields clean text with no escape codes. When
|
|
// color is enabled it also ensures the terminal will interpret the sequences (a
|
|
// no-op outside Windows). The terminal setup is idempotent, so calling this on
|
|
// each render path is harmless.
|
|
func useColor(flags appFlags, w io.Writer) bool {
|
|
if flags.noColor || os.Getenv("NO_COLOR") != "" || !isTerminal(w) {
|
|
return false
|
|
}
|
|
enableVirtualTerminal(w)
|
|
return true
|
|
}
|
|
|
|
// isTerminal reports whether w is an interactive terminal/console rather than a
|
|
// pipe or regular file.
|
|
func isTerminal(w io.Writer) bool {
|
|
f, ok := w.(*os.File)
|
|
if !ok {
|
|
return false
|
|
}
|
|
return isatty.IsTerminal(f.Fd()) || isatty.IsCygwinTerminal(f.Fd())
|
|
}
|