aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-12-20 20:00:00 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-12-20 20:00:00 +0000
commit144871b1f6d1f624499740db9cf530eeb73da3e2 (patch)
tree40f742d0e0066fdab293160eb60e96198ffa7eaa
parente7714b31197640da5932644f9d1d0ccaa0b4326a (diff)
downloadpaludis-144871b1f6d1f624499740db9cf530eeb73da3e2.tar.gz
paludis-144871b1f6d1f624499740db9cf530eeb73da3e2.tar.xz
Replace use flag displaying code
-rw-r--r--src/Makefile.am4
-rw-r--r--src/console_install_task.cc13
-rw-r--r--src/console_install_task.hh6
-rw-r--r--src/paludis/install.cc1
-rw-r--r--src/paludis/query.cc11
-rw-r--r--src/use.cc125
-rw-r--r--src/use.hh36
-rw-r--r--src/use_flag_pretty_printer.cc239
-rw-r--r--src/use_flag_pretty_printer.hh67
9 files changed, 329 insertions, 173 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index c8a7911..803bb5e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -6,8 +6,8 @@ MAINTAINERCLEANFILES = Makefile.in
noinst_LIBRARIES = liboutput.a
liboutput_a_SOURCES = \
colour.cc colour.hh \
- use.cc use.hh \
- console_install_task.cc console_install_task.hh
+ console_install_task.cc console_install_task.hh \
+ use_flag_pretty_printer.cc use_flag_pretty_printer.cc
AM_CXXFLAGS = -I$(top_srcdir) -I$(top_srcdir)/src @PALUDIS_CXXFLAGS@
diff --git a/src/console_install_task.cc b/src/console_install_task.cc
index a577042..20858e8 100644
--- a/src/console_install_task.cc
+++ b/src/console_install_task.cc
@@ -19,7 +19,7 @@
#include "console_install_task.hh"
#include "colour.hh"
-#include "use.hh"
+#include "use_flag_pretty_printer.hh"
#include <paludis/util/log.hh>
#include <paludis/util/collection_concrete.hh>
@@ -499,8 +499,9 @@ ConsoleInstallTask::display_merge_list_entry_use(const DepListEntry & d,
if (d.skip_install)
return;
- output_no_endl(make_pretty_use_flags_string(environment(), d.package,
- d.metadata, existing->empty() ? 0 : &*existing->last()));
+ output_no_endl(" ");
+ UseFlagPrettyPrinter::Pointer printer(make_use_flag_pretty_printer());
+ printer->print_package_flags(d.package, existing->empty() ? 0 : &*existing->last());
}
void
@@ -691,6 +692,12 @@ ConsoleInstallTask::make_entry_dep_tag_displayer()
return EntryDepTagDisplayer::Pointer(new EntryDepTagDisplayer());
}
+UseFlagPrettyPrinter::Pointer
+ConsoleInstallTask::make_use_flag_pretty_printer()
+{
+ return UseFlagPrettyPrinter::Pointer(new UseFlagPrettyPrinter(environment()));
+}
+
EntryDepTagDisplayer::EntryDepTagDisplayer()
{
}
diff --git a/src/console_install_task.hh b/src/console_install_task.hh
index 0457b2c..64682df 100644
--- a/src/console_install_task.hh
+++ b/src/console_install_task.hh
@@ -22,6 +22,7 @@
#include <paludis/tasks/install_task.hh>
#include <paludis/package_database_entry.hh>
+#include <src/use_flag_pretty_printer.hh>
#include <iosfwd>
namespace paludis
@@ -133,8 +134,8 @@ namespace paludis
///\name Output routines
///\{
- std::ostream & output_stream() const;
- std::ostream & output_xterm_stream() const;
+ virtual std::ostream & output_stream() const;
+ virtual std::ostream & output_xterm_stream() const;
virtual void output_activity_start_message(const std::string &) const;
virtual void output_activity_end_message() const;
@@ -232,6 +233,7 @@ namespace paludis
DepTagSummaryDisplayer::Pointer make_dep_tag_summary_displayer();
EntryDepTagDisplayer::Pointer make_entry_dep_tag_displayer();
+ UseFlagPrettyPrinter::Pointer make_use_flag_pretty_printer();
///\}
};
diff --git a/src/paludis/install.cc b/src/paludis/install.cc
index c75d45d..da80594 100644
--- a/src/paludis/install.cc
+++ b/src/paludis/install.cc
@@ -20,7 +20,6 @@
#include "colour.hh"
#include "install.hh"
#include "licence.hh"
-#include "use.hh"
#include "console_install_task.hh"
#include <iostream>
diff --git a/src/paludis/query.cc b/src/paludis/query.cc
index 99a0752..6041c5e 100644
--- a/src/paludis/query.cc
+++ b/src/paludis/query.cc
@@ -20,7 +20,7 @@
#include "colour.hh"
#include "query.hh"
#include "licence.hh"
-#include "use.hh"
+#include "use_flag_pretty_printer.hh"
#include <functional>
#include <iomanip>
#include <iostream>
@@ -301,9 +301,12 @@ void do_one_package_query(
" " << metadata->get_ebuild_interface()->provide_string << endl;
if (! metadata->get_ebuild_interface()->iuse.empty())
- cout << " " << std::setw(22) << std::left << "Use flags:" << std::setw(0) <<
- " " << make_pretty_use_flags_string(DefaultEnvironment::get_instance(),
- display_entry, metadata) << endl;
+ {
+ cout << " " << std::setw(22) << std::left << "Use flags:" << std::setw(0) << " ";
+ UseFlagPrettyPrinter printer(DefaultEnvironment::get_instance());
+ printer.print_package_flags(display_entry);
+ cout << endl;
+ }
}
if (metadata->get_virtual_interface())
diff --git a/src/use.cc b/src/use.cc
deleted file mode 100644
index f598e48..0000000
--- a/src/use.cc
+++ /dev/null
@@ -1,125 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
- *
- * This file is part of the Paludis package manager. Paludis is free software;
- * you can redistribute it and/or modify it under the terms of the GNU General
- * Public License version 2, as published by the Free Software Foundation.
- *
- * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "use.hh"
-#include "colour.hh"
-#include <paludis/util/tokeniser.hh>
-#include <sstream>
-#include <set>
-
-using namespace paludis;
-
-namespace
-{
- std::string::size_type
- use_expand_delim_pos(const UseFlagName & u, const UseFlagNameCollection::ConstPointer c)
- {
- for (UseFlagNameCollection::Iterator i(c->begin()), i_end(c->end()) ; i != i_end ; ++i)
- if (0 == u.data().compare(0, i->data().length(), i->data(), 0, i->data().length()))
- return i->data().length();
- return std::string::npos;
- }
-}
-
-std::string
-make_pretty_use_flags_string(const Environment * const env, const PackageDatabaseEntry & p,
- VersionMetadata::ConstPointer metadata, const PackageDatabaseEntry * const other_p)
-{
- std::ostringstream c;
-
- if (metadata->get_ebuild_interface())
- {
- const RepositoryUseInterface * const use_interface(
- env->package_database()->
- fetch_repository(p.repository)->use_interface);
- std::set<UseFlagName> iuse;
- WhitespaceTokeniser::get_instance()->tokenise(
- metadata->get_ebuild_interface()->iuse,
- create_inserter<UseFlagName>(std::inserter(iuse, iuse.end())));
-
- /* display normal use flags first */
- for (std::set<UseFlagName>::const_iterator i(iuse.begin()), i_end(iuse.end()) ;
- i != i_end ; ++i)
- {
- if (std::string::npos != use_expand_delim_pos(*i, use_interface->use_expand_prefixes()))
- continue;
-
- if (env->query_use(*i, &p))
- {
- if (use_interface && use_interface->query_use_force(*i, &p))
- c << " " << colour(cl_flag_on, "(" + stringify(*i) + ")");
- else
- c << " " << colour(cl_flag_on, *i);
- }
- else
- {
- if (use_interface && use_interface->query_use_mask(*i, &p))
- c << " " << colour(cl_flag_off, "(-" + stringify(*i) + ")");
- else
- c << " " << colour(cl_flag_off, "-" + stringify(*i));
- }
-
- if (other_p)
- if (env->query_use(*i, &p) != env->query_use(*i, other_p))
- c << "*";
- }
-
- /* now display expand flags */
- UseFlagName old_expand_name("OFTEN_NOT_BEEN_ON_BOATS");
- for (std::set<UseFlagName>::const_iterator i(iuse.begin()), i_end(iuse.end()) ;
- i != i_end ; ++i)
- {
- std::string::size_type delim_pos;
- if (std::string::npos == ((delim_pos = use_expand_delim_pos(*i, use_interface->use_expand_prefixes()))))
- continue;
- if (use_interface->use_expand_hidden_prefixes()->count(UseFlagName(i->data().substr(0, delim_pos))))
- continue;
-
- UseFlagName expand_name(i->data().substr(0, delim_pos)), expand_value(i->data().substr(delim_pos + 1));
-
- if (expand_name != old_expand_name)
- {
- c << " " << expand_name << ":";
- old_expand_name = expand_name;
- }
-
- if (env->query_use(*i, &p))
- {
- if (use_interface && use_interface->query_use_force(*i, &p))
- c << " " << colour(cl_flag_on, "(" + stringify(expand_value) + ")");
- else
- c << " " << colour(cl_flag_on, expand_value);
- }
- else
- {
- if (use_interface && use_interface->query_use_mask(*i, &p))
- c << " " << colour(cl_flag_off, "(-" + stringify(expand_value) + ")");
- else
- c << " " << colour(cl_flag_off, "-" + stringify(expand_value));
- }
-
- if (other_p)
- if (env->query_use(*i, &p) != env->query_use(*i, other_p))
- c << "*";
- }
- }
-
- return c.str();
-}
-
diff --git a/src/use.hh b/src/use.hh
deleted file mode 100644
index ed7e846..0000000
--- a/src/use.hh
+++ /dev/null
@@ -1,36 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
- *
- * This file is part of the Paludis package manager. Paludis is free software;
- * you can redistribute it and/or modify it under the terms of the GNU General
- * Public License version 2, as published by the Free Software Foundation.
- *
- * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef PALUDIS_GUARD_SRC_PALUDIS_USE_HH
-#define PALUDIS_GUARD_SRC_PALUDIS_USE_HH 1
-
-#include <paludis/name.hh>
-#include <paludis/environment.hh>
-#include <paludis/package_database_entry.hh>
-#include <paludis/version_metadata.hh>
-
-/**
- * Make a nice string for outputting USE flags.
- */
-std::string
-make_pretty_use_flags_string(const paludis::Environment * const env, const paludis::PackageDatabaseEntry & p,
- paludis::VersionMetadata::ConstPointer metadata, const paludis::PackageDatabaseEntry * const other_p = 0)
- PALUDIS_ATTRIBUTE((nonnull(1)));
-
-#endif
diff --git a/src/use_flag_pretty_printer.cc b/src/use_flag_pretty_printer.cc
new file mode 100644
index 0000000..f1db730
--- /dev/null
+++ b/src/use_flag_pretty_printer.cc
@@ -0,0 +1,239 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "use_flag_pretty_printer.hh"
+#include <paludis/version_metadata.hh>
+#include <paludis/environment.hh>
+#include <paludis/util/tokeniser.hh>
+#include "colour.hh"
+#include <iostream>
+#include <set>
+
+using namespace paludis;
+
+UseFlagPrettyPrinter::UseFlagPrettyPrinter(const Environment * const e) :
+ _env(e),
+ _need_space(false)
+{
+}
+
+UseFlagPrettyPrinter::~UseFlagPrettyPrinter()
+{
+}
+
+std::string::size_type
+UseFlagPrettyPrinter::use_expand_delim_pos(const UseFlagName & u,
+ const UseFlagNameCollection::ConstPointer c) const
+{
+ for (UseFlagNameCollection::Iterator i(c->begin()), i_end(c->end()) ; i != i_end ; ++i)
+ if (0 == u.data().compare(0, i->data().length(), i->data(), 0, i->data().length()))
+ return i->data().length();
+ return std::string::npos;
+}
+
+void
+UseFlagPrettyPrinter::print_package_flags(const PackageDatabaseEntry & pkg,
+ const PackageDatabaseEntry * const old_pkg)
+{
+ std::set<UseFlagName> iuse, old_iuse;
+
+ VersionMetadata::ConstPointer metadata(environment()->package_database()->
+ fetch_repository(pkg.repository)->version_metadata(pkg.name, pkg.version));
+
+ if (! metadata->get_ebuild_interface())
+ return;
+
+ WhitespaceTokeniser::get_instance()->tokenise(metadata->get_ebuild_interface()->iuse,
+ create_inserter<UseFlagName>(std::inserter(iuse, iuse.begin())));
+
+ if (old_pkg)
+ {
+ VersionMetadata::ConstPointer old_metadata(environment()->package_database()->
+ fetch_repository(old_pkg->repository)->version_metadata(old_pkg->name, old_pkg->version));
+ if (old_metadata->get_ebuild_interface())
+ WhitespaceTokeniser::get_instance()->tokenise(old_metadata->get_ebuild_interface()->iuse,
+ create_inserter<UseFlagName>(std::inserter(old_iuse, old_iuse.begin())));
+ }
+
+ const RepositoryUseInterface * const use_interface(environment()->package_database()->
+ fetch_repository(pkg.repository)->use_interface);
+
+ /* first pass: only non-expand flags */
+ for (std::set<UseFlagName>::const_iterator flag(iuse.begin()), flag_end(iuse.end()) ;
+ flag != flag_end ; ++flag)
+ {
+ if (use_interface)
+ if (std::string::npos != use_expand_delim_pos(*flag, use_interface->use_expand_prefixes()))
+ continue;
+
+ if (environment()->query_use(*flag, &pkg))
+ {
+ if (use_interface && use_interface->query_use_force(*flag, &pkg))
+ output_flag(render_as_forced_flag(stringify(*flag)));
+ else
+ output_flag(render_as_enabled_flag(stringify(*flag)));
+ }
+ else
+ {
+ if (use_interface && use_interface->query_use_mask(*flag, &pkg))
+ output_flag(render_as_masked_flag(stringify(*flag)));
+ else
+ output_flag(render_as_disabled_flag(stringify(*flag)));
+ }
+
+ if (old_pkg)
+ {
+ if (old_iuse.end() != old_iuse.find(*flag))
+ {
+ if (environment()->query_use(*flag, &pkg) != environment()->query_use(*flag, old_pkg))
+ output_flag_changed_mark();
+ }
+ else
+ output_flag_is_new_mark();
+ }
+ }
+
+ /* second pass: only expand flags */
+ UseFlagName old_expand_name("OFTEN_NOT_BEEN_ON_BOATS");
+ for (std::set<UseFlagName>::const_iterator flag(iuse.begin()), flag_end(iuse.end()) ;
+ flag != flag_end ; ++flag)
+ {
+ std::string::size_type delim_pos(0);
+ if (use_interface)
+ {
+ if (std::string::npos == ((delim_pos = use_expand_delim_pos(*flag,
+ use_interface->use_expand_prefixes()))))
+ continue;
+ if (use_interface->use_expand_hidden_prefixes()->count(UseFlagName(flag->data().substr(0, delim_pos))))
+ continue;
+ }
+
+ UseFlagName expand_name(flag->data().substr(0, delim_pos)),
+ expand_value(flag->data().substr(delim_pos + 1));
+
+ if (expand_name != old_expand_name)
+ {
+ output_expand_prefix(stringify(expand_name));
+ old_expand_name = expand_name;
+ }
+
+ if (environment()->query_use(*flag, &pkg))
+ {
+ if (use_interface && use_interface->query_use_force(*flag, &pkg))
+ output_flag(render_as_forced_flag(stringify(expand_value)));
+ else
+ output_flag(render_as_enabled_flag(stringify(expand_value)));
+ }
+ else
+ {
+ if (use_interface && use_interface->query_use_mask(*flag, &pkg))
+ output_flag(render_as_masked_flag(stringify(expand_value)));
+ else
+ output_flag(render_as_disabled_flag(stringify(expand_value)));
+ }
+
+ if (old_pkg)
+ {
+ if (old_iuse.end() != old_iuse.find(*flag))
+ {
+ if (environment()->query_use(*flag, &pkg) != environment()->query_use(*flag, old_pkg))
+ output_flag_changed_mark();
+ }
+ else
+ output_flag_is_new_mark();
+ }
+ }
+}
+
+void
+UseFlagPrettyPrinter::output_flag(const std::string & s)
+{
+ if (_need_space)
+ output_stream() << " ";
+
+ output_stream() << s;
+
+ _need_space = true;
+}
+
+void
+UseFlagPrettyPrinter::output_flag_changed_mark()
+{
+ output_stream() << "*";
+}
+
+void
+UseFlagPrettyPrinter::output_flag_is_new_mark()
+{
+ output_stream() << "%";
+}
+
+void
+UseFlagPrettyPrinter::output_expand_prefix(const std::string & s)
+{
+ if (_need_space)
+ output_stream() << " ";
+
+ output_stream() << s << ":";
+
+ _need_space = true;
+}
+
+std::string
+UseFlagPrettyPrinter::render_as_enabled_flag(const std::string & s) const
+{
+ return colour(cl_flag_on, s);
+}
+
+std::string
+UseFlagPrettyPrinter::render_as_disabled_flag(const std::string & s) const
+{
+ return colour(cl_flag_off, "-" + s);
+}
+
+std::string
+UseFlagPrettyPrinter::render_as_forced_flag(const std::string & s) const
+{
+ return colour(cl_flag_on, "(" + s + ")");
+}
+
+std::string
+UseFlagPrettyPrinter::render_as_masked_flag(const std::string & s) const
+{
+ return colour(cl_flag_off, "(-" + s + ")");
+}
+
+std::ostream &
+UseFlagPrettyPrinter::output_stream() const
+{
+ return std::cout;
+}
+
+bool
+UseFlagPrettyPrinter::need_space() const
+{
+ return _need_space;
+}
+
+const Environment *
+UseFlagPrettyPrinter::environment() const
+{
+ return _env;
+}
+
diff --git a/src/use_flag_pretty_printer.hh b/src/use_flag_pretty_printer.hh
new file mode 100644
index 0000000..f802b7f
--- /dev/null
+++ b/src/use_flag_pretty_printer.hh
@@ -0,0 +1,67 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_SRC_USE_FLAG_PRETTY_PRINTER_HH
+#define PALUDIS_GUARD_SRC_USE_FLAG_PRETTY_PRINTER_HH 1
+
+#include <paludis/util/counted_ptr.hh>
+#include <paludis/name.hh>
+#include <iosfwd>
+
+namespace paludis
+{
+ class Environment;
+ class PackageDatabaseEntry;
+
+ class UseFlagPrettyPrinter :
+ public InternalCounted<UseFlagPrettyPrinter>
+ {
+ private:
+ const Environment * const _env;
+ bool _need_space;
+
+ protected:
+ std::string::size_type use_expand_delim_pos(const UseFlagName & u,
+ const UseFlagNameCollection::ConstPointer c) const;
+
+ public:
+ UseFlagPrettyPrinter(const Environment * const);
+ virtual ~UseFlagPrettyPrinter();
+
+ virtual void print_package_flags(const PackageDatabaseEntry &,
+ const PackageDatabaseEntry * const = 0);
+
+ virtual void output_flag(const std::string &);
+ virtual void output_flag_changed_mark();
+ virtual void output_flag_is_new_mark();
+ virtual void output_expand_prefix(const std::string &);
+
+ virtual std::string render_as_enabled_flag(const std::string &) const;
+ virtual std::string render_as_disabled_flag(const std::string &) const;
+ virtual std::string render_as_forced_flag(const std::string &) const;
+ virtual std::string render_as_masked_flag(const std::string &) const;
+
+ virtual std::ostream & output_stream() const;
+
+ const Environment * environment() const;
+ bool need_space() const;
+ };
+}
+
+#endif