Modulo colors before comparing pairs

Otherwise a new pair is allocated every time a high color is requested.
master
C. McEnroe 2020-02-05 04:24:13 -05:00
parent 1cf6e29fc4
commit 6e679bdf26
1 changed files with 3 additions and 1 deletions

4
ui.c
View File

@ -135,12 +135,14 @@ static attr_t colorAttr(short fg) {
static short colorPair(short fg, short bg) {
if (bg == -1) return 1 + fg;
fg %= COLORS;
bg %= COLORS;
for (short pair = 17; pair < colorPairs; ++pair) {
short f, b;
pair_content(pair, &f, &b);
if (f == fg && b == bg) return pair;
}
init_pair(colorPairs, fg % COLORS, bg % COLORS);
init_pair(colorPairs, fg, bg);
return colorPairs++;
}