How to fully recolor window background after resize in PDCurses?

46 views Asked by At

I would like the WINDOWs I create to automatically take up all the width of the console window when I resize it. However, when I shrink the console window, and then make it bigger, my WINDOW isn't being entirely colored. It only stays colored up to the point where I shrunk it most.

I resize the WINDOW with wresize(), then I try to recolor it with wbkgd(). I then try to do a wrefresh() but nothing seems to change. I printed out the WINDOW's width when it was being resized and it seems to be correct, only the coloring appears to not be working properly.

Here's the code I used:

#include <curses.h>

int main(int argc, char **argv)
{
    WINDOW *wHea;

    initscr();
    noecho();
    nodelay(stdscr, TRUE);
    start_color();

    wHea = newwin(1, getmaxx(stdscr), 0, 0);

    init_pair(1, COLOR_BLACK, COLOR_WHITE);
    init_pair(2, COLOR_BLUE, COLOR_RED);
    bkgd(COLOR_PAIR(2));
    wbkgd(wHea, COLOR_PAIR(1));

    refresh();
    wrefresh(wHea);

    char input;
    while ((input = getch()) != 'q')
    {
        if (is_termresized())
        {
            resize_term(0, 0);
            bkgd(COLOR_PAIR(2));

            wresize(wHea, 1, getmaxx(stdscr));
            wbkgd(wHea, COLOR_PAIR(1));

            refresh();
            wrefresh(wHea);
        }
    }

    endwin();
}

Here's what the output looks like after I resize the console window:

enter image description here

0

There are 0 answers