gpt4 book ai didi

c - 调整终端大小时 Ncurses 程序退出

转载 作者:太空狗 更新时间:2023-10-29 11:15:16 26 4
gpt4 key购买 nike

当我调整终端窗口大小时,下面的程序退出。为什么以及如何阻止它?

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

int main () {
initscr ();

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

sleep (100);
endwin ();

return 0;
}

最佳答案

我找到了答案 here

当终端调整大小时,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;
}

关于c - 调整终端大小时 Ncurses 程序退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15450682/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com