tools/pw-dump: only print colors if we're connected to a terminal

We don't want ansi escape codes in the output of `pw-dump > log`. And where
colors are needed after the fact, it's easy to just run `jq . $file`.
This commit is contained in:
Peter Hutterer 2021-05-07 10:47:41 +10:00 committed by Wim Taymans
parent 65e14548a3
commit af63d08453

View file

@ -1429,7 +1429,7 @@ int main(int argc, char *argv[])
pw_init(&argc, &argv);
data.out = stdout;
if (getenv("NO_COLOR") == NULL)
if (isatty(fileno(data.out) && getenv("NO_COLOR") == NULL))
colors = true;
while ((c = getopt_long(argc, argv, "hVr:mN", long_options, NULL)) != -1) {