问题
When i resize my terminal window, the below program exits. Why and how can stop it?
#include <ncurses.h>
#include <unistd.h>
int main () {
initscr ();
printw ("Some text\n");
refresh ();
sleep (100);
endwin ();
return 0;
}
回答1:
I found the answer here
When terminal has resized, the SIGWINCH
signal raises and program exits.
Here is the solution:
#include <ncurses.h>
#include <unistd.h>
#include <signal.h>
int main () {
initscr ();
signal (SIGWINCH, NULL);
printw ("Some text\n");
refresh ();
sleep (100);
endwin ();
return 0;
}
回答2:
You need to handle the SIGWINCH signal :
#include <signal.h>
/* resizer handler, called when the user resizes the window */
void resizeHandler(int sig) {
// update layout, do stuff...
}
int main(int argc, char **argv) {
signal(SIGWINCH, resizeHandler);
// play with ncurses
// ...
}
来源:https://stackoverflow.com/questions/15450682/ncurses-program-exits-when-terminal-resized