Skip to content

Commit 1751b09

Browse files
eyal0gitster
authored andcommitted
color.c: support bright aixterm colors
These colors are the bright variants of the 3-bit colors. Instead of 30-37 range for the foreground and 40-47 range for the background, they live in 90-97 and 100-107 range, respectively. Signed-off-by: Eyal Soha <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4a28eb0 commit 1751b09

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

Documentation/config.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,9 @@ color::
263263
+
264264
The basic colors accepted are `normal`, `black`, `red`, `green`, `yellow`,
265265
`blue`, `magenta`, `cyan` and `white`. The first color given is the
266-
foreground; the second is the background.
266+
foreground; the second is the background. All the basic colors except
267+
`normal` have a bright variant that can be speficied by prefixing the
268+
color with `bright`, like `brightred`.
267269
+
268270
Colors may also be given as numbers between 0 and 255; these use ANSI
269271
256-color mode (but note that not all terminals may support this). If

color.c

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ enum {
2929
COLOR_FOREGROUND_ANSI = 30,
3030
COLOR_FOREGROUND_RGB = 38,
3131
COLOR_FOREGROUND_256 = 38,
32+
COLOR_FOREGROUND_BRIGHT_ANSI = 90,
3233
};
3334

3435
/* Ignore the RESET at the end when giving the size */
@@ -68,15 +69,38 @@ static int get_hex_color(const char *in, unsigned char *out)
6869
return 0;
6970
}
7071

71-
static int parse_color(struct color *out, const char *name, int len)
72+
/*
73+
* If an ANSI color is recognized in "name", fill "out" and return 0.
74+
* Otherwise, leave out unchanged and return -1.
75+
*/
76+
static int parse_ansi_color(struct color *out, const char *name, int len)
7277
{
7378
/* Positions in array must match ANSI color codes */
7479
static const char * const color_names[] = {
7580
"black", "red", "green", "yellow",
7681
"blue", "magenta", "cyan", "white"
7782
};
78-
char *end;
7983
int i;
84+
int color_offset = COLOR_FOREGROUND_ANSI;
85+
86+
if (strncasecmp(name, "bright", 6) == 0) {
87+
color_offset = COLOR_FOREGROUND_BRIGHT_ANSI;
88+
name += 6;
89+
len -= 6;
90+
}
91+
for (i = 0; i < ARRAY_SIZE(color_names); i++) {
92+
if (match_word(name, len, color_names[i])) {
93+
out->type = COLOR_ANSI;
94+
out->value = i + color_offset;
95+
return 0;
96+
}
97+
}
98+
return -1;
99+
}
100+
101+
static int parse_color(struct color *out, const char *name, int len)
102+
{
103+
char *end;
80104
long val;
81105

82106
/* First try the special word "normal"... */
@@ -96,12 +120,8 @@ static int parse_color(struct color *out, const char *name, int len)
96120
}
97121

98122
/* Then pick from our human-readable color names... */
99-
for (i = 0; i < ARRAY_SIZE(color_names); i++) {
100-
if (match_word(name, len, color_names[i])) {
101-
out->type = COLOR_ANSI;
102-
out->value = i + COLOR_FOREGROUND_ANSI;
103-
return 0;
104-
}
123+
if (parse_ansi_color(out, name, len) == 0) {
124+
return 0;
105125
}
106126

107127
/* And finally try a literal 256-color-mode number */

t/t4026-color.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ test_expect_success 'attribute before color name' '
3030
color "bold red" "[1;31m"
3131
'
3232

33+
test_expect_success 'aixterm bright fg color' '
34+
color "brightred" "[91m"
35+
'
36+
37+
test_expect_success 'aixterm bright bg color' '
38+
color "green brightblue" "[32;104m"
39+
'
40+
3341
test_expect_success 'color name before attribute' '
3442
color "red bold" "[1;31m"
3543
'

0 commit comments

Comments
 (0)