llvm.org GIT mirror llvm / f7364d5
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 Chandler Carruth 6 years ago
9 changed file(s) with 432 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
122122 set(LLVM_TARGET_ARCH "host"
123123 CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
124124
125 option(LLVM_ENABLE_CURSES "Use curses to detect terminal info if available." ON)
126
125127 option(LLVM_ENABLE_THREADS "Use threads if available." ON)
126128
127129 option(LLVM_ENABLE_ZLIB "Use zlib for compression/decompression if available." ON)
10711071 AC_DEFINE_UNQUOTED(BUG_REPORT_URL,"$withval",
10721072 [Bug report URL.])
10731073
1074 dnl --enable-curses: check whether the user wants to control use of curses:
1075 AC_ARG_ENABLE(curses,AS_HELP_STRING(
1076 [--enable-curses],
1077 [Use curses for querying terminal infomation if available (default is YES)]),
1078 [case "$enableval" in
1079 yes) llvm_cv_enable_curses="yes" ;;
1080 no) llvm_cv_enable_curses="no" ;;
1081 *) AC_MSG_ERROR([Invalid setting for --enable-curses. Use "yes" or "no"]) ;;
1082 esac],
1083 llvm_cv_enable_curses="yes")
1084
10741085 dnl --enable-libffi : check whether the user wants to turn off libffi:
10751086 AC_ARG_ENABLE(libffi,AS_HELP_STRING(
10761087 --enable-libffi,[Check for the presence of libffi (default is NO)]),
13761387 dnl macros to detect whether clock_gettime is available, this just finds the
13771388 dnl right libraries to link with.
13781389 AC_SEARCH_LIBS(clock_gettime,rt)
1390
1391 dnl The curses library is optional; used for querying terminal info
1392 if test "$llvm_cv_enable_curses" = "yes" ; then
1393 dnl We need the has_color functionality in curses for it to be useful.
1394 AC_SEARCH_LIBS(has_colors,curses ncurses ncursesw,
1395 AC_DEFINE([HAVE_CURSES],[1],
1396 [Define if curses provides the has_color() function on this platform.]))
1397 fi
13791398
13801399 dnl libffi is optional; used to call external functions from the interpreter
13811400 if test "$llvm_cv_enable_libffi" = "yes" ; then
15531572 AC_SUBST(HAVE_LIBZ, 0)
15541573 fi
15551574
1575 dnl Try to find a suitable curses header.
1576 if test "$llvm_cv_enable_curses" = "yes" ; then
1577 AC_CHECK_HEADERS([curses.h ncurses.h ncursesw.h ncurses/curses.h ncursesw/curses.h])
1578 fi
1579
15561580 dnl Try to find ffi.h.
15571581 if test "$llvm_cv_enable_libffi" = "yes" ; then
15581582 AC_CHECK_HEADERS([ffi.h ffi/ffi.h])
7373 check_include_file(mach/mach.h HAVE_MACH_MACH_H)
7474 check_include_file(mach-o/dyld.h HAVE_MACH_O_DYLD_H)
7575
76 check_include_file(curses.h HAVE_CURSES_H)
77 check_include_file(ncurses.h HAVE_NCURSES_H)
78 check_include_file(ncursesw.h HAVE_NCURSESW_H)
79 check_include_file(ncurses/curses.h HAVE_NCURSES_CURSES_H)
80 check_include_file(ncursesw/curses.h HAVE_NCURSESW_CURSES_H)
81
7682 # library checks
7783 if( NOT PURE_WINDOWS )
7884 check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD)
95101 check_library_exists(z compress2 "" HAVE_LIBZ)
96102 else()
97103 set(HAVE_LIBZ 0)
104 endif()
105 if(LLVM_ENABLE_CURSES)
106 check_library_exists(curses has_colors "" HAVE_CURSES)
107 if(NOT HAVE_CURSES)
108 check_library_exists(ncurses has_colors "" HAVE_NCURSES)
109 set(HAVE_CURSES ${HAVE_NCURSES})
110 if(NOT HAVE_CURSES)
111 check_library_exists(ncursesw has_colors "" HAVE_NCURSESW)
112 set(HAVE_CURSES ${HAVE_NCURSESW})
113 endif()
114 endif()
115 else()
116 set(HAVE_CURSES 0)
98117 endif()
99118 endif()
100119
88 endif()
99 if( HAVE_LIBDL )
1010 set(system_libs ${system_libs} ${CMAKE_DL_LIBS})
11 endif()
12 if(LLVM_ENABLE_CURSES)
13 if(HAVE_NCURSESW)
14 set(system_libs ${system_libs} ncursesw)
15 elseif(HAVE_NCURSES)
16 set(system_libs ${system_libs} ncurses)
17 elseif(HAVE_CURSES)
18 set(system_libs ${system_libs} curses)
19 endif()
1120 endif()
1221 if( LLVM_ENABLE_THREADS AND HAVE_LIBPTHREAD )
1322 set(system_libs ${system_libs} pthread)
1818 set(TARGET_TRIPLE "@TARGET_TRIPLE@")
1919
2020 set(LLVM_TOOLS_BINARY_DIR @LLVM_TOOLS_BINARY_DIR@)
21
22 set(LLVM_ENABLE_CURSES @LLVM_ENABLE_CURSES@)
2123
2224 set(LLVM_ENABLE_THREADS @LLVM_ENABLE_THREADS@)
2325
14521452 target1,target2,... (default=disable)
14531453 --enable-bindings Build specific language bindings:
14541454 all,auto,none,{binding-name} (default=auto)
1455 --enable-curses Use curses for querying terminal infomation if
1456 available (default is YES)
14551457 --enable-libffi Check for the presence of libffi (default is NO)
14561458 --enable-ltdl-install install libltdl
14571459
60036005 _ACEOF
60046006
60056007
6008 # Check whether --enable-curses was given.
6009 if test "${enable_curses+set}" = set; then
6010 enableval=$enable_curses; case "$enableval" in
6011 yes) llvm_cv_enable_curses="yes" ;;
6012 no) llvm_cv_enable_curses="no" ;;
6013 *) { { echo "$as_me:$LINENO: error: Invalid setting for --enable-curses. Use \"yes\" or \"no\"" >&5
6014 echo "$as_me: error: Invalid setting for --enable-curses. Use \"yes\" or \"no\"" >&2;}
6015 { (exit 1); exit 1; }; } ;;
6016 esac
6017 else
6018 llvm_cv_enable_curses="yes"
6019 fi
6020
6021
60066022 # Check whether --enable-libffi was given.
60076023 if test "${enable_libffi+set}" = set; then
60086024 enableval=$enable_libffi; case "$enableval" in
1054410560 lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
1054510561 lt_status=$lt_dlunknown
1054610562 cat > conftest.$ac_ext <
10547 #line 10548 "configure"
10563 #line 10564 "configure"
1054810564 #include "confdefs.h"
1054910565
1055010566 #if HAVE_DLFCN_H
1225112267 fi
1225212268
1225312269
12270 if test "$llvm_cv_enable_curses" = "yes" ; then
12271 { echo "$as_me:$LINENO: checking for library containing has_colors" >&5
12272 echo $ECHO_N "checking for library containing has_colors... $ECHO_C" >&6; }
12273 if test "${ac_cv_search_has_colors+set}" = set; then
12274 echo $ECHO_N "(cached) $ECHO_C" >&6
12275 else
12276 ac_func_search_save_LIBS=$LIBS
12277 cat >conftest.$ac_ext <<_ACEOF
12278 /* confdefs.h. */
12279 _ACEOF
12280 cat confdefs.h >>conftest.$ac_ext
12281 cat >>conftest.$ac_ext <<_ACEOF
12282 /* end confdefs.h. */
12283
12284 /* Override any GCC internal prototype to avoid an error.
12285 Use char because int might match the return type of a GCC
12286 builtin and then its argument prototype would still apply. */
12287 #ifdef __cplusplus
12288 extern "C"
12289 #endif
12290 char has_colors ();
12291 int
12292 main ()
12293 {
12294 return has_colors ();
12295 ;
12296 return 0;
12297 }
12298 _ACEOF
12299 for ac_lib in '' curses ncurses ncursesw; do
12300 if test -z "$ac_lib"; then
12301 ac_res="none required"
12302 else
12303 ac_res=-l$ac_lib
12304 LIBS="-l$ac_lib $ac_func_search_save_LIBS"
12305 fi
12306 rm -f conftest.$ac_objext conftest$ac_exeext
12307 if { (ac_try="$ac_link"
12308 case "(($ac_try" in
12309 *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
12310 *) ac_try_echo=$ac_try;;
12311 esac
12312 eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
12313 (eval "$ac_link") 2>conftest.er1
12314 ac_status=$?
12315 grep -v '^ *+' conftest.er1 >conftest.err
12316 rm -f conftest.er1
12317 cat conftest.err >&5
12318 echo "$as_me:$LINENO: \$? = $ac_status" >&5
12319 (exit $ac_status); } &&
12320 { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
12321 { (case "(($ac_try" in
12322 *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
12323 *) ac_try_echo=$ac_try;;
12324 esac
12325 eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
12326 (eval "$ac_try") 2>&5
12327 ac_status=$?
12328 echo "$as_me:$LINENO: \$? = $ac_status" >&5
12329 (exit $ac_status); }; } &&
12330 { ac_try='test -s conftest$ac_exeext'
12331 { (case "(($ac_try" in
12332 *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
12333 *) ac_try_echo=$ac_try;;
12334 esac
12335 eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
12336 (eval "$ac_try") 2>&5
12337 ac_status=$?
12338 echo "$as_me:$LINENO: \$? = $ac_status" >&5
12339 (exit $ac_status); }; }; then
12340 ac_cv_search_has_colors=$ac_res
12341 else
12342 echo "$as_me: failed program was:" >&5
12343 sed 's/^/| /' conftest.$ac_ext >&5
12344
12345
12346 fi
12347
12348 rm -f core conftest.err conftest.$ac_objext \
12349 conftest$ac_exeext
12350 if test "${ac_cv_search_has_colors+set}" = set; then
12351 break
12352 fi
12353 done
12354 if test "${ac_cv_search_has_colors+set}" = set; then
12355 :
12356 else
12357 ac_cv_search_has_colors=no
12358 fi
12359 rm conftest.$ac_ext
12360 LIBS=$ac_func_search_save_LIBS
12361 fi
12362 { echo "$as_me:$LINENO: result: $ac_cv_search_has_colors" >&5
12363 echo "${ECHO_T}$ac_cv_search_has_colors" >&6; }
12364 ac_res=$ac_cv_search_has_colors
12365 if test "$ac_res" != no; then
12366 test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
12367
12368 cat >>confdefs.h <<\_ACEOF
12369 #define HAVE_CURSES 1
12370 _ACEOF
12371
12372 fi
12373
12374 fi
12375
1225412376 if test "$llvm_cv_enable_libffi" = "yes" ; then
1225512377 { echo "$as_me:$LINENO: checking for library containing ffi_call" >&5
1225612378 echo $ECHO_N "checking for library containing ffi_call... $ECHO_C" >&6; }
1641716539
1641816540 else
1641916541 HAVE_LIBZ=0
16542
16543 fi
16544
16545 if test "$llvm_cv_enable_curses" = "yes" ; then
16546
16547
16548
16549
16550
16551 for ac_header in curses.h ncurses.h ncursesw.h ncurses/curses.h ncursesw/curses.h
16552 do
16553 as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
16554 if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
16555 { echo "$as_me:$LINENO: checking for $ac_header" >&5
16556 echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; }
16557 if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
16558 echo $ECHO_N "(cached) $ECHO_C" >&6
16559 fi
16560 ac_res=`eval echo '${'$as_ac_Header'}'`
16561 { echo "$as_me:$LINENO: result: $ac_res" >&5
16562 echo "${ECHO_T}$ac_res" >&6; }
16563 else
16564 # Is the header compilable?
16565 { echo "$as_me:$LINENO: checking $ac_header usability" >&5
16566 echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6; }
16567 cat >conftest.$ac_ext <<_ACEOF
16568 /* confdefs.h. */
16569 _ACEOF
16570 cat confdefs.h >>conftest.$ac_ext
16571 cat >>conftest.$ac_ext <<_ACEOF
16572 /* end confdefs.h. */
16573 $ac_includes_default
16574 #include <$ac_header>
16575 _ACEOF
16576 rm -f conftest.$ac_objext
16577 if { (ac_try="$ac_compile"
16578 case "(($ac_try" in
16579 *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
16580 *) ac_try_echo=$ac_try;;
16581 esac
16582 eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
16583 (eval "$ac_compile") 2>conftest.er1
16584 ac_status=$?
16585 grep -v '^ *+' conftest.er1 >conftest.err
16586 rm -f conftest.er1
16587 cat conftest.err >&5
16588 echo "$as_me:$LINENO: \$? = $ac_status" >&5
16589 (exit $ac_status); } &&
16590 { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
16591 { (case "(($ac_try" in
16592 *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
16593 *) ac_try_echo=$ac_try;;
16594 esac
16595 eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
16596 (eval "$ac_try") 2>&5
16597 ac_status=$?
16598 echo "$as_me:$LINENO: \$? = $ac_status" >&5
16599 (exit $ac_status); }; } &&
16600 { ac_try='test -s conftest.$ac_objext'
16601 { (case "(($ac_try" in
16602 *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
16603 *) ac_try_echo=$ac_try;;
16604 esac
16605 eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
16606 (eval "$ac_try") 2>&5
16607 ac_status=$?
16608 echo "$as_me:$LINENO: \$? = $ac_status" >&5
16609 (exit $ac_status); }; }; then
16610 ac_header_compiler=yes
16611 else
16612 echo "$as_me: failed program was:" >&5
16613 sed 's/^/| /' conftest.$ac_ext >&5
16614
16615 ac_header_compiler=no
16616 fi
16617
16618 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
16619 { echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
16620 echo "${ECHO_T}$ac_header_compiler" >&6; }
16621
16622 # Is the header present?
16623 { echo "$as_me:$LINENO: checking $ac_header presence" >&5
16624 echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6; }
16625 cat >conftest.$ac_ext <<_ACEOF
16626 /* confdefs.h. */
16627 _ACEOF
16628 cat confdefs.h >>conftest.$ac_ext
16629 cat >>conftest.$ac_ext <<_ACEOF
16630 /* end confdefs.h. */
16631 #include <$ac_header>
16632 _ACEOF
16633 if { (ac_try="$ac_cpp conftest.$ac_ext"
16634 case "(($ac_try" in
16635 *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
16636 *) ac_try_echo=$ac_try;;
16637 esac
16638 eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
16639 (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
16640 ac_status=$?
16641 grep -v '^ *+' conftest.er1 >conftest.err
16642 rm -f conftest.er1
16643 cat conftest.err >&5
16644 echo "$as_me:$LINENO: \$? = $ac_status" >&5
16645 (exit $ac_status); } >/dev/null; then
16646 if test -s conftest.err; then
16647 ac_cpp_err=$ac_c_preproc_warn_flag
16648 ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
16649 else
16650 ac_cpp_err=
16651 fi
16652 else
16653 ac_cpp_err=yes
16654 fi
16655 if test -z "$ac_cpp_err"; then
16656 ac_header_preproc=yes
16657 else
16658 echo "$as_me: failed program was:" >&5
16659 sed 's/^/| /' conftest.$ac_ext >&5
16660
16661 ac_header_preproc=no
16662 fi
16663
16664 rm -f conftest.err conftest.$ac_ext
16665 { echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
16666 echo "${ECHO_T}$ac_header_preproc" >&6; }
16667
16668 # So? What about this header?
16669 case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
16670 yes:no: )
16671 { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
16672 echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
16673 { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
16674 echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
16675 ac_header_preproc=yes
16676 ;;
16677 no:yes:* )
16678 { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
16679 echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
16680 { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5
16681 echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;}
16682 { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
16683 echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
16684 { echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5
16685 echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;}
16686 { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
16687 echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
16688 { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
16689 echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
16690 ( cat <<\_ASBOX
16691 ## ------------------------------------ ##
16692 ## Report this to http://llvm.org/bugs/ ##
16693 ## ------------------------------------ ##
16694 _ASBOX
16695 ) | sed "s/^/$as_me: WARNING: /" >&2
16696 ;;
16697 esac
16698 { echo "$as_me:$LINENO: checking for $ac_header" >&5
16699 echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; }
16700 if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
16701 echo $ECHO_N "(cached) $ECHO_C" >&6
16702 else
16703 eval "$as_ac_Header=\$ac_header_preproc"
16704 fi
16705 ac_res=`eval echo '${'$as_ac_Header'}'`
16706 { echo "$as_me:$LINENO: result: $ac_res" >&5
16707 echo "${ECHO_T}$ac_res" >&6; }
16708
16709 fi
16710 if test `eval echo '${'$as_ac_Header'}'` = yes; then
16711 cat >>confdefs.h <<_ACEOF
16712 #define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
16713 _ACEOF
16714
16715 fi
16716
16717 done
1642016718
1642116719 fi
1642216720
4646
4747 /* Define to 1 if you have the `closedir' function. */
4848 #cmakedefine HAVE_CLOSEDIR ${HAVE_CLOSEDIR}
49
50 /* Define if curses provides the has_color() function on this platform. */
51 #cmakedefine HAVE_CURSES
52
53 /* Define to 1 if you have the header file. */
54 #cmakedefine HAVE_CURSES_H
4955
5056 /* Define to 1 if you have the header file. */
5157 #cmakedefine HAVE_CXXABI_H ${HAVE_CXXABI_H}
255261 /* Define if mmap() can map files into memory */
256262 #undef HAVE_MMAP_FILE
257263
264 /* Define to 1 if you have the header file. */
265 #cmakedefine HAVE_NCURSESW_CURSES_H
266
267 /* Define to 1 if you have the header file. */
268 #cmakedefine HAVE_NCURSESW_H
269
270 /* Define to 1 if you have the header file. */
271 #cmakedefine HAVE_NCURSES_CURSES_H
272
273 /* Define to 1 if you have the header file. */
274 #cmakedefine HAVE_NCURSES_H
275
258276 /* Define to 1 if you have the header file, and it defines `DIR'. */
259277 #cmakedefine HAVE_NDIR_H ${HAVE_NDIR_H}
260278
6767
6868 /* can use __crashreporter_info__ */
6969 #undef HAVE_CRASHREPORTER_INFO
70
71 /* Define if curses provides the has_color() function on this platform. */
72 #undef HAVE_CURSES
73
74 /* Define to 1 if you have the header file. */
75 #undef HAVE_CURSES_H
7076
7177 /* Define to 1 if you have the header file. */
7278 #undef HAVE_CXXABI_H
281287 /* Define if mmap() can map files into memory */
282288 #undef HAVE_MMAP_FILE
283289
290 /* Define to 1 if you have the header file. */
291 #undef HAVE_NCURSESW_CURSES_H
292
293 /* Define to 1 if you have the header file. */
294 #undef HAVE_NCURSESW_H
295
296 /* Define to 1 if you have the header file. */
297 #undef HAVE_NCURSES_CURSES_H
298
299 /* Define to 1 if you have the header file. */
300 #undef HAVE_NCURSES_H
301
284302 /* Define to 1 if you have the header file, and it defines `DIR'. */
285303 #undef HAVE_NDIR_H
286304
1212
1313 #include "Unix.h"
1414 #include "llvm/ADT/Hashing.h"
15 #include "llvm/Support/Mutex.h"
16 #include "llvm/Support/MutexGuard.h"
1517 #include "llvm/Support/TimeValue.h"
1618 #ifdef HAVE_SYS_TIME_H
1719 #include
3335 #endif
3436 #ifdef HAVE_TERMIOS_H
3537 # include
38 #endif
39
40 // See if we can use curses to detect information about a terminal when
41 // connected to one.
42 #ifdef HAVE_CURSES
43 # if defined(HAVE_CURSES_H)
44 # include
45 # elif defined(HAVE_NCURSES_H)
46 # include
47 # elif defined(HAVE_NCURSESW_H)
48 # include
49 # elif defined(HAVE_NCURSES_CURSES_H)
50 # include
51 # elif defined(HAVE_NCURSESW_CURSES_H)
52 # include
53 # else
54 # error Have a curses library but unable to find a curses header!
55 # endif
56 # include
3657 #endif
3758
3859 //===----------------------------------------------------------------------===//
244265 return getColumns(2);
245266 }
246267
247 static bool terminalHasColors() {
248 if (const char *term = std::getenv("TERM")) {
249 // Most modern terminals support ANSI escape sequences for colors.
250 // We could check terminfo, or have a list of known terms that support
251 // colors, but that would be overkill.
252 // The user can always ask for no colors by setting TERM to dumb, or
253 // using a commandline flag.
254 return strcmp(term, "dumb") != 0;
255 }
268 static bool terminalHasColors(int fd) {
269 #ifdef HAVE_CURSES
270 // First, acquire a global lock because the curses C routines are thread
271 // hostile.
272 static sys::Mutex M;
273 MutexGuard G(M);
274
275 int errret = 0;
276 if (setupterm((char *)0, fd, &errret) != OK)
277 // Regardless of why, if we can't get terminfo, we shouldn't try to print
278 // colors.
279 return false;
280
281 // Test whether the terminal as set up supports color output.
282 if (has_colors() == TRUE)
283 return true;
284 #endif
285
286 // Otherwise, be conservative.
256287 return false;
257288 }
258289
259290 bool Process::FileDescriptorHasColors(int fd) {
260291 // A file descriptor has colors if it is displayed and the terminal has
261292 // colors.
262 return FileDescriptorIsDisplayed(fd) && terminalHasColors();
293 return FileDescriptorIsDisplayed(fd) && terminalHasColors(fd);
263294 }
264295
265296 bool Process::StandardOutHasColors() {