mirror of
https://github.com/Jguer/yay
synced 2024-09-14 13:51:12 +00:00
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:
parent
9ac4ab6c25
commit
e78070ebbe
7
exec.go
7
exec.go
|
@ -121,3 +121,10 @@ func passToGit(dir string, _args ...string) *exec.Cmd {
|
||||||
cmd := exec.Command(config.GitBin, args...)
|
cmd := exec.Command(config.GitBin, args...)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isTty() bool {
|
||||||
|
cmd := exec.Command("test", "-t", "1")
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
err := cmd.Run()
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
|
|
6
main.go
6
main.go
|
@ -146,12 +146,14 @@ func initAlpm() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if value, _, _ := cmdArgs.getArg("color"); value == "always" || value == "auto" {
|
if value, _, _ := cmdArgs.getArg("color"); value == "always" {
|
||||||
useColor = true
|
useColor = true
|
||||||
|
} else if value == "auto" {
|
||||||
|
useColor = isTty()
|
||||||
} else if value == "never" {
|
} else if value == "never" {
|
||||||
useColor = false
|
useColor = false
|
||||||
} else {
|
} else {
|
||||||
useColor = pacmanConf.Color
|
useColor = pacmanConf.Color && isTty()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in a new issue