Add support for linking against a curses library when available and

using it to detect whether or not a terminal supports colors. This
replaces a particularly egregious hack that merely compared the TERM
environment variable to "dumb". That doesn't really translate to
a reasonable experience for users that have actually ensured their
terminal's capabilities are accurately reflected.

This makes testing a terminal for color support somewhat more expensive,
but it is called very rarely anyways. The important fast path when the
output is being piped somewhere is already in place.

The global lock may seem excessive, but the spec for calling into curses
is *terrible*. The whole library is terrible, and I spent quite a bit of
time looking for a better way of doing this before convincing myself
that this was the fundamentally correct way to behave. The damage of the
curses library is very narrowly confined, and we continue to use raw
escape codes for actually manipulating the colors which is a much sane
system than directly using curses here (IMO).

If this causes trouble for folks, please let me know. I've tested it on
Linux and will watch the bots carefully. I've also worked to account for
the variances of curses interfaces that I could finde documentation for,
but that may not have been sufficient.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187874 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chandler Carruth
2013-08-07 08:47:36 +00:00
parent f76e118cf8
commit f7364d5833
9 changed files with 432 additions and 11 deletions

View File

@@ -48,6 +48,12 @@
/* Define to 1 if you have the `closedir' function. */
#cmakedefine HAVE_CLOSEDIR ${HAVE_CLOSEDIR}
/* Define if curses provides the has_color() function on this platform. */
#cmakedefine HAVE_CURSES
/* Define to 1 if you have the <curses.h> header file. */
#cmakedefine HAVE_CURSES_H
/* Define to 1 if you have the <cxxabi.h> header file. */
#cmakedefine HAVE_CXXABI_H ${HAVE_CXXABI_H}
@@ -256,6 +262,18 @@
/* Define if mmap() can map files into memory */
#undef HAVE_MMAP_FILE
/* Define to 1 if you have the <ncursesw/curses.h> header file. */
#cmakedefine HAVE_NCURSESW_CURSES_H
/* Define to 1 if you have the <ncursesw.h> header file. */
#cmakedefine HAVE_NCURSESW_H
/* Define to 1 if you have the <ncurses/curses.h> header file. */
#cmakedefine HAVE_NCURSES_CURSES_H
/* Define to 1 if you have the <ncurses.h> header file. */
#cmakedefine HAVE_NCURSES_H
/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
#cmakedefine HAVE_NDIR_H ${HAVE_NDIR_H}

View File

@@ -69,6 +69,12 @@
/* can use __crashreporter_info__ */
#undef HAVE_CRASHREPORTER_INFO
/* Define if curses provides the has_color() function on this platform. */
#undef HAVE_CURSES
/* Define to 1 if you have the <curses.h> header file. */
#undef HAVE_CURSES_H
/* Define to 1 if you have the <cxxabi.h> header file. */
#undef HAVE_CXXABI_H
@@ -282,6 +288,18 @@
/* Define if mmap() can map files into memory */
#undef HAVE_MMAP_FILE
/* Define to 1 if you have the <ncursesw/curses.h> header file. */
#undef HAVE_NCURSESW_CURSES_H
/* Define to 1 if you have the <ncursesw.h> header file. */
#undef HAVE_NCURSESW_H
/* Define to 1 if you have the <ncurses/curses.h> header file. */
#undef HAVE_NCURSES_CURSES_H
/* Define to 1 if you have the <ncurses.h> header file. */
#undef HAVE_NCURSES_H
/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
#undef HAVE_NDIR_H