Linux 5.1.15
[linux/fpc-iii.git] / tools / perf / util / color_config.c
blob817dc56e7e9588cb2c1826da2617e5808b0ac407
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/kernel.h>
3 #include "cache.h"
4 #include "config.h"
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include "color.h"
8 #include <math.h>
9 #include <unistd.h>
11 int perf_config_colorbool(const char *var, const char *value, int stdout_is_tty)
13 if (value) {
14 if (!strcasecmp(value, "never"))
15 return 0;
16 if (!strcasecmp(value, "always"))
17 return 1;
18 if (!strcasecmp(value, "auto"))
19 goto auto_color;
22 /* Missing or explicit false to turn off colorization */
23 if (!perf_config_bool(var, value))
24 return 0;
26 /* any normal truth value defaults to 'auto' */
27 auto_color:
28 if (stdout_is_tty < 0)
29 stdout_is_tty = isatty(1);
30 if (stdout_is_tty || pager_in_use()) {
31 char *term = getenv("TERM");
32 if (term && strcmp(term, "dumb"))
33 return 1;
35 return 0;
38 int perf_color_default_config(const char *var, const char *value,
39 void *cb __maybe_unused)
41 if (!strcmp(var, "color.ui")) {
42 perf_use_color_default = perf_config_colorbool(var, value, -1);
43 return 0;
46 return 0;