netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Petr Vorel <petr.vorel@gmail.com>
To: netdev@vger.kernel.org
Cc: Petr Vorel <petr.vorel@gmail.com>,
	Julien Fortin <julien@cumulusnetworks.com>,
	Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH iproute2 v2 3/4] color: Cleanup code to remove "magic" offset + 7
Date: Fri, 13 Oct 2017 15:57:18 +0200	[thread overview]
Message-ID: <20171013135719.18450-4-petr.vorel@gmail.com> (raw)
In-Reply-To: <20171013135719.18450-1-petr.vorel@gmail.com>

Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
---
 lib/color.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/color.c b/lib/color.c
index 05afcb21..497f5e1b 100644
--- a/lib/color.c
+++ b/lib/color.c
@@ -45,8 +45,8 @@ static const char * const color_codes[] = {
 	NULL,
 };
 
-static enum color attr_colors[] = {
-	/* light background */
+/* light background */
+static enum color attr_colors_light[] = {
 	C_CYAN,
 	C_YELLOW,
 	C_MAGENTA,
@@ -54,8 +54,10 @@ static enum color attr_colors[] = {
 	C_GREEN,
 	C_RED,
 	C_CLEAR,
+};
 
-	/* dark background */
+/* dark background */
+static enum color attr_colors_dark[] = {
 	C_BOLD_CYAN,
 	C_BOLD_YELLOW,
 	C_BOLD_MAGENTA,
@@ -109,8 +111,9 @@ int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...)
 		goto end;
 	}
 
-	ret += fprintf(fp, "%s",
-		       color_codes[attr_colors[is_dark_bg ? attr + 7 : attr]]);
+	ret += fprintf(fp, "%s", color_codes[is_dark_bg ?
+		attr_colors_dark[attr] : attr_colors_light[attr]]);
+
 	ret += vfprintf(fp, fmt, args);
 	ret += fprintf(fp, "%s", color_codes[C_CLEAR]);
 
-- 
2.14.2

  parent reply	other threads:[~2017-10-13 13:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-13 13:57 [PATCH iproute2 v2 0/4] Fix ip segfault when using --color switch Petr Vorel
2017-10-13 13:57 ` [PATCH iproute2 v2 1/4] color: " Petr Vorel
2017-10-13 13:57 ` [PATCH iproute2 v2 2/4] color: Fix another " Petr Vorel
2017-10-13 13:57 ` Petr Vorel [this message]
2017-10-13 13:57 ` [PATCH iproute2 v2 4/4] color: Rename enum Petr Vorel
2017-10-16 16:24 ` [PATCH iproute2 v2 0/4] Fix ip segfault when using --color switch Stephen Hemminger

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=20171013135719.18450-4-petr.vorel@gmail.com \
    --to=petr.vorel@gmail.com \
    --cc=julien@cumulusnetworks.com \
    --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).