diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2013-08-12 09:49:17 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2013-08-12 09:49:17 +0000 |
commit | 8d8bdff6d7eccb05bf16e18141263ee72ea8296b (patch) | |
tree | 6433ea896c6e1bf5d2996bb770920fb1cd9d1682 /lib | |
parent | 6a4e44f0de6e59d4458e3795c765a9001ba1b87f (diff) | |
download | external_llvm-8d8bdff6d7eccb05bf16e18141263ee72ea8296b.zip external_llvm-8d8bdff6d7eccb05bf16e18141263ee72ea8296b.tar.gz external_llvm-8d8bdff6d7eccb05bf16e18141263ee72ea8296b.tar.bz2 |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188160 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Support/Unix/Process.inc | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/lib/Support/Unix/Process.inc b/lib/Support/Unix/Process.inc index 0a797f6..1bb3e22 100644 --- a/lib/Support/Unix/Process.inc +++ b/lib/Support/Unix/Process.inc @@ -38,9 +38,12 @@ # include <termios.h> #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 <curses.h> # elif defined(HAVE_NCURSES_H) @@ -51,10 +54,10 @@ # include <ncurses/curses.h> # elif defined(HAVE_NCURSESW_CURSES_H) # include <ncursesw/curses.h> -# else -# error Have a curses library but unable to find a curses header! # endif -# include <term.h> +# if defined(HAVE_TERM_H) +# include <term.h> +# 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 |