--enable-sigwinchを使用してコンパイルせずにターミナルサイズ変更ncursesを検出する

--enable-sigwinchを使用してコンパイルせずにターミナルサイズ変更ncursesを検出する

On Archは--enable-sigwinchncursesにコンパイルされません。 ~によるとこのフォーラムの投稿端末のサイズ変更を検出するために使用できます。そのオプションをオンにするのに抵抗がないようです。端末のサイズ変更を検出する別の一般的な方法はありますか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実行できます。テスト/views.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

ncursesは、すでにハンドラがある場合はSIGWINCH何もしません。

おすすめ記事