3

ターミナル ウィンドウのサイズを変更すると、以下のプログラムが終了します。なぜ、どのようにそれを止めることができますか?

#include <ncurses.h>
#include <unistd.h>

int main () {
    initscr ();

    printw ("Some text\n");
    refresh ();

    sleep (100);
    endwin ();

    return 0;
}
4

2 に答える 2

2

ここで答えを見つけました

端末のサイズが変更されると、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;
}
于 2013-03-16T15:10:46.857 に答える
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
    // ...
}
于 2013-03-16T15:11:29.713 に答える