Skip to content

Commit c444f03

Browse files
eyal0gitster
authored andcommitted
color.c: alias RGB colors 8-15 to aixterm colors
This results in shorter output, and is _probably_ more portable. There is at least one environment (GitHub Actions) which supports 16-color mode but not 256-color mode. It's possible there are environments which go the other way, but it seems unlikely. Signed-off-by: Eyal Soha <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1751b09 commit c444f03

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

color.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,16 @@ static int parse_color(struct color *out, const char *name, int len)
136136
else if (val < 0) {
137137
out->type = COLOR_NORMAL;
138138
return 0;
139-
/* Rewrite low numbers as more-portable standard colors. */
139+
/* Rewrite 0-7 as more-portable standard colors. */
140140
} else if (val < 8) {
141141
out->type = COLOR_ANSI;
142142
out->value = val + COLOR_FOREGROUND_ANSI;
143143
return 0;
144+
/* Rewrite 8-15 as more-portable aixterm colors. */
145+
} else if (val < 16) {
146+
out->type = COLOR_ANSI;
147+
out->value = val - 8 + COLOR_FOREGROUND_BRIGHT_ANSI;
148+
return 0;
144149
} else if (val < 256) {
145150
out->type = COLOR_256;
146151
out->value = val;

t/t4026-color.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ test_expect_success '0-7 are aliases for basic ANSI color names' '
8282
color "0 7" "[30;47m"
8383
'
8484

85+
test_expect_success '8-15 are aliases for aixterm color names' '
86+
color "12 13" "[94;105m"
87+
'
88+
8589
test_expect_success '256 colors' '
8690
color "254 bold 255" "[1;38;5;254;48;5;255m"
8791
'

0 commit comments

Comments
 (0)