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")

This comment has been minimized.

Copy link
@Sasasu

Sasasu May 21, 2019

I don't sure execl("test", "-t", "1", NULL) will work or not when $PATH is empty (like in systemd service).

I think it will not work.

use mattn/go-isatty is another bad idea, mattn/go-isatty do not use isatty in libc, $LD_PRELOAD will not work.

This comment has been minimized.

Copy link
@Morganamilo

Morganamilo May 21, 2019

Author Contributor

If path is empty then our calls to: sudo, pacman, makepkg, tar and whatever else are also likely to fail. I'm sure whoever writes a service file can also configure it to have PATH available.

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.