diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-02-28 03:56:38 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-03-07 21:00:36 +0100 |
commit | 8b124135a97b593d50a90abcec231552b31c7ade (patch) | |
tree | 174c3351039ccb082ef50f95811d0dfa3128fa5c /color.c | |
parent | Merge branch 'maint-1.6.1' into maint-1.6.2 (diff) | |
download | git-8b124135a97b593d50a90abcec231552b31c7ade.tar.xz git-8b124135a97b593d50a90abcec231552b31c7ade.zip |
color: allow multiple attributes
In configuration files (and "git config --color" command line), we
supported one and only one attribute after foreground and background
color. Accept combinations of attributes, e.g.
[diff.color]
old = red reverse bold
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'color.c')
-rw-r--r-- | color.c | 24 |
1 files changed, 16 insertions, 8 deletions
@@ -49,7 +49,7 @@ void color_parse_mem(const char *value, int value_len, const char *var, { const char *ptr = value; int len = value_len; - int attr = -1; + unsigned int attr = 0; int fg = -2; int bg = -2; @@ -58,7 +58,7 @@ void color_parse_mem(const char *value, int value_len, const char *var, return; } - /* [fg [bg]] [attr] */ + /* [fg [bg]] [attr]... */ while (len > 0) { const char *word = ptr; int val, wordlen = 0; @@ -87,19 +87,27 @@ void color_parse_mem(const char *value, int value_len, const char *var, goto bad; } val = parse_attr(word, wordlen); - if (val < 0 || attr != -1) + if (0 <= val) + attr |= (1 << val); + else goto bad; - attr = val; } - if (attr >= 0 || fg >= 0 || bg >= 0) { + if (attr || fg >= 0 || bg >= 0) { int sep = 0; + int i; *dst++ = '\033'; *dst++ = '['; - if (attr >= 0) { - *dst++ = '0' + attr; - sep++; + + for (i = 0; attr; i++) { + unsigned bit = (1 << i); + if (!(attr & bit)) + continue; + attr &= ~bit; + if (sep++) + *dst++ = ';'; + *dst++ = '0' + i; } if (fg >= 0) { if (sep++) |