From: Vincent Bernat <vincent@bernat.im>
To: netdev@vger.kernel.org, Stephen Hemminger <stephen@networkplumber.org>
Cc: Vincent Bernat <vincent@bernat.im>
Subject: [PATCH iproute2-next] color: disable color when json output is requested
Date: Wed, 21 Feb 2018 00:28:04 +0100 [thread overview]
Message-ID: <20180220232804.10930-1-vincent@bernat.im> (raw)
Instead of declaring -color and -json exclusive, ignore -color when
-json is provided. The rationale is to allow to put -color in an alias
for ip while still being able to use -json. -color is merely a
presentation suggestion and we can assume there is nothing to color in
the JSON output.
Signed-off-by: Vincent Bernat <vincent@bernat.im>
---
include/color.h | 1 -
ip/ip.c | 7 ++++---
lib/color.c | 8 --------
3 files changed, 4 insertions(+), 12 deletions(-)
diff --git a/include/color.h b/include/color.h
index f6c351b77746..c80359d3e2e9 100644
--- a/include/color.h
+++ b/include/color.h
@@ -13,7 +13,6 @@ enum color_attr {
};
void enable_color(void);
-void check_if_color_enabled(void);
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 b15e6b66b3f6..ebf77aa2ee37 100644
--- a/ip/ip.c
+++ b/ip/ip.c
@@ -172,6 +172,7 @@ int main(int argc, char **argv)
{
char *basename;
char *batch_file = NULL;
+ int color = 0;
basename = strrchr(argv[0], '/');
if (basename == NULL)
@@ -273,7 +274,7 @@ int main(int argc, char **argv)
}
rcvbuf = size;
} else if (matches(opt, "-color") == 0) {
- enable_color();
+ ++color;
} else if (matches(opt, "-help") == 0) {
usage();
} else if (matches(opt, "-netns") == 0) {
@@ -293,8 +294,8 @@ int main(int argc, char **argv)
_SL_ = oneline ? "\\" : "\n";
- if (json)
- check_if_color_enabled();
+ if (color && !json)
+ enable_color();
if (batch_file)
return batch(batch_file);
diff --git a/lib/color.c b/lib/color.c
index a13a4930b10c..da1f516cb249 100644
--- a/lib/color.c
+++ b/lib/color.c
@@ -92,14 +92,6 @@ void set_color_palette(void)
is_dark_bg = 1;
}
-void check_if_color_enabled(void)
-{
- if (color_is_enabled) {
- fprintf(stderr, "Option \"-json\" conflicts with \"-color\".\n");
- exit(1);
- }
-}
-
int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...)
{
int ret = 0;
--
2.16.1
next reply other threads:[~2018-02-20 23:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-20 23:28 Vincent Bernat [this message]
2018-02-21 0:04 ` [PATCH iproute2-next] color: disable color when json output is requested Stephen Hemminger
2018-02-21 5:58 ` Vincent Bernat
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180220232804.10930-1-vincent@bernat.im \
--to=vincent@bernat.im \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).