summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-11-25 21:31:29 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-11-25 21:31:29 +0200
commit44361fe20d7559b307d4c34c6e7420316609ff5a (patch)
tree194ab6dc8ffdb4c6d1740d06c41c6d9a673f7c70
parentafe1bf47cbc2fa1d437f50e68a771eb23e8891f0 (diff)
Color: Parse 24-bit SGR foreground/background
-rw-r--r--src/ui/color.c19
1 files 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,
818 case 48: { 818 case 48: {
819 iColor *dst = (arg == 38 ? &fg : &bg); 819 iColor *dst = (arg == 38 ? &fg : &bg);
820 /* Extended foreground color. */ 820 /* Extended foreground color. */
821 /* TODO: Cleanup? More robust parsing? */
822 if (ch >= escapeSequence.end) break;
821 arg = strtoul(ch + 1, &endPtr, 10); 823 arg = strtoul(ch + 1, &endPtr, 10);
822 ch = endPtr; 824 ch = endPtr;
823 if (arg == 5) /* 8-bit palette */ { 825 if (arg == 5) /* 8-bit palette */ {
824 arg = strtoul(ch + 1, &endPtr, 10); 826 if (ch >= escapeSequence.end) break;
825 ch = endPtr; 827 arg = strtoul(ch + 1, &endPtr, 10);
828 ch = endPtr;
826 *dst = ansi8BitColors_[iClamp(arg, 0, 255)]; 829 *dst = ansi8BitColors_[iClamp(arg, 0, 255)];
827 } 830 }
831 else if (arg == 2) /* 24-bit RGB */ {
832 int rgb[3] = { 0, 0, 0 };
833 iForIndices(i, rgb) {
834 if (ch >= escapeSequence.end) break;
835 rgb[i] = strtoul(ch + 1, &endPtr, 10);
836 ch = endPtr;
837 }
838 dst->r = iClamp(rgb[0], 0, 255);
839 dst->g = iClamp(rgb[1], 0, 255);
840 dst->b = iClamp(rgb[2], 0, 255);
841 dst->a = 255;
842 }
828 break; 843 break;
829 } 844 }
830 case 39: 845 case 39: