Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Support `NO_COLOR' environment variable
Suppress color if the `NO_COLOR' environment variable is is present.
For more information, visit `https://no-color.org/'.
  • Loading branch information
flimberger committed Oct 31, 2018
1 parent a8aed64 commit 785e560
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions alogview.go
Expand Up @@ -86,20 +86,21 @@ func main() {
if len(*s) > 0 {
adbargs = append(adbargs, "-s", *s)
}
_, suppresscolor := os.LookupEnv("NO_COLOR")
if len(flag.Args()) == 0 {
processLogs(func(line *logLine) bool { return true })
processLogs(func(line *logLine) bool { return true }, suppresscolor)
} else {
packages := make(map[string]bool)

for _, pkg := range os.Args {
packages[pkg] = true
}
pids := getProcs(packages)
processLogs(func(line *logLine) bool { return filterByPackages(line, packages, pids) })
processLogs(func(line *logLine) bool { return filterByPackages(line, packages, pids) }, suppresscolor)
}
}

func processLogs(filter filter) {
func processLogs(filter filter, suppresscolor bool) {
r, w := io.Pipe()

go runADB(w, "logcat")
Expand All @@ -119,7 +120,11 @@ func processLogs(filter filter) {
continue
}
if filter(msg) {
fmt.Printf("%s%s%s\n", colorForLevel(msg.level), line, reset)
if suppresscolor {
fmt.Printf("%s\n", line)
} else {
fmt.Printf("%s%s%s\n", colorForLevel(msg.level), line, reset)
}
}
}
}
Expand Down

0 comments on commit 785e560

Please sign in to comment.