]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/colors: ncurses cleanup
authorKarel Zak <kzak@redhat.com>
Tue, 30 May 2017 15:10:40 +0000 (17:10 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 30 May 2017 15:14:12 +0000 (17:14 +0200)
* 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>
lib/Makemodule.am
lib/colors.c

index 358b85aee060dd9b451bfea750a3156fcc053bc2..7a018f51621dbe29bec970e3d01d30d364fdf887 100644 (file)
@@ -50,9 +50,19 @@ libcommon_la_SOURCES += lib/sysfs.c
 endif
 
 noinst_LTLIBRARIES += libtcolors.la
-libtcolors_la_CFLAGS = $(AM_CFLAGS) $(TINFO_CFLAGS)
-libtcolors_la_LIBADD = $(TINFO_LIBS)
+libtcolors_la_CFLAGS = $(AM_CFLAGS)
 libtcolors_la_SOURCES = lib/colors.c lib/color-names.c include/colors.h include/color-names.h
+libtcolors_la_LIBADD =
+# tinfo or ncurses are optional
+if HAVE_TINFO
+libtcolors_la_LIBADD += $(TINFO_LIBS)
+libtcolors_la_CFLAGS += $(TINFO_CFLAGS)
+else
+if HAVE_NCURSES
+libtcolors_la_LIBADD += $(NCURSES_LIBS)
+libtcolors_la_CFLAGS += $(NCURSES_CFLAGS)
+endif
+endif # !HAVE_TINFO
 
 dist_man_MANS += lib/terminal-colors.d.5
 
index b2742e4e9f858d77196e88ac73fc1fb232ec0b26..72c5158cb3d551e875ebcd3ce161acecff8e60ef 100644 (file)
 #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;