/* * Demo of a bug with panels and updating * * cc broke2.c -lpanel -lncurses -o broke2 * * address@hidden */ #include #include /* * blank a rectangluar screen region */ void wblankrect(WINDOW *win, int miny, int minx, int maxy, int maxx, int saveattr) { int x, y; chtype ch; for (y = miny; y <= maxy; ++y) for (x = minx; x <= maxx; ++x) { if (saveattr) { ch = mvwinch(win, y, x); ch &= ~0xff; ch |= ' '; mvwaddch(win, y, x, ch); } else mvwaddch(win, y, x, ' '); } } /* * Scroll a rectangular screen region */ void wvscrollrect(WINDOW *win, int miny, int minx, int maxy, int maxx, int lines) { int x, y; chtype ch; while (lines > 0) { for (y = miny; y < maxy; ++y) for (x = minx; x <= maxx; ++x) { ch = mvwinch(win, y+1, x); mvwaddch(win, y, x, ch); } wblankrect(win, maxy, minx, maxy, maxx, 1); --lines; } while (lines < 0) { for (y = maxy; y > miny; --y) for (x = minx; x <= maxx; ++x) { ch = mvwinch(win, y-1, x); mvwaddch(win, y, x, ch); } wblankrect(win, miny, minx, miny, maxx, 1); ++lines; } } main() { WINDOW *win; WINDOW *sub; PANEL *panel; char sym[16]; int n; initscr(); win = newwin(10, 24, 0, 0); box(win, 0, 0); mvwprintw(win, 0, (24-strlen("Popup"))/2, "Popup"); sub = derwin(win, 8, 22, 1, 1); panel = new_panel(win); mvwprintw(sub, 4, 0, "Why arent't these lines updated?"); for (n = 0;; ++n) { /* Scroll the *entire* contents of the popup up 1 line */ wvscrollrect(sub, 0, 0, getmaxy(sub)-1, getmaxx(sub)-1, 1); /* Add new line at bottom */ mvwprintw(sub, getmaxy(sub)-1, 0, "%7.2f %5d %02d:%02d:%02d", n * 1.23, n, n, n, n ); /* BUG ?!? * * Only the lines in the panel which *overlay * stdscr lines that have themselves been changed* * will get updated! * * The next code shows how 2 lines in the popup * will get updated, while the rest won't! */ if (1) { mvprintw(2, 0, "This is a test"); mvprintw(8, 0, "This is a test"); } update_panels(); // refresh(); doupdate(); usleep(100*1000); } }