mirror of
https://github.com/Jguer/yay
synced 2024-10-31 04:12:51 +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
2 changed files with 11 additions and 2 deletions
7
exec.go
7
exec.go
|
@ -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
|
||||
}
|
||||
|
|
6
main.go
6
main.go
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue