Explorar o código

Support color = auto

This is done using the test command as the stdlib lacks any way to
do this without using syscalls directly
morganamilo %!s(int64=6) %!d(string=hai) anos
pai
achega
e78070ebbe
Modificáronse 2 ficheiros con 11 adicións e 2 borrados
  1. 7 0
      exec.go
  2. 4 2
      main.go

+ 7 - 0
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
+}

+ 4 - 2
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