On Arch--enable-sigwinch
不会编译成 ncurses。根据这个论坛帖子它可用于检测终端大小调整。让他们打开该选项似乎没有一些阻力,是否有另一种通用方法来检测终端大小调整C
?
答案1
引用自INSTALL
:
--enable-sigwinch
Compile support for ncurses' SIGWINCH handler. If your application has
its own SIGWINCH handler, ncurses will not use its own. The ncurses
handler causes wgetch() to return KEY_RESIZE when the screen-size
changes. This option is the default, unless you have disabled the
extended functions.
如果它不存在,则它已被禁用。原则上,您可以按照最近删除(早已过时)CAN_RESIZE
的部分所示进行操作测试/视图.c文件。 ncurses 库比这做得更好;该示例于 1995 年 7 月添加。评论指 SunOS 4:
/*
* This uses functions that are "unsafe", but it seems to work on SunOS.
* Usually: the "unsafe" refers to the functions that POSIX lists which may be
* called from a signal handler. Those do not include buffered I/O, which is
* used for instance in wrefresh(). To be really portable, you should use the
* KEY_RESIZE return (which relies on ncurses' sigwinch handler).
*
* The 'wrefresh(curscr)' is needed to force the refresh to start from the top
* of the screen -- some xterms mangle the bitmap while resizing.
*/
现代的等效方法只是在信号处理程序中设置一个标志,如图书馆:
#if USE_SIGWINCH
static void
handle_SIGWINCH(int sig GCC_UNUSED)
{
_nc_globals.have_sigwinch = 1;
# if USE_PTHREADS_EINTR
if (_nc_globals.read_thread) {
if (!pthread_equal(pthread_self(), _nc_globals.read_thread))
pthread_kill(_nc_globals.read_thread, SIGWINCH);
_nc_globals.read_thread = 0;
}
# endif
}
#endif /* USE_SIGWINCH */
顺便说一句,打包脚本不显示该功能已禁用:
./configure --prefix=/usr --mandir=/usr/share/man \
--with-pkg-config-libdir=/usr/lib/pkgconfig \
--with-static --with-normal --without-debug --without-ada \
--enable-widec --enable-pc-files --with-cxx-binding --with-cxx-static \
--with-shared --with-cxx-shared
回过头来参考图书馆SIGWINCH
,如果信号是默认(未设置)值,它会初始化其处理程序:
#if USE_SIGWINCH
CatchIfDefault(SIGWINCH, handle_SIGWINCH);
#endif
如果已经有一个SIGWINCH
处理程序,ncurses 将不会执行任何操作。