Git development
 help / color / mirror / Atom feed
* [PATCH] sideband: allow ANSI SGR with colon-separated subfields
@ 2026-05-13  7:08 grawity
  0 siblings, 0 replies; only message in thread
From: grawity @ 2026-05-13  7:08 UTC (permalink / raw)
  To: git; +Cc: Mantas Mikulėnas, Junio C Hamano, Johannes Schindelin

From: Mantas Mikulėnas <grawity@gmail.com>

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).

See also: https://github.com/ThomasDickey/xterm-snapshots/blob/6380a3eaed857c182ea6cfa78cd706966b2628d0/charproc.c#L2047-L2118

Signed-off-by: Mantas Mikulėnas <grawity@gmail.com>
---
 sideband.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/sideband.c b/sideband.c
index 04282a568e..6cf70ef6f6 100644
--- a/sideband.c
+++ b/sideband.c
@@ -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;
 	}
 
-- 
2.54.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-05-13  7:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-13  7:08 [PATCH] sideband: allow ANSI SGR with colon-separated subfields grawity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox