AC_SUBST([TINFO_LIBS])
AC_SUBST([TINFO_CFLAGS])
AM_CONDITIONAL([HAVE_TINFO], [test "x$have_tinfo" = xyes])
+AS_IF([test "x$have_tinfo" = xyes],
+ AC_DEFINE(HAVE_LIBTINFO, 1, [Define if libtinfo available.])
+])
AC_ARG_WITH([utempter],
disk-utils/fdisk-list.c \
disk-utils/fdisk-list.h
-fdisk_LDADD = $(LDADD) libcommon.la libfdisk.la libsmartcols.la
+fdisk_LDADD = $(LDADD) libcommon.la libfdisk.la libsmartcols.la libtcolors.la
fdisk_CFLAGS = $(AM_CFLAGS) -I$(ul_libfdisk_incdir) -I$(ul_libsmartcols_incdir)
if BUILD_LIBBLKID
disk-utils/fdisk-list.c \
disk-utils/fdisk-list.h
-sfdisk_LDADD = $(LDADD) libcommon.la libfdisk.la libsmartcols.la
+sfdisk_LDADD = $(LDADD) libcommon.la libfdisk.la libsmartcols.la libtcolors.la
sfdisk_CFLAGS = $(AM_CFLAGS) -I$(ul_libfdisk_incdir) -I$(ul_libsmartcols_incdir)
if BUILD_LIBUUID
sbin_PROGRAMS += cfdisk
dist_man_MANS += disk-utils/cfdisk.8
cfdisk_SOURCES = disk-utils/cfdisk.c
-cfdisk_LDADD = $(LDADD) libcommon.la libfdisk.la
+cfdisk_LDADD = $(LDADD) libcommon.la libfdisk.la libtcolors.la
cfdisk_CFLAGS = $(AM_CFLAGS) -I$(ul_libfdisk_incdir)
if BUILD_LIBUUID
lib/at.c \
lib/blkdev.c \
lib/canonicalize.c \
- lib/colors.c \
lib/crc32.c \
lib/crc64.c \
lib/env.c \
libcommon_la_SOURCES += lib/cpuset.c
endif
+
+noinst_LTLIBRARIES += libtcolors.la
+libtcolors_la_CFLAGS = $(AM_CFLAGS) $(TINFO_CFLAGS)
+libtcolors_la_LIBADD = $(TINFO_LIBS)
+libtcolors_la_SOURCES = lib/colors.c include/colors.h
+
dist_man_MANS += lib/terminal-colors.d.5
+
check_PROGRAMS += \
test_at \
test_blkdev \
test_strutils \
test_ttyutils
+
+
+
if LINUX
if HAVE_CPU_SET_T
check_PROGRAMS += test_cpuset
test_strutils_CFLAGS = -DTEST_PROGRAM
test_colors_SOURCES = lib/colors.c
-test_colors_CFLAGS = -DTEST_PROGRAM
+test_colors_CFLAGS = -DTEST_PROGRAM $(TINFO_CFLAGS)
+test_colors_LDADD = $(LDADD) $(TINFO_LIBS)
test_randutils_SOURCES = lib/randutils.c
test_randutils_CFLAGS = -DTEST_PROGRAM
#include <sys/types.h>
#include <dirent.h>
#include <ctype.h>
+#ifdef HAVE_LIBTINFO
+# include <curses.h>
+# include <term.h>
+#endif
#include "c.h"
#include "colors.h"
__UL_INIT_DEBUG(termcolors, TERMCOLORS_DEBUG_, 0, TERMINAL_COLORS_DEBUG);
}
+static int colors_terminal_is_ready(void)
+{
+ int ncolors = -1;
+
+ if (isatty(STDOUT_FILENO) != 1)
+ goto none;
+
+#ifdef HAVE_LIBTINFO
+ {
+ int ret;
+
+ if (setupterm(NULL, STDOUT_FILENO, &ret) != OK || 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;
+none:
+ DBG(CONF, ul_debug("terminal is NOT ready"));
+ return 0;
+}
+
/**
* colors_init:
* @mode: UL_COLORMODE_*
*/
int colors_init(int mode, const char *name)
{
- int atty = -1;
+ int ready = -1;
struct ul_color_ctl *cc = &ul_colors;
cc->utilname = name;
termcolors_init_debug();
- if (mode == UL_COLORMODE_UNDEF && (atty = isatty(STDOUT_FILENO))) {
+ if (mode == UL_COLORMODE_UNDEF && (ready = colors_terminal_is_ready())) {
int rc = colors_read_configuration(cc);
if (rc)
cc->mode = UL_COLORMODE_DEFAULT;
switch (cc->mode) {
case UL_COLORMODE_AUTO:
- cc->has_colors = atty == -1 ? isatty(STDOUT_FILENO) : atty;
+ cc->has_colors = ready == -1 ? colors_terminal_is_ready() : ready;
break;
case UL_COLORMODE_ALWAYS:
cc->has_colors = 1;
nodist_libsmartcols_la_SOURCES = libsmartcols/src/smartcolsP.h
-libsmartcols_la_LIBADD = libcommon.la
+libsmartcols_la_LIBADD = libcommon.la libtcolors.la
libsmartcols_la_CFLAGS = \
$(SOLIB_CFLAGS) \
libsmartcols_la_DEPENDENCIES = \
libcommon.la \
+ libtcolors.la \
libsmartcols/src/libsmartcols.sym \
libsmartcols/src/libsmartcols.h.in
check_PROGRAMS += test_smartcols
libsmartcols_tests_cflags = $(libsmartcols_la_CFLAGS)
-libsmartcols_tests_ldadd = libsmartcols.la libcommon.la
+libsmartcols_tests_ldadd = libsmartcols.la libcommon.la libtcolors.la
test_smartcols_SOURCES = libsmartcols/src/test.c
test_smartcols_CFLAGS = $(libsmartcols_tests_cflags)
endif
cal_CFLAGS = $(AM_CFLAGS) $(NCURSES_CFLAGS)
-cal_LDADD = $(LDADD) libcommon.la $(NCURSES_LIBS) $(TINFO_LIBS)
+cal_LDADD = $(LDADD) libcommon.la libtcolors.la $(NCURSES_LIBS)
if HAVE_TERMCAP
cal_LDADD += -ltermcap
endif
bin_PROGRAMS += dmesg
dist_man_MANS += sys-utils/dmesg.1
dmesg_SOURCES = sys-utils/dmesg.c lib/monotonic.c
-dmesg_LDADD = $(LDADD) libcommon.la $(CLOCKGETTIME_LIBS)
+dmesg_LDADD = $(LDADD) libcommon.la libtcolors.la $(CLOCKGETTIME_LIBS)
+dmesg_CFLAGS = $(AM_CFLAGS)
endif
if BUILD_CTRLALTDEL
text-utils/hexdump.c \
text-utils/hexdump.h \
text-utils/hexdump-parse.c
-hexdump_LDADD = $(LDADD) libcommon.la
+hexdump_LDADD = $(LDADD) libcommon.la libtcolors.la
endif
if BUILD_REV