Double post, sorry...
The example posted does more than just clear the screen. The initscr() method is all that it takes. Perhaps this might serve as a word of warning, however... this is what ncurses printed to initalize the screen:
Code:
"\^[)0\^[7\^[[?47h\^[[1;56r\^[[m\^[[4l\^[[H\^[[2J"
and this to clear it subsequently:
and wrote this to restore it:
Code:
"\^[[56;1H\^[[2J\^[[?47l\^[8\r\^[[?1l\^[>"
I have no idea what any of these control characters are... but ncurses handles all of this, per platform, for you.
To try to simplify it, I wrote this:
Code:
#include <ncurses.h>
int main(int argc, char *argv[]) {
initscr();
getch();
printw("Muss up the screen a bit");
getch();
clear();
getch();
endwin();
return 0;
}
The initscr() is all it takes to clear the screen. endwin() is all it takes to restore it to its previous state. The getch() is in there so it will stay with a blank screen until you press a key. I also put something on the screen and called clear again, to demonstrate that you can clear whenever you want once ncurses is up, not just at startup.
I should state that there is definitely a way to do this by hand... but this makes it better. I have a pretty good feel for how this works, and I'd never looked at ncurses at all until 20 minutes ago.
-Lee
P.S. To compile this, which i called testncurses.c, i ran:
Code:
gcc -o testncurses -lncurses testncurses.c
the -lncurses would be the only thing I wold expect to be unusual. That just adds in the ncurses library for the linker. I'm pretty sure this can be added easily to XCode to handle this for you, but I won't speak to things that I don't know for sure.