title: Resizing glitch with Ncurses?
body: <p>I'm writing an <code>ncurses</code> program and am trying to make it respond correctly to terminal resizing. While I can read the terminal dimensions correctly in my program, <code>ncurses</code> doesn't seem to deal with new dimensions correctly. Here's a (somewhat lengthy) sample program:</p>
  
  <pre><code>#include &lt;ncurses.h&gt;
  #include &lt;string.h&gt;
  #include &lt;signal.h&gt;
  #include &lt;sys/ioctl.h&gt;
  
  void handle_winch(int sig){
  
      struct winsize w;
      ioctl(0, TIOCGWINSZ, &amp;w);
      COLS = w.ws_col;
      LINES = w.ws_row;
  
      wresize(stdscr, LINES, COLS);
      clear();
  
      mvprintw(0, 0, "COLS = %d, LINES = %d", COLS, LINES);
      for (int i = 0; i &lt; COLS; i++)
          mvaddch(1, i, '*');
  
      refresh();
  }
  
  int main(int argc, char *argv[]){
  
      initscr();
  
      struct sigaction sa;
      memset(&amp;sa, 0, sizeof(struct sigaction));
      sa.sa_handler = handle_winch;
      sigaction(SIGWINCH, &amp;sa, NULL);
  
      while(getch() != 27) {}
  
      endwin();
      return 0;
  }
  </code></pre>
  
  <p>If you run it, you can see that the terminal dimensions are correctly retrieved. But the second line, which is supposed to draw <code>*</code>-characters across the screen, doesn't work. Try resizing the window horizontally to make it larger, the line of <code>*</code>s will not get larger.</p>
  
  <p>What's the problem here? I'm aware that one can temporarily leave curses mode, but I'd prefer a cleaner solution. Thanks!</p>