Make colored output configurable
This commit is contained in:
parent
81eb9cb3c9
commit
941d2e148b
33
0003-tc-Fix-typo-in-check-for-colored-output.patch
Normal file
33
0003-tc-Fix-typo-in-check-for-colored-output.patch
Normal file
@ -0,0 +1,33 @@
|
||||
From 1824d687058b2c818ae057321d7ca67de46b0fbb Mon Sep 17 00:00:00 2001
|
||||
From: Phil Sutter <phil@nwl.cc>
|
||||
Date: Wed, 15 Aug 2018 18:21:24 +0200
|
||||
Subject: [PATCH] tc: Fix typo in check for colored output
|
||||
|
||||
The check used binary instead of boolean AND, which means colored output
|
||||
was enabled only if the number of specified '-color' flags was odd.
|
||||
|
||||
Fixes: 2d165c0811058 ("tc: implement color output")
|
||||
Signed-off-by: Phil Sutter <phil@nwl.cc>
|
||||
Signed-off-by: David Ahern <dsahern@gmail.com>
|
||||
(cherry picked from commit 0d0e0e0bef68f888bedb8d8f343baa943207dafc)
|
||||
Signed-off-by: Phil Sutter <psutter@redhat.com>
|
||||
---
|
||||
tc/tc.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/tc/tc.c b/tc/tc.c
|
||||
index 3bb5910ffac52..3bb893756f40e 100644
|
||||
--- a/tc/tc.c
|
||||
+++ b/tc/tc.c
|
||||
@@ -515,7 +515,7 @@ int main(int argc, char **argv)
|
||||
|
||||
_SL_ = oneline ? "\\" : "\n";
|
||||
|
||||
- if (color & !json)
|
||||
+ if (color && !json)
|
||||
enable_color();
|
||||
|
||||
if (batch_file)
|
||||
--
|
||||
2.18.0
|
||||
|
35
0004-bridge-Fix-check-for-colored-output.patch
Normal file
35
0004-bridge-Fix-check-for-colored-output.patch
Normal file
@ -0,0 +1,35 @@
|
||||
From 02a126e40fce4fe03fdc9ce39bd3d9ff20dd1fb0 Mon Sep 17 00:00:00 2001
|
||||
From: Phil Sutter <phil@nwl.cc>
|
||||
Date: Wed, 15 Aug 2018 18:21:25 +0200
|
||||
Subject: [PATCH] bridge: Fix check for colored output
|
||||
|
||||
There is no point in calling enable_color() conditionally if it was
|
||||
already called for each time '-color' flag was parsed. Align the
|
||||
algorithm with that in ip and tc by actually making use of 'color'
|
||||
variable.
|
||||
|
||||
Fixes: e9625d6aead11 ("Merge branch 'iproute2-master' into iproute2-next")
|
||||
Signed-off-by: Phil Sutter <phil@nwl.cc>
|
||||
Signed-off-by: David Ahern <dsahern@gmail.com>
|
||||
(cherry picked from commit 5332148debeadcf52cc157ef1dd0a377dd482517)
|
||||
Signed-off-by: Phil Sutter <psutter@redhat.com>
|
||||
---
|
||||
bridge/bridge.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/bridge/bridge.c b/bridge/bridge.c
|
||||
index 7fcfe1116f6e5..289a157d37f03 100644
|
||||
--- a/bridge/bridge.c
|
||||
+++ b/bridge/bridge.c
|
||||
@@ -174,7 +174,7 @@ main(int argc, char **argv)
|
||||
if (netns_switch(argv[1]))
|
||||
exit(-1);
|
||||
} else if (matches(opt, "-color") == 0) {
|
||||
- enable_color();
|
||||
+ ++color;
|
||||
} else if (matches(opt, "-compressvlans") == 0) {
|
||||
++compress_vlans;
|
||||
} else if (matches(opt, "-force") == 0) {
|
||||
--
|
||||
2.18.0
|
||||
|
@ -0,0 +1,97 @@
|
||||
From 9aef957dfc6c46468b6469d4e0e275011546753b Mon Sep 17 00:00:00 2001
|
||||
From: Phil Sutter <phil@nwl.cc>
|
||||
Date: Wed, 15 Aug 2018 18:21:26 +0200
|
||||
Subject: [PATCH] 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>
|
||||
(cherry picked from commit 4d82962cccc6a6b543fa2110e81621c51441f0dd)
|
||||
Signed-off-by: Phil Sutter <psutter@redhat.com>
|
||||
---
|
||||
bridge/bridge.c | 3 +--
|
||||
include/color.h | 1 +
|
||||
ip/ip.c | 3 +--
|
||||
lib/color.c | 9 +++++++++
|
||||
tc/tc.c | 3 +--
|
||||
5 files changed, 13 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/bridge/bridge.c b/bridge/bridge.c
|
||||
index 289a157d37f03..451d684e0bcfd 100644
|
||||
--- a/bridge/bridge.c
|
||||
+++ b/bridge/bridge.c
|
||||
@@ -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);
|
||||
diff --git a/include/color.h b/include/color.h
|
||||
index c80359d3e2e95..4f2c918db7e43 100644
|
||||
--- a/include/color.h
|
||||
+++ b/include/color.h
|
||||
@@ -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);
|
||||
diff --git a/ip/ip.c b/ip/ip.c
|
||||
index 71d5170c0cc23..38eac5ec1e17d 100644
|
||||
--- a/ip/ip.c
|
||||
+++ b/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);
|
||||
diff --git a/lib/color.c b/lib/color.c
|
||||
index da1f516cb2492..edf96e5c6ecd7 100644
|
||||
--- a/lib/color.c
|
||||
+++ b/lib/color.c
|
||||
@@ -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");
|
||||
diff --git a/tc/tc.c b/tc/tc.c
|
||||
index 3bb893756f40e..e775550174473 100644
|
||||
--- a/tc/tc.c
|
||||
+++ b/tc/tc.c
|
||||
@@ -515,8 +515,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);
|
||||
--
|
||||
2.18.0
|
||||
|
233
0006-Make-colored-output-configurable.patch
Normal file
233
0006-Make-colored-output-configurable.patch
Normal file
@ -0,0 +1,233 @@
|
||||
From 889c7c942e23c77118ed5cdb610f53c13a5bfea8 Mon Sep 17 00:00:00 2001
|
||||
From: Phil Sutter <phil@nwl.cc>
|
||||
Date: Fri, 17 Aug 2018 18:38:45 +0200
|
||||
Subject: [PATCH] Make colored output configurable
|
||||
|
||||
Allow for -color={never,auto,always} to have colored output disabled,
|
||||
enabled only if stdout is a terminal or enabled regardless of stdout
|
||||
state.
|
||||
|
||||
Signed-off-by: Phil Sutter <phil@nwl.cc>
|
||||
Reviewed-by: David Ahern <dsahern@gmail.com>
|
||||
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
|
||||
(cherry picked from commit ff1ab8edf827f55b86c6487c90b7454975d52236)
|
||||
Signed-off-by: Phil Sutter <psutter@redhat.com>
|
||||
---
|
||||
bridge/bridge.c | 3 +--
|
||||
include/color.h | 9 +++++++++
|
||||
ip/ip.c | 3 +--
|
||||
lib/color.c | 33 ++++++++++++++++++++++++++++++++-
|
||||
man/man8/bridge.8 | 13 +++++++++++--
|
||||
man/man8/ip.8 | 13 +++++++++++--
|
||||
man/man8/tc.8 | 13 +++++++++++--
|
||||
tc/tc.c | 3 +--
|
||||
8 files changed, 77 insertions(+), 13 deletions(-)
|
||||
|
||||
diff --git a/bridge/bridge.c b/bridge/bridge.c
|
||||
index 451d684e0bcfd..263fa5397a623 100644
|
||||
--- a/bridge/bridge.c
|
||||
+++ b/bridge/bridge.c
|
||||
@@ -173,8 +173,7 @@ main(int argc, char **argv)
|
||||
NEXT_ARG();
|
||||
if (netns_switch(argv[1]))
|
||||
exit(-1);
|
||||
- } else if (matches(opt, "-color") == 0) {
|
||||
- ++color;
|
||||
+ } else if (matches_color(opt, &color)) {
|
||||
} else if (matches(opt, "-compressvlans") == 0) {
|
||||
++compress_vlans;
|
||||
} else if (matches(opt, "-force") == 0) {
|
||||
diff --git a/include/color.h b/include/color.h
|
||||
index 4f2c918db7e43..a22a00c2277e0 100644
|
||||
--- a/include/color.h
|
||||
+++ b/include/color.h
|
||||
@@ -2,6 +2,8 @@
|
||||
#ifndef __COLOR_H__
|
||||
#define __COLOR_H__ 1
|
||||
|
||||
+#include <stdbool.h>
|
||||
+
|
||||
enum color_attr {
|
||||
COLOR_IFNAME,
|
||||
COLOR_MAC,
|
||||
@@ -12,8 +14,15 @@ enum color_attr {
|
||||
COLOR_NONE
|
||||
};
|
||||
|
||||
+enum color_opt {
|
||||
+ COLOR_OPT_NEVER = 0,
|
||||
+ COLOR_OPT_AUTO = 1,
|
||||
+ COLOR_OPT_ALWAYS = 2
|
||||
+};
|
||||
+
|
||||
void enable_color(void);
|
||||
int check_enable_color(int color, int json);
|
||||
+bool matches_color(const char *arg, int *val);
|
||||
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);
|
||||
diff --git a/ip/ip.c b/ip/ip.c
|
||||
index 38eac5ec1e17d..4fe471d99dc97 100644
|
||||
--- a/ip/ip.c
|
||||
+++ b/ip/ip.c
|
||||
@@ -283,8 +283,7 @@ int main(int argc, char **argv)
|
||||
exit(-1);
|
||||
}
|
||||
rcvbuf = size;
|
||||
- } else if (matches(opt, "-color") == 0) {
|
||||
- ++color;
|
||||
+ } else if (matches_color(opt, &color)) {
|
||||
} else if (matches(opt, "-help") == 0) {
|
||||
usage();
|
||||
} else if (matches(opt, "-netns") == 0) {
|
||||
diff --git a/lib/color.c b/lib/color.c
|
||||
index edf96e5c6ecd7..9c9023587748f 100644
|
||||
--- a/lib/color.c
|
||||
+++ b/lib/color.c
|
||||
@@ -3,11 +3,13 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
+#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <linux/if.h>
|
||||
|
||||
#include "color.h"
|
||||
+#include "utils.h"
|
||||
|
||||
enum color {
|
||||
C_RED,
|
||||
@@ -79,13 +81,42 @@ void enable_color(void)
|
||||
|
||||
int check_enable_color(int color, int json)
|
||||
{
|
||||
- if (color && !json) {
|
||||
+ if (json || color == COLOR_OPT_NEVER)
|
||||
+ return 1;
|
||||
+
|
||||
+ if (color == COLOR_OPT_ALWAYS || isatty(fileno(stdout))) {
|
||||
enable_color();
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
+bool matches_color(const char *arg, int *val)
|
||||
+{
|
||||
+ char *dup, *p;
|
||||
+
|
||||
+ if (!val)
|
||||
+ return false;
|
||||
+
|
||||
+ dup = strdupa(arg);
|
||||
+ p = strchrnul(dup, '=');
|
||||
+ if (*p)
|
||||
+ *(p++) = '\0';
|
||||
+
|
||||
+ if (matches(dup, "-color"))
|
||||
+ return false;
|
||||
+
|
||||
+ if (*p == '\0' || !strcmp(p, "always"))
|
||||
+ *val = COLOR_OPT_ALWAYS;
|
||||
+ else if (!strcmp(p, "auto"))
|
||||
+ *val = COLOR_OPT_AUTO;
|
||||
+ else if (!strcmp(p, "never"))
|
||||
+ *val = COLOR_OPT_NEVER;
|
||||
+ else
|
||||
+ return false;
|
||||
+ return true;
|
||||
+}
|
||||
+
|
||||
void set_color_palette(void)
|
||||
{
|
||||
char *p = getenv("COLORFGBG");
|
||||
diff --git a/man/man8/bridge.8 b/man/man8/bridge.8
|
||||
index e7f7148315e19..9684169844f36 100644
|
||||
--- a/man/man8/bridge.8
|
||||
+++ b/man/man8/bridge.8
|
||||
@@ -170,8 +170,17 @@ If there were any errors during execution of the commands, the application
|
||||
return code will be non zero.
|
||||
|
||||
.TP
|
||||
-.BR "\-c" , " -color"
|
||||
-Use color output.
|
||||
+.BR \-c [ color ][ = { always | auto | never }
|
||||
+Configure color output. If parameter is omitted or
|
||||
+.BR always ,
|
||||
+color output is enabled regardless of stdout state. If parameter is
|
||||
+.BR auto ,
|
||||
+stdout is checked to be a terminal before enabling color output. If parameter is
|
||||
+.BR never ,
|
||||
+color output is disabled. If specified multiple times, the last one takes
|
||||
+precedence. This flag is ignored if
|
||||
+.B \-json
|
||||
+is also given.
|
||||
|
||||
.TP
|
||||
.BR "\-j", " \-json"
|
||||
diff --git a/man/man8/ip.8 b/man/man8/ip.8
|
||||
index 0087d18b74706..1d358879ec39c 100644
|
||||
--- a/man/man8/ip.8
|
||||
+++ b/man/man8/ip.8
|
||||
@@ -187,8 +187,17 @@ to
|
||||
executes specified command over all objects, it depends if command supports this option.
|
||||
|
||||
.TP
|
||||
-.BR "\-c" , " -color"
|
||||
-Use color output.
|
||||
+.BR \-c [ color ][ = { always | auto | never }
|
||||
+Configure color output. If parameter is omitted or
|
||||
+.BR always ,
|
||||
+color output is enabled regardless of stdout state. If parameter is
|
||||
+.BR auto ,
|
||||
+stdout is checked to be a terminal before enabling color output. If parameter is
|
||||
+.BR never ,
|
||||
+color output is disabled. If specified multiple times, the last one takes
|
||||
+precedence. This flag is ignored if
|
||||
+.B \-json
|
||||
+is also given.
|
||||
|
||||
.TP
|
||||
.BR "\-t" , " \-timestamp"
|
||||
diff --git a/man/man8/tc.8 b/man/man8/tc.8
|
||||
index 840880fbdba63..a5849a776c592 100644
|
||||
--- a/man/man8/tc.8
|
||||
+++ b/man/man8/tc.8
|
||||
@@ -729,8 +729,17 @@ option was specified. Classes can be filtered only by
|
||||
option.
|
||||
|
||||
.TP
|
||||
-.BR "\ -color"
|
||||
-Use color output.
|
||||
+.BR \-c [ color ][ = { always | auto | never }
|
||||
+Configure color output. If parameter is omitted or
|
||||
+.BR always ,
|
||||
+color output is enabled regardless of stdout state. If parameter is
|
||||
+.BR auto ,
|
||||
+stdout is checked to be a terminal before enabling color output. If parameter is
|
||||
+.BR never ,
|
||||
+color output is disabled. If specified multiple times, the last one takes
|
||||
+precedence. This flag is ignored if
|
||||
+.B \-json
|
||||
+is also given.
|
||||
|
||||
.TP
|
||||
.BR "\-j", " \-json"
|
||||
diff --git a/tc/tc.c b/tc/tc.c
|
||||
index e775550174473..586db30cb87c2 100644
|
||||
--- a/tc/tc.c
|
||||
+++ b/tc/tc.c
|
||||
@@ -493,8 +493,7 @@ int main(int argc, char **argv)
|
||||
matches(argv[1], "-conf") == 0) {
|
||||
NEXT_ARG();
|
||||
conf_file = argv[1];
|
||||
- } else if (matches(argv[1], "-color") == 0) {
|
||||
- ++color;
|
||||
+ } else if (matches_color(argv[1], &color)) {
|
||||
} else if (matches(argv[1], "-timestamp") == 0) {
|
||||
timestamp++;
|
||||
} else if (matches(argv[1], "-tshort") == 0) {
|
||||
--
|
||||
2.18.0
|
||||
|
59
0007-lib-Make-check_enable_color-return-boolean.patch
Normal file
59
0007-lib-Make-check_enable_color-return-boolean.patch
Normal file
@ -0,0 +1,59 @@
|
||||
From 028f717e06d8496e15de6c4eaef3ecd88bd9c8d0 Mon Sep 17 00:00:00 2001
|
||||
From: Phil Sutter <phil@nwl.cc>
|
||||
Date: Fri, 17 Aug 2018 18:38:46 +0200
|
||||
Subject: [PATCH] lib: Make check_enable_color() return boolean
|
||||
|
||||
As suggested, turn return code into true/false although it's not checked
|
||||
anywhere yet.
|
||||
|
||||
Fixes: 4d82962cccc6a ("Merge common code for conditionally colored output")
|
||||
Signed-off-by: Phil Sutter <phil@nwl.cc>
|
||||
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
|
||||
(cherry picked from commit 515a766cd29bbed8a180733e93bc8590b001cad7)
|
||||
Signed-off-by: Phil Sutter <psutter@redhat.com>
|
||||
---
|
||||
include/color.h | 2 +-
|
||||
lib/color.c | 8 ++++----
|
||||
2 files changed, 5 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/include/color.h b/include/color.h
|
||||
index a22a00c2277e0..e30f28c51c844 100644
|
||||
--- a/include/color.h
|
||||
+++ b/include/color.h
|
||||
@@ -21,7 +21,7 @@ enum color_opt {
|
||||
};
|
||||
|
||||
void enable_color(void);
|
||||
-int check_enable_color(int color, int json);
|
||||
+bool check_enable_color(int color, int json);
|
||||
bool matches_color(const char *arg, int *val);
|
||||
void set_color_palette(void);
|
||||
int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...);
|
||||
diff --git a/lib/color.c b/lib/color.c
|
||||
index 9c9023587748f..eaf69e74d673a 100644
|
||||
--- a/lib/color.c
|
||||
+++ b/lib/color.c
|
||||
@@ -79,16 +79,16 @@ void enable_color(void)
|
||||
set_color_palette();
|
||||
}
|
||||
|
||||
-int check_enable_color(int color, int json)
|
||||
+bool check_enable_color(int color, int json)
|
||||
{
|
||||
if (json || color == COLOR_OPT_NEVER)
|
||||
- return 1;
|
||||
+ return false;
|
||||
|
||||
if (color == COLOR_OPT_ALWAYS || isatty(fileno(stdout))) {
|
||||
enable_color();
|
||||
- return 0;
|
||||
+ return true;
|
||||
}
|
||||
- return 1;
|
||||
+ return false;
|
||||
}
|
||||
|
||||
bool matches_color(const char *arg, int *val)
|
||||
--
|
||||
2.18.0
|
||||
|
11
iproute.spec
11
iproute.spec
@ -2,7 +2,7 @@
|
||||
Summary: Advanced IP routing and network device configuration tools
|
||||
Name: iproute
|
||||
Version: 4.18.0
|
||||
Release: 2%{?dist}
|
||||
Release: 3%{?dist}
|
||||
Group: Applications/System
|
||||
URL: http://kernel.org/pub/linux/utils/net/%{name}2/
|
||||
Source0: http://kernel.org/pub/linux/utils/net/%{name}2/%{name}2-%{version}.tar.xz
|
||||
@ -15,6 +15,12 @@ Source2: avpkt
|
||||
Patch1: 0001-Add-cbq.8-as-an-alias-to-tc-cbq.8.patch
|
||||
# Fix for bz#1615373
|
||||
Patch2: 0002-ss-Review-ssfilter.patch
|
||||
# Fix for bz#1582898
|
||||
Patch3: 0003-tc-Fix-typo-in-check-for-colored-output.patch
|
||||
Patch4: 0004-bridge-Fix-check-for-colored-output.patch
|
||||
Patch5: 0005-Merge-common-code-for-conditionally-colored-output.patch
|
||||
Patch6: 0006-Make-colored-output-configurable.patch
|
||||
Patch7: 0007-lib-Make-check_enable_color-return-boolean.patch
|
||||
|
||||
License: GPLv2+ and Public Domain
|
||||
BuildRequires: gcc
|
||||
@ -161,6 +167,9 @@ rm -rf '%{buildroot}%{_docdir}'
|
||||
%{_includedir}/iproute2/bpf_elf.h
|
||||
|
||||
%changelog
|
||||
* Thu Aug 23 2018 Phil Sutter <psutter@redhat.com> - 4.18.0-3
|
||||
- Make colored output configurable
|
||||
|
||||
* Thu Aug 16 2018 Phil Sutter <psutter@redhat.com> - 4.18.0-2
|
||||
- Fix ss filter expressions
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user