From 8815bc1e03e9910d453e352be0b21efd8a61f6c8 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Thu, 1 Aug 2019 17:01:29 -0400 Subject: Use PSCap in updateCSI and styleDiff --- term.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/term.c b/term.c index a79a084..357861f 100644 --- a/term.c +++ b/term.c @@ -216,6 +216,9 @@ static void updateSGR(uint ps[], uint n) { } } +// SGR toggling all attributes and setting both colors in 256 palette. +enum { PSCap = 4 + 2 * 3 }; + enum { DEC = '?', CUU = 'A', @@ -248,11 +251,11 @@ static char updateCSI(wchar_t ch) { return CSI; } - static uint n, p, ps[8]; + static uint n, p, ps[PSCap]; if (ch == ';') { n++; p++; - ps[p %= 8] = 0; + ps[p %= PSCap] = 0; return CSI; } if (ch >= '0' && ch <= '9') { @@ -376,7 +379,8 @@ styleDiff(FILE *file, const struct Style *prev, const struct Style *next) { if (!memcmp(next, &Default, sizeof(*next))) { return fprintf(file, "%c%c%c", ESC, CSI, SGR); } - uint ps[10]; + + uint ps[PSCap]; uint n = 0; if (next->bold != prev->bold) { ps[n++] = (next->bold ? Bold : NotBold); @@ -416,6 +420,7 @@ styleDiff(FILE *file, const struct Style *prev, const struct Style *next) { ps[n++] = next->fg; } } + if (0 > fprintf(file, "%c%c%u", ESC, CSI, ps[0])) return -1; for (uint i = 1; i < n; ++i) { if (0 > fprintf(file, ";%u", ps[i])) return -1; -- cgit 1.4.1