Search code examples
c++unicodencurses

how to use and update panels in ncursesw


I'm currently coding in C++ in Ubuntu WSL2, using the <panel.h> header to create panels in ncursesw, as I need Unicode characters.

I've done a couple tests already, where the results are shown in the table below: enter image description here

This is the code and result when creating a window with a WINDOW* and -lncursesw.

Code:

#include <panel.h>

int main() {
    setlocale(LC_ALL, "");
    initscr();
    noecho();
    cbreak();
    refresh();

    WINDOW *window {newwin(0, 0, 0, 0)};
    
    box(window, 0, 0);
    mvwaddstr(window, 1, 1, "\U0001F600");
    wrefresh(window);

    getch();
    endwin();
}

Result:

enter image description here

This is the code and result when creating a window with a PANEL* and -lncursesw.

Code:

int main() {
    setlocale(LC_ALL, "");
    initscr();
    noecho();
    cbreak();

    PANEL *panel {new_panel(newwin(0, 0, 0, 0))};

    box(panel_window(panel), 0, 0);
    mvwaddstr(panel_window(panel), 1, 1, "\U0001F600");
    // wrefresh(panel_window(panel));
    update_panels();
    doupdate();

    getch();
    endwin();
}

Result:

enter image description here

However if I uncomment the wrefresh() line, I get the same desired result when using WINDOW *. Why is this happening?


Solution

  • doupdate doesn't do a wrefresh (it's generally used after one more more windows is prepared using wnoutrefresh).

    Without an explicit wrefresh, your program is getting the wrefresh done as a side-effect of getch — which refreshes stdscr, but that in turn has only the pending werase from initscr followed by the box call: it seems you'll get an empty box.