2 #include <linux/kernel.h> 16 if (!strcasecmp(value,
"never"))
18 if (!strcasecmp(value,
"always"))
20 if (!strcasecmp(value,
"auto"))
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"))
41 void *cb __maybe_unused)
43 if (!strcmp(var,
"color.ui")) {
52 const char *
fmt, va_list
args,
const char *trail)
60 if (isatty(1) || pager_in_use())
67 r += scnprintf(bf, size,
"%s", color);
68 r += vscnprintf(bf + r, size - r, fmt, args);
72 r += scnprintf(bf + r, size - r,
"%s", trail);
86 if (isatty(fileno(fp)) || pager_in_use())
93 fprintf(fp,
"%s", color);
94 r += vfprintf(fp, fmt, args);
112 const char *
fmt, ...)
140 size_t count,
const char *buf)
143 return fwrite(buf, count, 1, fp) != 1;
146 char *p = memchr(buf,
'\n', count);
148 if (p != buf && (fputs(color, fp) < 0 ||
149 fwrite(buf, p ? (
size_t)(p - buf) : count, 1, fp) != 1 ||
154 if (fputc(
'\n', fp) < 0)
156 count -= p + 1 - buf;
203 percent = va_arg(args,
double);
216 len = va_arg(args,
int);
217 percent = va_arg(args,
double);
const char * get_percent_color(double percent)
int color_fprintf(FILE *fp, const char *color, const char *fmt,...)
int perf_config_colorbool(const char *var, const char *value, int stdout_is_tty)
int perf_config_bool(const char *name, const char *value)
int perf_color_default_config(const char *var, const char *value, void *cb __maybe_unused)
static int term(yyscan_t scanner, int type)
#define PERF_COLOR_NORMAL
int color_vsnprintf(char *bf, size_t size, const char *color, const char *fmt, va_list args)
int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf)
static int __color_vfprintf(FILE *fp, const char *color, const char *fmt, va_list args)
int percent_color_fprintf(FILE *fp, const char *fmt, double percent)
static int __color_vsnprintf(char *bf, size_t size, const char *color, const char *fmt, va_list args, const char *trail)
int color_vfprintf(FILE *fp, const char *color, const char *fmt, va_list args)
int value_color_snprintf(char *bf, size_t size, const char *fmt, double value)
static double percent(int st, int tot)
int color_snprintf(char *bf, size_t size, const char *color, const char *fmt,...)
int percent_color_snprintf(char *bf, size_t size, const char *fmt,...)
int percent_color_len_snprintf(char *bf, size_t size, const char *fmt,...)
int perf_use_color_default