ターミナル ウィンドウのサイズを変更すると、以下のプログラムが終了します。なぜ、どのようにそれを止めることができますか?
#include <ncurses.h>
#include <unistd.h>
int main () {
initscr ();
printw ("Some text\n");
refresh ();
sleep (100);
endwin ();
return 0;
}
ここで答えを見つけました
端末のサイズが変更されると、SIGWINCH
シグナルが発生し、プログラムが終了します。
解決策は次のとおりです。
#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;
}
SIGWINCH シグナルを処理する必要があります。
#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
// ...
}