aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-08-24 20:51:10 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-08-24 20:51:10 +0000
commit7cc7ca817d02755119cf6905d335f701f6100d41 (patch)
treec0ede7a50cc49007051e9bd4a9e300303f2fead1
parent279ae8bf6f8032e602aaf1058fb3f3584bdaf229 (diff)
downloadpaludis-7cc7ca817d02755119cf6905d335f701f6100d41.tar.gz
paludis-7cc7ca817d02755119cf6905d335f701f6100d41.tar.xz
Move colour code from src/paludis to src so that it can be used by qualudis and archtool.
-rw-r--r--src/Makefile.am5
-rw-r--r--src/colour.cc (renamed from src/paludis/colour.cc)20
-rw-r--r--src/colour.hh (renamed from src/paludis/colour.hh)8
-rw-r--r--src/paludis/Makefile.am5
-rw-r--r--src/paludis/contents.cc1
-rw-r--r--src/paludis/list.cc1
-rw-r--r--src/paludis/owner.cc1
-rw-r--r--src/paludis/paludis.cc1
8 files changed, 32 insertions, 10 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index fe09f67..311ffa8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,6 +1,7 @@
-SUBDIRS = paludis gtkpaludis qualudis archtool
+SUBDIRS = . paludis gtkpaludis qualudis archtool
CLEANFILES = *~ gmon.out *.gcov *.gcno *.gcda
MAINTAINERCLEANFILES = Makefile.in
-
+noinst_LIBRARIES = libcolour.a
+libcolour_a_SOURCES = colour.cc colour.hh
diff --git a/src/paludis/colour.cc b/src/colour.cc
index 6a81e44..cfad0b5 100644
--- a/src/paludis/colour.cc
+++ b/src/colour.cc
@@ -21,8 +21,17 @@
#include <paludis/util/system.hh>
#include <unistd.h>
-bool use_colour()
+namespace
{
+ static bool can_use_colour = true;
+}
+
+bool
+use_colour()
+{
+ if (! can_use_colour)
+ return false;
+
static bool result(
(1 == isatty(1)) &&
(0 != paludis::getenv_with_default("TERM", "").compare(0, 4, "dumb")));
@@ -30,7 +39,14 @@ bool use_colour()
return result;
}
-bool use_xterm_titles()
+void
+set_use_colour(const bool value)
+{
+ can_use_colour = value;
+}
+
+bool
+use_xterm_titles()
{
static bool result(
(0 != paludis::getenv_with_default("TERM", "").compare(0, 4, "dumb")) &&
diff --git a/src/paludis/colour.hh b/src/colour.hh
index 62b58bd..a1f5ef1 100644
--- a/src/paludis/colour.hh
+++ b/src/colour.hh
@@ -20,7 +20,6 @@
#ifndef PALUDIS_GUARD_SRC_COLOUR_HH
#define PALUDIS_GUARD_SRC_COLOUR_HH 1
-#include "command_line.hh"
#include <paludis/util/stringify.hh>
#include <config.h>
#include <string>
@@ -75,13 +74,14 @@ enum Colour
cl_misc = cl_red
};
-bool use_colour() PALUDIS_ATTRIBUTE((pure));
+bool use_colour();
+void set_use_colour(const bool value);
bool use_xterm_titles() PALUDIS_ATTRIBUTE((pure));
template <typename T_>
std::string colour(Colour colour, const T_ & s)
{
- if (CommandLine::get_instance()->a_no_color.specified() || ! use_colour())
+ if (! use_colour())
return paludis::stringify(s);
else if (cl_none != colour)
return "\033[" + paludis::stringify(static_cast<unsigned>(colour) / 100) + ";"
@@ -94,7 +94,7 @@ std::string colour(Colour colour, const T_ & s)
template <typename T_>
std::string xterm_title(const T_ & s)
{
- if (CommandLine::get_instance()->a_no_color.specified() || ! use_colour() || ! use_xterm_titles())
+ if (! use_colour() || ! use_xterm_titles())
return "";
else
return "\x1b]2;" + paludis::stringify(s) + "\x07";
diff --git a/src/paludis/Makefile.am b/src/paludis/Makefile.am
index eea67bb..fa6835f 100644
--- a/src/paludis/Makefile.am
+++ b/src/paludis/Makefile.am
@@ -1,4 +1,4 @@
-AM_CXXFLAGS = -I$(top_srcdir) @PALUDIS_CXXFLAGS@
+AM_CXXFLAGS = -I$(top_srcdir) -I$(top_srcdir)/src @PALUDIS_CXXFLAGS@
DEFS= \
-DSYSCONFDIR=\"$(sysconfdir)\" \
-DDATADIR=\"$(datadir)\" \
@@ -23,12 +23,12 @@ man_paludis_SOURCES = \
man_paludis_LDADD = \
$(top_builddir)/paludis/args/libpaludisargs.la \
$(top_builddir)/paludis/util/libpaludisutil.la \
+ $(top_builddir)/src/libcolour.a \
$(DYNAMIC_LD_LIBS)
paludis_SOURCES = \
applets.hh applets.cc \
command_line.hh command_line.cc \
- colour.hh colour.cc \
install.hh install.cc \
uninstall.hh uninstall.cc \
list.hh list.cc \
@@ -46,6 +46,7 @@ paludis_LDADD = \
$(top_builddir)/paludis/libpaludis.la \
$(top_builddir)/paludis/args/libpaludisargs.la \
$(top_builddir)/paludis/util/libpaludisutil.la \
+ $(top_builddir)/src/libcolour.a \
$(DYNAMIC_LD_LIBS)
TESTS_ENVIRONMENT = env \
diff --git a/src/paludis/contents.cc b/src/paludis/contents.cc
index 4aa9414..188fda4 100644
--- a/src/paludis/contents.cc
+++ b/src/paludis/contents.cc
@@ -19,6 +19,7 @@
#include "contents.hh"
#include "colour.hh"
+#include "command_line.hh"
#include <paludis/paludis.hh>
#include <iostream>
#include <algorithm>
diff --git a/src/paludis/list.cc b/src/paludis/list.cc
index 183b2a4..69a81fd 100644
--- a/src/paludis/list.cc
+++ b/src/paludis/list.cc
@@ -18,6 +18,7 @@
*/
#include "colour.hh"
+#include "command_line.hh"
#include "list.hh"
#include <iomanip>
#include <iostream>
diff --git a/src/paludis/owner.cc b/src/paludis/owner.cc
index 581c8f6..bf9b7eb 100644
--- a/src/paludis/owner.cc
+++ b/src/paludis/owner.cc
@@ -19,6 +19,7 @@
#include "owner.hh"
#include "colour.hh"
+#include "command_line.hh"
#include <paludis/paludis.hh>
#include <iostream>
diff --git a/src/paludis/paludis.cc b/src/paludis/paludis.cc
index 1045831..4035c92 100644
--- a/src/paludis/paludis.cc
+++ b/src/paludis/paludis.cc
@@ -134,6 +134,7 @@ main(int argc, char *argv[])
try
{
CommandLine::get_instance()->run(argc, argv);
+ set_use_colour(! CommandLine::get_instance()->a_no_color.specified());
if (CommandLine::get_instance()->a_help.specified())
throw DoHelp();