Skip to content

Commit 5621068

Browse files
peffgitster
authored andcommitted
color: allow "no-" for negating attributes
Using "no-bold" rather than "nobold" is easier to read and more natural to type (to me, anyway, even though I was the person who introduced "nobold" in the first place). It's easy to allow both. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent df8e472 commit 5621068

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

Documentation/config.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ hex, like `#ff0ab3`.
163163
The accepted attributes are `bold`, `dim`, `ul`, `blink`, and `reverse`.
164164
The position of any attributes with respect to the colors (before, after,
165165
or in between), doesn't matter. Specific attributes may be turned off
166-
by prefixing them with `no` (e.g., `noreverse`, `noul`, etc).
166+
by prefixing them with `no` or `no-` (e.g., `noreverse`, `no-ul`, etc).
167167
+
168168
For git's pre-defined color slots, the attributes are meant to be reset
169169
at the beginning of each item in the colored output. So setting

color.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,10 @@ static int parse_attr(const char *name, size_t len)
141141
int negate = 0;
142142
int i;
143143

144-
if (skip_prefix_mem(name, len, "no", &name, &len))
144+
if (skip_prefix_mem(name, len, "no", &name, &len)) {
145+
skip_prefix_mem(name, len, "-", &name, &len);
145146
negate = 1;
147+
}
146148

147149
for (i = 0; i < ARRAY_SIZE(attrs); i++) {
148150
if (attrs[i].len == len && !memcmp(attrs[i].name, name, len))

t/t4026-color.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ test_expect_success 'attr negation' '
5050
color "nobold nodim noul noblink noreverse" "[22;24;25;27m"
5151
'
5252

53+
test_expect_success '"no-" variant of negation' '
54+
color "no-bold no-blink" "[22;25m"
55+
'
56+
5357
test_expect_success 'long color specification' '
5458
color "254 255 bold dim ul blink reverse" "[1;2;4;5;7;38;5;254;48;5;255m"
5559
'

0 commit comments

Comments
 (0)