12

I have a small ncurse program I'm running, but the output doesn't seem to show up unless I stick the wrefresh() in a while loop.

Is there some buffering going on or something? I tried other refresh functions in the library and fflush with stddout (which I don't think makes sense, but worth a try), but nothing seems to work.

A second small question: to make getch() non-blocking we need to call nodelay(win,TRUE), right?


void main()
{
        initscr();
        start_color();
        init_pair(1,COLOR_YELLOW,COLOR_CYAN);
        WINDOW *win = newwin(10,10,1,1);
        wbkgd(win,COLOR_PAIR(1));
        wprintw(win,"Hello, World.");
        wrefresh(win);
        getch();
        delwin(win);
        endwin();
}

Mark
  • 2,380
  • 11
  • 29
  • 49
Tim
  • 279
  • 2
  • 3
  • 10
  • I added the following code: while(ERR == getch()) { wrefresh(win); ++ctr; } and the output looks good, but I still don't understand why it doesn't initially display without looping. – Tim Sep 27 '10 at 23:55

2 Answers2

22

You are not supposed to mix operations on stdscr and windows created with newwin(). getch() operates on stdscr, so that is your problem. Replace that call with

wgetch(win);

(getch() is causing stdscr to be dumped over the top of your other window, and because that happens so quickly it looks like the other window never got displayed at all).

caf
  • 233,326
  • 40
  • 323
  • 462
  • Right you are. Thanks a bunch! Sorry, but I need to ask one more: when you call a function that operates on a window does it set focus to that window if there is such a thing as focus? – Tim Sep 28 '10 at 01:23
  • @Tim: The hardware cursor is left at the location of the cursor in the window that you last refreshed, but that's really the only kind of "focus". – caf Sep 28 '10 at 01:28
  • If you need independent overlaping windows you should look at the panels library that is part of ncurses. – Craig Oct 07 '10 at 03:34
1

That's working as designed. That allows you to completely redraw your next screen but only the parts that actually changed get sent to the terminal at refresh time. This isn't such a big deal these days but made a big difference when terminal connections were relatively slow.

JOTN
  • 6,120
  • 2
  • 26
  • 31
  • Thanks for the reply. I understand that's the case, but I don't see anything but a blank screen. How do I get the window and text to appear *initially* without repeatedly calling wrefresh()? – Tim Sep 27 '10 at 23:49