From: Timo Hirvonen <tihirvon@gmail.com>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: [PATCH] diff: Support 256 colors
Date: Thu, 13 Jul 2006 19:08:06 +0300 [thread overview]
Message-ID: <20060713190806.4700b24c.tihirvon@gmail.com> (raw)
Add support for more than 8 colors. Colors can be specified as numbers
-1..255. -1 is same as "normal".
Signed-off-by: Timo Hirvonen <tihirvon@gmail.com>
---
diff.c | 24 ++++++++++++++++++------
1 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/diff.c b/diff.c
index a9118a9..351cd07 100644
--- a/diff.c
+++ b/diff.c
@@ -26,8 +26,8 @@ enum color_diff {
DIFF_FILE_NEW = 5,
};
-/* "\033[1;30;47m\0" is 11 bytes */
-static char diff_colors[][16] = {
+/* "\033[1;38;5;2xx;48;5;2xxm\0" is 23 bytes */
+static char diff_colors[][24] = {
"\033[m", /* reset */
"", /* normal */
"\033[1m", /* bold */
@@ -57,12 +57,16 @@ static int parse_color(const char *name,
"normal", "black", "red", "green", "yellow",
"blue", "magenta", "cyan", "white"
};
+ char *end;
int i;
for (i = 0; i < ARRAY_SIZE(color_names); i++) {
const char *str = color_names[i];
if (!strncasecmp(name, str, len) && !str[len])
return i - 1;
}
+ i = strtol(name, &end, 10);
+ if (*name && !*end && i >= -1 && i <= 255)
+ return i;
return -2;
}
@@ -135,14 +139,22 @@ static void parse_diff_color_value(const
if (fg >= 0) {
if (sep++)
*dst++ = ';';
- *dst++ = '3';
- *dst++ = '0' + fg;
+ if (fg < 8) {
+ *dst++ = '3';
+ *dst++ = '0' + fg;
+ } else {
+ dst += sprintf(dst, "38;5;%d", fg);
+ }
}
if (bg >= 0) {
if (sep++)
*dst++ = ';';
- *dst++ = '4';
- *dst++ = '0' + bg;
+ if (bg < 8) {
+ *dst++ = '4';
+ *dst++ = '0' + bg;
+ } else {
+ dst += sprintf(dst, "48;5;%d", bg);
+ }
}
*dst++ = 'm';
}
--
1.4.1.gd0c9d-dirty
reply other threads:[~2006-07-13 16:10 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20060713190806.4700b24c.tihirvon@gmail.com \
--to=tihirvon@gmail.com \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/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