]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sideband: allow ANSI SGR with colon-separated subfields
authorMantas Mikulėnas <grawity@gmail.com>
Wed, 13 May 2026 07:08:03 +0000 (10:08 +0300)
committerJunio C Hamano <gitster@pobox.com>
Tue, 7 Jul 2026 18:20:44 +0000 (11:20 -0700)
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>
sideband.c

index 1523a53e1d781dca0460971021e5e21d1b044ecc..4a2c5f858f60ad0125b91c6c2b7831379b974f22 100644 (file)
@@ -163,6 +163,10 @@ static int handle_ansi_sequence(struct strbuf *dest, const char *src, int n)
         *
         * ESC [ [<n> [; <n>]*] m
         *
+        * where <n> can be either zero-length, or a decimal number, or a
+        * series of decimal numbers separated by a colon (for 256-color or
+        * true-color codes).
+        *
         * These are part of the Select Graphic Rendition sequences which
         * contain more than just color sequences, for more details see
         * 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)
                        strbuf_add(dest, src, i + 1);
                        return i;
                }
-               if (!isdigit(src[i]) && src[i] != ';')
+               if (!isdigit(src[i]) && src[i] != ':' && src[i] != ';')
                        break;
        }