diff options
author | Karel Zak | 2017-05-30 17:10:40 +0200 |
---|---|---|
committer | Karel Zak | 2017-05-30 17:14:12 +0200 |
commit | 23d47267848129b520dd187c0db02f8b5b684372 (patch) | |
tree | ffba162c22149d34f1e9e63c1a9c87db8fb60dad /lib/colors.c | |
parent | build-sys: make ncurses detection more robust (diff) | |
download | kernel-qcow2-util-linux-23d47267848129b520dd187c0db02f8b5b684372.tar.gz kernel-qcow2-util-linux-23d47267848129b520dd187c0db02f8b5b684372.tar.xz kernel-qcow2-util-linux-23d47267848129b520dd187c0db02f8b5b684372.zip |
lib/colors: ncurses cleanup
* use proper paths to term.h
* keep ncurses support optional
* link with TINFO_LIBS (-ltinfo), or fallback to NCURSES_LIBS (-ltinfo -lncurses)
* don't include unnecessary ncurses.h (term.h is enough)
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/colors.c')
-rw-r--r-- | lib/colors.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/colors.c b/lib/colors.c index b2742e4e9..72c5158cb 100644 --- a/lib/colors.c +++ b/lib/colors.c @@ -10,9 +10,15 @@ #include <sys/types.h> #include <dirent.h> #include <ctype.h> -#ifdef HAVE_LIBTINFO -# include <curses.h> -# include <term.h> + +#if defined(HAVE_LIBNCURSES) || defined(HAVE_LIBNCURSESW) +# ifdef HAVE_TERM_H +# include <term.h> +# elif defined(HAVE_NCURSES_TERM_H) +# include <ncurses/term.h> +# elif defined(HAVE_NCURSESW_TERM_H) +# include <ncursesw/term.h> +# endif #endif #include "c.h" @@ -643,19 +649,21 @@ static int colors_terminal_is_ready(void) if (isatty(STDOUT_FILENO) != 1) goto none; -#ifdef HAVE_LIBTINFO +#if defined(HAVE_LIBNCURSES) || defined(HAVE_LIBNCURSESW) { int ret; - if (setupterm(NULL, STDOUT_FILENO, &ret) != OK || ret != 1) + if (setupterm(NULL, STDOUT_FILENO, &ret) != 0 || ret != 1) goto none; ncolors = tigetnum("colors"); if (ncolors <= 2) goto none; } #endif - DBG(CONF, ul_debug("terminal is ready (supports %d colors)", ncolors)); - return 1; + if (ncolors != -1) { + DBG(CONF, ul_debug("terminal is ready (supports %d colors)", ncolors)); + return 1; + } none: DBG(CONF, ul_debug("terminal is NOT ready")); return 0; |