]>
git.proxmox.com Git - mirror_iproute2.git/blob - lib/color.c
8d049a01ec0e462acbef11d60f86812070625ffc
5 #include <sys/socket.h>
29 static const char * const color_codes
[] = {
48 /* light background */
49 static enum color attr_colors_light
[] = {
60 static enum color attr_colors_dark
[] = {
70 static int is_dark_bg
;
71 static int color_is_enabled
;
73 void enable_color(void)
79 void set_color_palette(void)
81 char *p
= getenv("COLORFGBG");
84 * COLORFGBG environment variable usually contains either two or three
85 * values separated by semicolons; we want the last value in either case.
86 * If this value is 0-6 or 8, background is dark.
88 if (p
&& (p
= strrchr(p
, ';')) != NULL
89 && ((p
[1] >= '0' && p
[1] <= '6') || p
[1] == '8')
94 void check_if_color_enabled(void)
96 if (color_is_enabled
) {
97 fprintf(stderr
, "Option \"-json\" conflicts with \"-color\".\n");
102 int color_fprintf(FILE *fp
, enum color_attr attr
, const char *fmt
, ...)
109 if (!color_is_enabled
|| attr
== COLOR_NONE
) {
110 ret
= vfprintf(fp
, fmt
, args
);
114 ret
+= fprintf(fp
, "%s", color_codes
[is_dark_bg
?
115 attr_colors_dark
[attr
] : attr_colors_light
[attr
]]);
117 ret
+= vfprintf(fp
, fmt
, args
);
118 ret
+= fprintf(fp
, "%s", color_codes
[C_CLEAR
]);
125 enum color_attr
ifa_family_color(__u8 ifa_family
)
127 switch (ifa_family
) {
137 enum color_attr
oper_state_color(__u8 state
)
141 return COLOR_OPERSTATE_UP
;
143 return COLOR_OPERSTATE_DOWN
;