@matheusbsbs / matheus-bagliano / commits / c444f032e4
Fork 0

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 <shawarmakarma@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eyal Soha committed Jan 21, 2020 at 08:56 UTC c444f032e43611b95612882cd06380866f8da0fd
2 files changed +10 -1
color.c
+6 -1
@@ -136,11 +136,16 @@ static int parse_color(struct color *out, const char *name, int len)
136 else if (val < 0) {
137 out->type = COLOR_NORMAL;
138 return 0;
139 - /* Rewrite low numbers as more-portable standard colors. */
139 + /* Rewrite 0-7 as more-portable standard colors. */
140 } else if (val < 8) {
141 out->type = COLOR_ANSI;
142 out->value = val + COLOR_FOREGROUND_ANSI;
143 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;
149 } else if (val < 256) {
150 out->type = COLOR_256;
151 out->value = val;
t/t4026-color.sh
+4
@@ -82,6 +82,10 @@ test_expect_success '0-7 are aliases for basic ANSI color names' '
82 color "0 7" "[30;47m"
83 '
84
85 +test_expect_success '8-15 are aliases for aixterm color names' '
86 + color "12 13" "[94;105m"
87 +'
88 +
89 test_expect_success '256 colors' '
90 color "254 bold 255" "[1;38;5;254;48;5;255m"
91 '