From f11f1e43de54b5f6e4e6ad7fc952482772177c9d Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Mon, 12 Aug 2013 09:49:17 +0000 Subject: Target a minimal terminfo library rather than necessarily a full curses library for color support detection. This still will use a curses library if that is all we have available on the system. This change tries to use a smaller subset of the curses library, specifically the subset that is on some systems split off into a separate library. For example, if you install ncurses configured --with-tinfo, a 'libtinfo' is install that provides just the terminfo querying functionality. That library is now used instead of curses when it is available. This happens to fix a build error on systems with that library because when we tried to link ncurses into the binary, we didn't pull tinfo in as well. =] It should also provide an easy path for supporting the NetBSD libterminfo library, but as I don't have access to a NetBSD system I'm leaving adding that support to those folks. llvm-svn: 188160 --- llvm/lib/Support/Unix/Process.inc | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'llvm/lib/Support/Unix/Process.inc') diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc index 0a797f6979e..1bb3e2244c6 100644 --- a/llvm/lib/Support/Unix/Process.inc +++ b/llvm/lib/Support/Unix/Process.inc @@ -38,9 +38,12 @@ # include #endif -// See if we can use curses to detect information about a terminal when -// connected to one. -#ifdef HAVE_CURSES +// Pull in the headers we found to go with the terminfo reading library (tinfo, +// curses, whatever it may be). We have to pull in the 'curses.h' header as the +// SysV spec only provides certain values and defines from that header even +// though we work hard to not link against all of the curses implementation +// when avoidable. +#ifdef HAVE_TERMINFO # if defined(HAVE_CURSES_H) # include # elif defined(HAVE_NCURSES_H) @@ -51,10 +54,10 @@ # include # elif defined(HAVE_NCURSESW_CURSES_H) # include -# else -# error Have a curses library but unable to find a curses header! # endif -# include +# if defined(HAVE_TERM_H) +# include +# endif #endif //===----------------------------------------------------------------------===// @@ -267,9 +270,8 @@ unsigned Process::StandardErrColumns() { } static bool terminalHasColors(int fd) { -#ifdef HAVE_CURSES - // First, acquire a global lock because the curses C routines are thread - // hostile. +#ifdef HAVE_TERMINFO + // First, acquire a global lock because these C routines are thread hostile. static sys::Mutex M; MutexGuard G(M); @@ -279,8 +281,20 @@ static bool terminalHasColors(int fd) { // colors. return false; - // Test whether the terminal as set up supports color output. - if (has_colors() == TRUE) + // Test whether the terminal as set up supports color output. How to do this + // isn't entirely obvious. We can use the curses routine 'has_colors' but it + // would be nice to avoid a dependency on curses proper when we can make do + // with a minimal terminfo parsing library. Also, we don't really care whether + // the terminal supports the curses-specific color changing routines, merely + // if it will interpret ANSI color escape codes in a reasonable way. Thus, the + // strategy here is just to query the baseline colors capability and if it + // supports colors at all to assume it will translate the escape codes into + // whatever range of colors it does support. We can add more detailed tests + // here if users report them as necessary. + // + // The 'tigetnum' routine returns -2 or -1 on errors, and might return 0 if + // the terminfo says that no colors are supported. + if (tigetnum("colors") > 0) return true; #endif -- cgit v1.2.3