Permalink
Browse files

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 785e5608711d92a1c41733f9ecfa3ed2d335a940
Showing with 9 additions and 4 deletions.
  1. +9 −4 alogview.go
View
@@ -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")
@@ -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)
}
}
}
}

0 comments on commit 785e560

Please sign in to comment.