bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Issue using more than 255 color pairs


From: David Unterwandling
Subject: Re: Issue using more than 255 color pairs
Date: Sat, 29 Jul 2023 00:58:48 +0200

>>     char *f;
>>
>>     sprintf(f, "%d color pairs allowed", COLOR_PAIRS);

> "f" is an uninitialized buffer (and that sprintf trashes memory)

You see I'm an novice. I'll searched for that basic answer..
Is it just
        char f[16];
that would satisfy? Can you explain?

Btw, my last code example is horrible. Now I have a solution where all of the
16 colors it into 152 pairs, and using the reverse attribute for spared 120.

-KISS Dave

attr_t
colorpair(unsigned char f, unsigned char b)
{
    attr_t c, a = 0;
    unsigned char m = 16;
    register char z;

    if (b)
        b = black_switch(b);
    if (COLORS < m) {
        m = 8;
        b %= m;
    }
    if (b && f == NO_COLOR)
        f = b;
    else {
        f = black_switch(f);
        if (m == BRIGHT) {
            if (f >= m && (!b || f < CLR_BLACK))
                a |= A_BOLD;

            if (f == CLR_BLACK)
                f = m;
            if (f > m || (b && f == m))
                f %= m;
        }
        if (f < b) {
            c = b; b = f; f = c;
            a |= A_REVERSE;
        }
    }
    c = f + b * m;

        z = (b > 1) ? b : 0;
    while (z--)
        c -= z;
    if (m == BRIGHT && b)
        c -= b - 1;

    return COLOR_PAIR(c) | a;
}

void init_pairs(void)
{
        for (b = 0; b < CLR_MAX; b++) {
                if (COLORS < 16 && b >= BRIGHT)
                    continue;

                for (f = 1; f < CLR_MAX; f++) {
                    if (COLORS < 16 && (f > BRIGHT || (f == BRIGHT && b)))
                        continue;

                    if (f >= b) {
                        n = f + b * m;
                        c = (b > 1) ? b : 0;
                        while (c--)
                            n -= c;
                        if (COLORS < 16 && b)
                            n -= b - 1;

                        if (f == b)
                            init_pair(n, -1, b % m);
                        else
                            if (!b)
                                init_pair(n, f % m, -1);
                            else
                                init_pair(n, f % m, b % m);
                    }
                }
       }
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]