Search code examples
c++ncurses

ncursesw causing weird behaviour


On WSL2, I'm using the first example code given in this tutorial website: https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/panels.html.

Code:

#include <panel.h>

int main()
{   WINDOW *my_wins[3];
    PANEL  *my_panels[3];
    int lines = 10, cols = 40, y = 2, x = 4, i;
    initscr();
    cbreak();
    noecho();

    /* Create windows for the panels */
    my_wins[0] = newwin(lines, cols, y, x);
    my_wins[1] = newwin(lines, cols, y + 1, x + 5);
    my_wins[2] = newwin(lines, cols, y + 2, x + 10);

    /* 
     * Create borders around the windows so that you can see the effect
     * of panels
     */
    for(i = 0; i < 3; ++i)
        box(my_wins[i], 0, 0);

    /* Attach a panel to each window */     /* Order is bottom up */
    my_panels[0] = new_panel(my_wins[0]);   /* Push 0, order: stdscr-0 */
    my_panels[1] = new_panel(my_wins[1]);   /* Push 1, order: stdscr-0-1 */
    my_panels[2] = new_panel(my_wins[2]);   /* Push 2, order: stdscr-0-1-2 */

    /* Update the stacking order. 2nd panel will be on top */
    update_panels();

    /* Show it on the screen */
    doupdate();
    
    getch();
    endwin();
}

When I run the code with the flags -lpanel -ncurses, it works fine as shown below: enter image description here

When I run the code with the flags -lpanel -ncursesw, it doesn't work well: enter image description here


Solution

  • The example shows two problems:

    • mixing -lpanel with -lncursesw (won't work because the size of the types holding character plus attributes differs).
    • You should use -lpanelw.
    • there's no call to setlocale to make line-drawing work portably.