Merge branch 'master' into net-next
This commit is contained in:
commit
75209f840b
|
|
@ -2,14 +2,13 @@
|
||||||
#define __COLOR_H__ 1
|
#define __COLOR_H__ 1
|
||||||
|
|
||||||
enum color_attr {
|
enum color_attr {
|
||||||
COLOR_NONE,
|
|
||||||
COLOR_IFNAME,
|
COLOR_IFNAME,
|
||||||
COLOR_MAC,
|
COLOR_MAC,
|
||||||
COLOR_INET,
|
COLOR_INET,
|
||||||
COLOR_INET6,
|
COLOR_INET6,
|
||||||
COLOR_OPERSTATE_UP,
|
COLOR_OPERSTATE_UP,
|
||||||
COLOR_OPERSTATE_DOWN,
|
COLOR_OPERSTATE_DOWN,
|
||||||
COLOR_CLEAR
|
COLOR_NONE
|
||||||
};
|
};
|
||||||
|
|
||||||
void enable_color(void);
|
void enable_color(void);
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ void close_json_array(enum output_type type, const char *delim);
|
||||||
const char *fmt, \
|
const char *fmt, \
|
||||||
type value) \
|
type value) \
|
||||||
{ \
|
{ \
|
||||||
print_color_##type_name(t, -1, key, fmt, value); \
|
print_color_##type_name(t, COLOR_NONE, key, fmt, value); \
|
||||||
}
|
}
|
||||||
_PRINT_FUNC(int, int);
|
_PRINT_FUNC(int, int);
|
||||||
_PRINT_FUNC(bool, bool);
|
_PRINT_FUNC(bool, bool);
|
||||||
|
|
|
||||||
17
lib/color.c
17
lib/color.c
|
|
@ -45,8 +45,8 @@ static const char * const color_codes[] = {
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum color attr_colors[] = {
|
/* light background */
|
||||||
/* light background */
|
static enum color attr_colors_light[] = {
|
||||||
C_CYAN,
|
C_CYAN,
|
||||||
C_YELLOW,
|
C_YELLOW,
|
||||||
C_MAGENTA,
|
C_MAGENTA,
|
||||||
|
|
@ -54,8 +54,10 @@ static enum color attr_colors[] = {
|
||||||
C_GREEN,
|
C_GREEN,
|
||||||
C_RED,
|
C_RED,
|
||||||
C_CLEAR,
|
C_CLEAR,
|
||||||
|
};
|
||||||
|
|
||||||
/* dark background */
|
/* dark background */
|
||||||
|
static enum color attr_colors_dark[] = {
|
||||||
C_BOLD_CYAN,
|
C_BOLD_CYAN,
|
||||||
C_BOLD_YELLOW,
|
C_BOLD_YELLOW,
|
||||||
C_BOLD_MAGENTA,
|
C_BOLD_MAGENTA,
|
||||||
|
|
@ -109,8 +111,9 @@ int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...)
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret += fprintf(fp, "%s",
|
ret += fprintf(fp, "%s", color_codes[is_dark_bg ?
|
||||||
color_codes[attr_colors[is_dark_bg ? attr + 8 : attr]]);
|
attr_colors_dark[attr] : attr_colors_light[attr]]);
|
||||||
|
|
||||||
ret += vfprintf(fp, fmt, args);
|
ret += vfprintf(fp, fmt, args);
|
||||||
ret += fprintf(fp, "%s", color_codes[C_CLEAR]);
|
ret += fprintf(fp, "%s", color_codes[C_CLEAR]);
|
||||||
|
|
||||||
|
|
@ -127,7 +130,7 @@ enum color_attr ifa_family_color(__u8 ifa_family)
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
return COLOR_INET6;
|
return COLOR_INET6;
|
||||||
default:
|
default:
|
||||||
return COLOR_CLEAR;
|
return COLOR_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -139,6 +142,6 @@ enum color_attr oper_state_color(__u8 state)
|
||||||
case IF_OPER_DOWN:
|
case IF_OPER_DOWN:
|
||||||
return COLOR_OPERSTATE_DOWN;
|
return COLOR_OPERSTATE_DOWN;
|
||||||
default:
|
default:
|
||||||
return COLOR_CLEAR;
|
return COLOR_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
|
|
||||||
. lib/generic.sh
|
. lib/generic.sh
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue