Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <linux/kernel.h>
0003 #include <subcmd/pager.h>
0004 #include <string.h>
0005 #include "config.h"
0006 #include <stdlib.h>
0007 #include <stdio.h>
0008 #include "color.h"
0009 #include <math.h>
0010 #include <unistd.h>
0011 
0012 int perf_config_colorbool(const char *var, const char *value, int stdout_is_tty)
0013 {
0014     if (value) {
0015         if (!strcasecmp(value, "never"))
0016             return 0;
0017         if (!strcasecmp(value, "always"))
0018             return 1;
0019         if (!strcasecmp(value, "auto"))
0020             goto auto_color;
0021     }
0022 
0023     /* Missing or explicit false to turn off colorization */
0024     if (!perf_config_bool(var, value))
0025         return 0;
0026 
0027     /* any normal truth value defaults to 'auto' */
0028  auto_color:
0029     if (stdout_is_tty < 0)
0030         stdout_is_tty = isatty(1);
0031     if (stdout_is_tty || pager_in_use()) {
0032         char *term = getenv("TERM");
0033         if (term && strcmp(term, "dumb"))
0034             return 1;
0035     }
0036     return 0;
0037 }
0038 
0039 int perf_color_default_config(const char *var, const char *value,
0040                   void *cb __maybe_unused)
0041 {
0042     if (!strcmp(var, "color.ui")) {
0043         perf_use_color_default = perf_config_colorbool(var, value, -1);
0044         return 0;
0045     }
0046 
0047     return 0;
0048 }