potrzebie potrzebie - 1 year ago 143
C Question

Correct way to repaint entire screen?

I don't understand what function(s) to use to repaint the screen when the user presses Ctrl-L or Ctrl-R. What's the difference between using

, or
as argument? From the OpenBSD man pages:

If clearok is called with TRUE as argument, the next call to wrefresh with this window will clear the screen completely and redraw the entire screen from scratch. This is useful when the contents of the screen are uncertain, or in some cases for a more pleasing visual effect. If the win argument to clearok is the global variable curscr, the next call to wrefresh with any window causes the screen to be cleared and repainted from scratch.


If the win argument to wrefresh is the global variable curscr, the screen is immediately cleared and repainted from scratch.


The wredrawln routine indicates to curses that some screen lines are corrupted and should be thrown away before anything is written over them. It touches the indicated lines (marking them changed). The routine redrawwin() touches the entire window.

Answer Source

The "OpenBSD manpages" are ncurses. The key-bindings are irrelevant.
You've asked about three features:

  1. clearok(),
  2. redrawwin(), or
  3. wrefresh() with curscr as argument?

But those are different:

  • with clearok(), you are not telling curses that you've lost track of what's on the screen, but saying that it's preferable to clear it (and curses will do that), but
  • redrawwin() isn't repainting the whole screen, but a window. Your application might do this if it is imitating the panel library, making some windows overlap and wanting to "raise" an obscured window above the others. Finally,
  • refreshing curscr explicitly is telling curses to bypass the normal sequence of printing onto a window, or onto stdscr, then applying changes from stdscr onto newscr, and applying differences between newscr and curscr to curscr. As far as curses is concerned, curscr has whatever is put onto the physical screen. So when you modify curscr, curses updates the physical screen as soon as it is asked to refresh.

For what it's worth, the curscr feature predates ncurses, though I'd have to point to source-code to show that. It's mentioned in this changelog entry from 1995 though:

src/curses/resizwin.c: refresh curscr to force screen update in ncurses

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download