aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-20 05:21:46 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-20 05:21:46 +0000
commit122a7b5393bd3539e5919ec936e9f66e786343a1 (patch)
tree50a5714e18f7bfb4b180da7dfd2c157678f3dfc6
parent34fff22d84d816b774a0b2bafbab01a2297107c6 (diff)
downloadpaludis-122a7b5393bd3539e5919ec936e9f66e786343a1.tar.gz
paludis-122a7b5393bd3539e5919ec936e9f66e786343a1.tar.xz
Don't use colour for non-tty output or for dumb terminals.
-rw-r--r--src/colour.cc10
-rw-r--r--src/colour.hh4
2 files changed, 13 insertions, 1 deletions
diff --git a/src/colour.cc b/src/colour.cc
index 92c8d72..0df7d41 100644
--- a/src/colour.cc
+++ b/src/colour.cc
@@ -19,4 +19,14 @@
*/
#include "colour.hh"
+#include <unistd.h>
+#include <paludis/getenv.hh>
+bool use_colour()
+{
+ static bool result(
+ (1 == isatty(1)) &&
+ (0 != paludis::getenv_with_default("TERM", "").compare(0, 4, "dumb")));
+
+ return result;
+}
diff --git a/src/colour.hh b/src/colour.hh
index 20a3d4d..cf6563b 100644
--- a/src/colour.hh
+++ b/src/colour.hh
@@ -43,10 +43,12 @@ enum Colour
cl_masked = cl_flag_off
};
+bool use_colour() PALUDIS_ATTRIBUTE((nothrow,pure));
+
template <typename T_>
std::string colour(Colour colour, const T_ & s)
{
- if (CommandLine::get_instance()->a_no_color.specified())
+ if (CommandLine::get_instance()->a_no_color.specified() || ! use_colour())
return paludis::stringify(s);
else
return "\033[" + paludis::stringify(static_cast<unsigned>(colour) / 100) + ";"