【发布时间】:2013-03-16 14:51:13
【问题描述】:
当我调整终端窗口的大小时,以下程序会退出。为什么以及如何阻止它?
#include <ncurses.h>
#include <unistd.h>
int main () {
initscr ();
printw ("Some text\n");
refresh ();
sleep (100);
endwin ();
return 0;
}
【问题讨论】:
当我调整终端窗口的大小时,以下程序会退出。为什么以及如何阻止它?
#include <ncurses.h>
#include <unistd.h>
int main () {
initscr ();
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
// ...
}
【讨论】:
signal(7) 手册页。通常的方法是只在信号处理程序中设置一个volatile sigatomic_t 标志,并在其他地方测试该标志......