.. | .. |
---|
1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
---|
2 | 2 | #include <linux/kernel.h> |
---|
3 | | -#include "cache.h" |
---|
4 | | -#include "config.h" |
---|
| 3 | +#include <subcmd/pager.h> |
---|
5 | 4 | #include <stdlib.h> |
---|
6 | 5 | #include <stdio.h> |
---|
| 6 | +#include <string.h> |
---|
7 | 7 | #include "color.h" |
---|
8 | 8 | #include <math.h> |
---|
9 | 9 | #include <unistd.h> |
---|
10 | 10 | |
---|
11 | 11 | int perf_use_color_default = -1; |
---|
12 | | - |
---|
13 | | -int perf_config_colorbool(const char *var, const char *value, int stdout_is_tty) |
---|
14 | | -{ |
---|
15 | | - if (value) { |
---|
16 | | - if (!strcasecmp(value, "never")) |
---|
17 | | - return 0; |
---|
18 | | - if (!strcasecmp(value, "always")) |
---|
19 | | - return 1; |
---|
20 | | - if (!strcasecmp(value, "auto")) |
---|
21 | | - goto auto_color; |
---|
22 | | - } |
---|
23 | | - |
---|
24 | | - /* Missing or explicit false to turn off colorization */ |
---|
25 | | - if (!perf_config_bool(var, value)) |
---|
26 | | - return 0; |
---|
27 | | - |
---|
28 | | - /* any normal truth value defaults to 'auto' */ |
---|
29 | | - auto_color: |
---|
30 | | - if (stdout_is_tty < 0) |
---|
31 | | - stdout_is_tty = isatty(1); |
---|
32 | | - if (stdout_is_tty || pager_in_use()) { |
---|
33 | | - char *term = getenv("TERM"); |
---|
34 | | - if (term && strcmp(term, "dumb")) |
---|
35 | | - return 1; |
---|
36 | | - } |
---|
37 | | - return 0; |
---|
38 | | -} |
---|
39 | | - |
---|
40 | | -int perf_color_default_config(const char *var, const char *value, |
---|
41 | | - void *cb __maybe_unused) |
---|
42 | | -{ |
---|
43 | | - if (!strcmp(var, "color.ui")) { |
---|
44 | | - perf_use_color_default = perf_config_colorbool(var, value, -1); |
---|
45 | | - return 0; |
---|
46 | | - } |
---|
47 | | - |
---|
48 | | - return 0; |
---|
49 | | -} |
---|
50 | 12 | |
---|
51 | 13 | static int __color_vsnprintf(char *bf, size_t size, const char *color, |
---|
52 | 14 | const char *fmt, va_list args, const char *trail) |
---|