Skip to content

Commit

Permalink
Support color = auto
Browse files Browse the repository at this point in the history
This is done using the test command as the stdlib lacks any way to
do this without using syscalls directly
  • Loading branch information
Morganamilo committed Sep 27, 2018
1 parent 9ac4ab6 commit e78070e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 7 additions & 0 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e78070e

Please sign in to comment.