Support color = auto

This is done using the test command as the stdlib lacks any way to
do this without using syscalls directly
This commit is contained in:
morganamilo 2018-09-27 16:50:59 +01:00
parent 9ac4ab6c25
commit e78070ebbe
No known key found for this signature in database
GPG key ID: 6FE9E7996B0B082E
2 changed files with 11 additions and 2 deletions

View file

@ -121,3 +121,10 @@ func passToGit(dir string, _args ...string) *exec.Cmd {
cmd := exec.Command(config.GitBin, args...)
return cmd
}
func isTty() bool {
cmd := exec.Command("test", "-t", "1")
cmd.Stdout = os.Stdout
err := cmd.Run()
return err == nil
}

View file

@ -146,12 +146,14 @@ func initAlpm() error {
return err
}
if value, _, _ := cmdArgs.getArg("color"); value == "always" || value == "auto" {
if value, _, _ := cmdArgs.getArg("color"); value == "always" {
useColor = true
} else if value == "auto" {
useColor = isTty()
} else if value == "never" {
useColor = false
} else {
useColor = pacmanConf.Color
useColor = pacmanConf.Color && isTty()
}
return nil