mirror of
https://git.kernel.org/pub/scm/network/iproute2/iproute2.git
synced 2024-11-15 14:05:22 +08:00
Merge common code for conditionally colored output
Instead of calling enable_color() conditionally with identical check in three places, introduce check_enable_color() which does it in one place. Signed-off-by: Phil Sutter <phil@nwl.cc> Signed-off-by: David Ahern <dsahern@gmail.com>
This commit is contained in:
parent
5332148deb
commit
4d82962ccc
@ -200,8 +200,7 @@ main(int argc, char **argv)
|
||||
|
||||
_SL_ = oneline ? "\\" : "\n";
|
||||
|
||||
if (color && !json)
|
||||
enable_color();
|
||||
check_enable_color(color, json);
|
||||
|
||||
if (batch_file)
|
||||
return batch(batch_file);
|
||||
|
@ -13,6 +13,7 @@ enum color_attr {
|
||||
};
|
||||
|
||||
void enable_color(void);
|
||||
int check_enable_color(int color, int json);
|
||||
void set_color_palette(void);
|
||||
int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...);
|
||||
enum color_attr ifa_family_color(__u8 ifa_family);
|
||||
|
3
ip/ip.c
3
ip/ip.c
@ -304,8 +304,7 @@ int main(int argc, char **argv)
|
||||
|
||||
_SL_ = oneline ? "\\" : "\n";
|
||||
|
||||
if (color && !json)
|
||||
enable_color();
|
||||
check_enable_color(color, json);
|
||||
|
||||
if (batch_file)
|
||||
return batch(batch_file);
|
||||
|
@ -77,6 +77,15 @@ void enable_color(void)
|
||||
set_color_palette();
|
||||
}
|
||||
|
||||
int check_enable_color(int color, int json)
|
||||
{
|
||||
if (color && !json) {
|
||||
enable_color();
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void set_color_palette(void)
|
||||
{
|
||||
char *p = getenv("COLORFGBG");
|
||||
|
Loading…
Reference in New Issue
Block a user