Ncurses program exits when terminal resized

て烟熏妆下的殇ゞ 提交于 2019-12-07 14:45:42

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!