Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support color = auto #739

Merged
merged 1 commit into from
Sep 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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