sideband: allow ANSI SGR with colon-separated subfields

The SGR values used for 256-color formatting are officially defined to be a single field with :-separated subfields (e.g. "\e[1;38:5:XX;40m") despite the more common but kludgy use of separate values (which then become context-dependent and lead to misinterpretation by incompatible terminals). Signed-off-by: Mantas Mikulėnas <grawity@gmail.com> Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Mantas Mikulėnas committed May 13, 2026 at 10:08 UTC 3792b2aea4371c2c6f65cac2ece9b2718ad61b1c
1 file changed +5 -1
sideband.c
+5 -1
@@ -163,6 +163,10 @@ static int handle_ansi_sequence(struct strbuf *dest, const char *src, int n)
163 *
164 * ESC [ [<n> [; <n>]*] m
165 *
166 + * where <n> can be either zero-length, or a decimal number, or a
167 + * series of decimal numbers separated by a colon (for 256-color or
168 + * true-color codes).
169 + *
170 * These are part of the Select Graphic Rendition sequences which
171 * contain more than just color sequences, for more details see
172 * https://en.wikipedia.org/wiki/ANSI_escape_code#SGR.
@@ -210,7 +214,7 @@ static int handle_ansi_sequence(struct strbuf *dest, const char *src, int n)
214 strbuf_add(dest, src, i + 1);
215 return i;
216 }
213 - if (!isdigit(src[i]) && src[i] != ';')
217 + if (!isdigit(src[i]) && src[i] != ':' && src[i] != ';')
218 break;
219 }
220