From 44361fe20d7559b307d4c34c6e7420316609ff5a Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Thu, 25 Nov 2021 21:31:29 +0200 Subject: Color: Parse 24-bit SGR foreground/background --- src/ui/color.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/ui/color.c b/src/ui/color.c index 0b927fd6..3ea98d8c 100644 --- a/src/ui/color.c +++ b/src/ui/color.c @@ -818,13 +818,28 @@ void ansiColors_Color(iRangecc escapeSequence, int fgDefault, int bgDefault, case 48: { iColor *dst = (arg == 38 ? &fg : &bg); /* Extended foreground color. */ + /* TODO: Cleanup? More robust parsing? */ + if (ch >= escapeSequence.end) break; arg = strtoul(ch + 1, &endPtr, 10); ch = endPtr; if (arg == 5) /* 8-bit palette */ { - arg = strtoul(ch + 1, &endPtr, 10); - ch = endPtr; + if (ch >= escapeSequence.end) break; + arg = strtoul(ch + 1, &endPtr, 10); + ch = endPtr; *dst = ansi8BitColors_[iClamp(arg, 0, 255)]; } + else if (arg == 2) /* 24-bit RGB */ { + int rgb[3] = { 0, 0, 0 }; + iForIndices(i, rgb) { + if (ch >= escapeSequence.end) break; + rgb[i] = strtoul(ch + 1, &endPtr, 10); + ch = endPtr; + } + dst->r = iClamp(rgb[0], 0, 255); + dst->g = iClamp(rgb[1], 0, 255); + dst->b = iClamp(rgb[2], 0, 255); + dst->a = 255; + } break; } case 39: -- cgit v1.2.3