diff options
author | 2010-12-31 02:08:00 +0000 | |
---|---|---|
committer | 2011-01-01 03:57:53 +0000 | |
commit | 79da6018d6c02a099af83ecd62e8858ead5f27db (patch) | |
tree | f97a0337777101f8c4a90257397e30196f798b92 | |
parent | 3dd53676acf85d7b3d9758f2def081d20c00b3b9 (diff) | |
download | paludis-79da6018d6c02a099af83ecd62e8858ead5f27db.tar.gz paludis-79da6018d6c02a099af83ecd62e8858ead5f27db.tar.xz |
Use pretty_print_value
40 files changed, 1293 insertions, 1104 deletions
diff --git a/doc/api/cplusplus/examples/Makefile.am b/doc/api/cplusplus/examples/Makefile.am index d0df5c15b..ff69e593f 100644 --- a/doc/api/cplusplus/examples/Makefile.am +++ b/doc/api/cplusplus/examples/Makefile.am @@ -18,8 +18,6 @@ noinst_PROGRAMS = \ example_dep_tag \ example_dep_spec_flattener \ example_environment \ - example_formatter \ - example_stringify_formatter \ example_package_id \ example_metadata_key \ example_mask \ @@ -88,18 +86,6 @@ example_environment_LDADD = \ $(top_builddir)/paludis/libpaludis_@PALUDIS_PC_SLOT@.la \ $(top_builddir)/paludis/args/libpaludisargs_@PALUDIS_PC_SLOT@.la -example_formatter_SOURCES = example_formatter.cc -example_formatter_LDADD = \ - libpaludisexamples.a \ - $(top_builddir)/paludis/libpaludis_@PALUDIS_PC_SLOT@.la \ - $(top_builddir)/paludis/args/libpaludisargs_@PALUDIS_PC_SLOT@.la - -example_stringify_formatter_SOURCES = example_stringify_formatter.cc -example_stringify_formatter_LDADD = \ - libpaludisexamples.a \ - $(top_builddir)/paludis/libpaludis_@PALUDIS_PC_SLOT@.la \ - $(top_builddir)/paludis/args/libpaludisargs_@PALUDIS_PC_SLOT@.la - example_package_id_SOURCES = example_package_id.cc example_package_id_LDADD = \ libpaludisexamples.a \ diff --git a/doc/api/cplusplus/examples/example_formatter.cc b/doc/api/cplusplus/examples/example_formatter.cc deleted file mode 100644 index 2a8069870..000000000 --- a/doc/api/cplusplus/examples/example_formatter.cc +++ /dev/null @@ -1,256 +0,0 @@ -/* vim: set sw=4 sts=4 et foldmethod=syntax : */ - -/** \file - * - * Example \ref example_formatter.cc "example_formatter.cc" . - * - * \ingroup g_formatters - */ - -/** \example example_formatter.cc - * - * This example demonstrates how to create a formatter. It outputs information - * about a package's dependencies in HTML. - * - * See \ref example_stringify_formatter.cc "example_stringify_formatter.cc" for - * StringifyFormatter, a premade formatter that uses stringify. - */ - -#include <paludis/paludis.hh> -#include "example_command_line.hh" -#include <iostream> -#include <iomanip> -#include <cstdlib> - -using namespace paludis; -using namespace examples; - -using std::cout; -using std::endl; - -namespace -{ - /* Utility function that replaces dodgy characters with HTML escapes. */ - std::string escape_html(const std::string & s) - { - std::string result; - for (std::string::const_iterator i(s.begin()), i_end(s.end()) ; - i != i_end ; ++i) - switch (*i) - { - case '<': - result.append("<"); - break; - - case '>': - result.append(">"); - break; - - case '&': - result.append("&"); - break; - - default: - result.append(std::string(1, *i)); - } - - return result; - } - - /* Utility function that creates an HTML <span> with a colour. */ - std::string span_colour(const std::string & s, const std::string & c) - { - return "<span style=\"color: " + c + "\">" + s + "</span>"; - } - - /* This formatter outputs information about dependencies in HTML. We need - * to implement CanFormat<> for all of the things that can be found in - * DependencySpecTree::ItemFormatter, as well as CanSpace. */ - class HTMLFormatter : - public CanSpace, - public CanFormat<PackageDepSpec>, - public CanFormat<DependenciesLabelsDepSpec>, - public CanFormat<ConditionalDepSpec>, - public CanFormat<NamedSetDepSpec>, - public CanFormat<BlockDepSpec> - { - public: - /* The second parameter to the format functions has no meaning - * beyond being used to overload to the appropriate function. */ - std::string format(const PackageDepSpec & s, const format::Plain &) const - { - return span_colour(escape_html(stringify(s)), "#666666"); - } - - std::string format(const PackageDepSpec & s, const format::Installed &) const - { - return span_colour(escape_html(stringify(s)), "#6666ff"); - } - - std::string format(const PackageDepSpec & s, const format::Installable &) const - { - return span_colour(escape_html(stringify(s)), "#66ff66"); - } - - std::string format(const DependenciesLabelsDepSpec & s, const format::Plain &) const - { - return span_colour(escape_html(stringify(s)), "#666666"); - } - - std::string format(const ConditionalDepSpec & s, const format::Plain &) const - { - return span_colour(escape_html(stringify(s)), "#666666"); - } - - std::string format(const ConditionalDepSpec & s, const format::Enabled &) const - { - return span_colour(escape_html(stringify(s)), "#66ff66"); - } - - std::string decorate(const ConditionalDepSpec &, const std::string & s, const format::Added &) const - { - return s; - } - - std::string decorate(const ConditionalDepSpec &, const std::string & s, const format::Changed &) const - { - return s; - } - - std::string format(const ConditionalDepSpec & s, const format::Disabled &) const - { - return span_colour(escape_html(stringify(s)), "#ff6666"); - } - - std::string format(const ConditionalDepSpec & s, const format::Forced &) const - { - return span_colour(escape_html("(" + stringify(s) + ")"), "#66ff66"); - } - - std::string format(const ConditionalDepSpec & s, const format::Masked &) const - { - return span_colour(escape_html("(" + stringify(s) + ")"), "#ff6666"); - } - - std::string format(const NamedSetDepSpec & s, const format::Plain &) const - { - return span_colour(escape_html(stringify(s)), "#666666"); - } - - std::string format(const BlockDepSpec & s, const format::Plain &) const - { - return span_colour(escape_html(stringify(s)), "#666666"); - } - - std::string newline() const - { - return "<br />\n"; - } - - std::string indent(const int i) const - { - std::string result; - for (int x(0) ; x < i ; ++x) - result.append(" "); - return result; - } - }; -} - -int main(int argc, char * argv[]) -{ - try - { - CommandLine::get_instance()->run(argc, argv, - "example_formatter", "EXAMPLE_FORMATTER_OPTIONS", "EXAMPLE_FORMATTER_CMDLINE"); - - /* We start with an Environment, respecting the user's '--environment' choice. */ - std::shared_ptr<Environment> env(EnvironmentFactory::get_instance()->create( - CommandLine::get_instance()->a_environment.argument())); - - /* Fetch package IDs for installable 'sys-apps/paludis'. */ - std::shared_ptr<const PackageIDSequence> ids((*env)[selection::AllVersionsSorted( - generator::Package(QualifiedPackageName("sys-apps/paludis")) | - filter::SupportsAction<InstallAction>())]); - - /* Write nice valid XHTML, because we're good like that. */ - cout << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"" << endl; - cout << " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" << endl; - cout << "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">" << endl; - cout << "<head><title>Dependencies for sys-apps/paludis</title></head>" << endl; - cout << "<body>" << endl; - - /* For each ID: */ - for (PackageIDSequence::ConstIterator i(ids->begin()), i_end(ids->end()) ; - i != i_end ; ++i) - { - cout << "<h1>" << escape_html(stringify(**i)) << "</h1>" << endl; - - /* Our formatter. It has no saved state, so we can use a single - * formatter for all of the keys. */ - HTMLFormatter formatter; - - /* We need to check that _key() methods don't return zero. */ - if ((*i)->build_dependencies_key()) - { - cout << "<h2>" << escape_html((*i)->build_dependencies_key()->human_name()) << "</h2>" << endl; - cout << "<div style=\"border: 1px solid #999999; background-color: #eeeeee; " - "margin-left: 1em; padding: 0.2em 0.5em; \">" << endl; - cout << (*i)->build_dependencies_key()->pretty_print(formatter); - cout << endl << "</div>" << endl; - } - - if ((*i)->run_dependencies_key()) - { - cout << "<h2>" << escape_html((*i)->run_dependencies_key()->human_name()) << "</h2>" << endl; - cout << "<div style=\"border: 1px solid #999999; background-color: #eeeeee; " - "margin-left: 1em; padding: 0.2em 0.5em; \">" << endl; - cout << (*i)->run_dependencies_key()->pretty_print(formatter); - cout << endl << "</div>" << endl; - } - - if ((*i)->post_dependencies_key()) - { - cout << "<h2>" << escape_html((*i)->post_dependencies_key()->human_name()) << "</h2>" << endl; - cout << "<div style=\"border: 1px solid #999999; background-color: #eeeeee; " - "margin-left: 1em; padding: 0.2em 0.5em; \">" << endl; - cout << (*i)->post_dependencies_key()->pretty_print(formatter); - cout << endl << "</div>" << endl; - } - - cout << endl; - } - - cout << "</body>" << endl; - cout << "</html>" << endl; - } - catch (const Exception & e) - { - /* Paludis exceptions can provide a handy human-readable backtrace and - * an explanation message. Where possible, these should be displayed. */ - cout << endl; - cout << "Unhandled exception:" << endl - << " * " << e.backtrace("\n * ") - << e.message() << " (" << e.what() << ")" << endl; - return EXIT_FAILURE; - } - catch (const std::exception & e) - { - cout << endl; - cout << "Unhandled exception:" << endl - << " * " << e.what() << endl; - return EXIT_FAILURE; - } - catch (...) - { - cout << endl; - cout << "Unhandled exception:" << endl - << " * Unknown exception type. Ouch..." << endl; - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} - - - diff --git a/doc/api/cplusplus/examples/example_metadata_key.cc b/doc/api/cplusplus/examples/example_metadata_key.cc index b55dfb8bb..2493c2555 100644 --- a/doc/api/cplusplus/examples/example_metadata_key.cc +++ b/doc/api/cplusplus/examples/example_metadata_key.cc @@ -45,10 +45,6 @@ namespace class MetadataKeyInformationVisitor { private: - /* Various methods need a formatter. See \ref example_stringify_formatter.cc - * "example_stringify_formatter.cc" for more details. */ - StringifyFormatter formatter; - /* Because of MetadataSectionKey, we can be called recursively. We add a level * of indenting each time. */ std::string indent; @@ -149,50 +145,50 @@ namespace void visit(const MetadataSpecTreeKey<PlainTextSpecTree> & key) { cout << indent << left << setw(30) << " Class:" << " " << "MetadataSpecTreeKey<PlainTextSpecTree>" << endl; - cout << indent << left << setw(30) << " Value:" << " " << key.pretty_print_flat(formatter) << endl; + cout << indent << left << setw(30) << " Value:" << " " << key.pretty_print_value(UnformattedPrettyPrinter(), { }) << endl; } void visit(const MetadataSpecTreeKey<RequiredUseSpecTree> & key) { cout << indent << left << setw(30) << " Class:" << " " << "MetadataSpecTreeKey<RequiredUseSpecTree>" << endl; - cout << indent << left << setw(30) << " Value:" << " " << key.pretty_print_flat(formatter) << endl; + cout << indent << left << setw(30) << " Value:" << " " << key.pretty_print_value(UnformattedPrettyPrinter(), { }) << endl; } void visit(const MetadataSpecTreeKey<ProvideSpecTree> & key) { cout << indent << left << setw(30) << " Class:" << " " << "MetadataSpecTreeKey<ProvideSpecTree>" << endl; - cout << indent << left << setw(30) << " Value:" << " " << key.pretty_print_flat(formatter) << endl; + cout << indent << left << setw(30) << " Value:" << " " << key.pretty_print_value(UnformattedPrettyPrinter(), { }) << endl; } void visit(const MetadataSpecTreeKey<LicenseSpecTree> & key) { cout << indent << left << setw(30) << " Class:" << " " << "MetadataSpecTreeKey<LicenseSpecTree>" << endl; - cout << indent << left << setw(30) << " Value:" << " " << key.pretty_print_flat(formatter) << endl; + cout << indent << left << setw(30) << " Value:" << " " << key.pretty_print_value(UnformattedPrettyPrinter(), { }) << endl; } void visit(const MetadataSpecTreeKey<SimpleURISpecTree> & key) { cout << indent << left << setw(30) << " Class:" << " " << "MetadataSpecTreeKey<SimpleURISpecTree>" << endl; - cout << indent << left << setw(30) << " Value:" << " " << key.pretty_print_flat(formatter) << endl; + cout << indent << left << setw(30) << " Value:" << " " << key.pretty_print_value(UnformattedPrettyPrinter(), { }) << endl; } void visit(const MetadataSpecTreeKey<DependencySpecTree> & key) { cout << indent << left << setw(30) << " Class:" << " " << "MetadataSpecTreeKey<DependencySpecTree>" << endl; - cout << indent << left << setw(30) << " Value:" << " " << key.pretty_print_flat(formatter) << endl; + cout << indent << left << setw(30) << " Value:" << " " << key.pretty_print_value(UnformattedPrettyPrinter(), { }) << endl; } void visit(const MetadataSpecTreeKey<FetchableURISpecTree> & key) { cout << indent << left << setw(30) << " Class:" << " " << "MetadataSpecTreeKey<FetchableURISpecTree>" << endl; - cout << indent << left << setw(30) << " Value:" << " " << key.pretty_print_flat(formatter) << endl; + cout << indent << left << setw(30) << " Value:" << " " << key.pretty_print_value(UnformattedPrettyPrinter(), { }) << endl; cout << indent << left << setw(30) << " Initial label:" << " " << key.initial_label()->text() << endl; } void visit(const MetadataCollectionKey<KeywordNameSet> & key) { cout << indent << left << setw(30) << " Class:" << " " << "MetadataCollectionKey<KeywordNameSet>" << endl; - cout << indent << left << setw(30) << " Value:" << " " << key.pretty_print_flat(formatter) << endl; + cout << indent << left << setw(30) << " Value:" << " " << key.pretty_print_value(UnformattedPrettyPrinter(), { }) << endl; } void visit(const MetadataCollectionKey<Set<std::string> > & key) diff --git a/doc/api/cplusplus/examples/example_stringify_formatter.cc b/doc/api/cplusplus/examples/example_stringify_formatter.cc deleted file mode 100644 index 343a92d2c..000000000 --- a/doc/api/cplusplus/examples/example_stringify_formatter.cc +++ /dev/null @@ -1,100 +0,0 @@ -/* vim: set sw=4 sts=4 et foldmethod=syntax : */ - -/** \file - * - * Example \ref example_stringify_formatter.cc "example_stringify_formatter.cc" . - * - * \ingroup g_formatters - */ - -/** \example example_stringify_formatter.cc - * - * This example demonstrates how to use StringifyFormatter. - * - * See \ref example_formatter.cc "example_formatter.cc" for how to create - * a custom Formatter. - */ - -#include <paludis/paludis.hh> -#include "example_command_line.hh" -#include <iostream> -#include <cstdlib> - -using namespace paludis; -using namespace examples; - -using std::cout; -using std::endl; - -int main(int argc, char * argv[]) -{ - try - { - CommandLine::get_instance()->run(argc, argv, - "example_stringify_formatter", "EXAMPLE_STRINGIFY_FORMATTER_OPTIONS", "EXAMPLE_STRINGIFY_FORMATTER_CMDLINE"); - - /* We start with an Environment, respecting the user's '--environment' choice. */ - std::shared_ptr<Environment> env(EnvironmentFactory::get_instance()->create( - CommandLine::get_instance()->a_environment.argument())); - - /* Fetch package IDs for installable 'sys-apps/paludis'. */ - std::shared_ptr<const PackageIDSequence> ids((*env)[selection::AllVersionsSorted( - generator::Package(QualifiedPackageName("sys-apps/paludis")) | - filter::SupportsAction<InstallAction>())]); - - /* For each ID: */ - for (PackageIDSequence::ConstIterator i(ids->begin()), i_end(ids->end()) ; - i != i_end ; ++i) - { - cout << stringify(**i) << ":" << endl; - - /* Our formatter. It has no saved state, so we can use a single - * formatter for all of the keys. */ - StringifyFormatter formatter; - - if ((*i)->keywords_key()) - { - cout << " " << (*i)->keywords_key()->human_name() << ":" << endl; - cout << " " << (*i)->keywords_key()->pretty_print_flat(formatter) << endl; - } - - if ((*i)->homepage_key()) - { - cout << " " << (*i)->homepage_key()->human_name() << ":" << endl; - cout << " " << (*i)->homepage_key()->pretty_print_flat(formatter) << endl; - } - - cout << endl; - } - } - catch (const Exception & e) - { - /* Paludis exceptions can provide a handy human-readable backtrace and - * an explanation message. Where possible, these should be displayed. */ - cout << endl; - cout << "Unhandled exception:" << endl - << " * " << e.backtrace("\n * ") - << e.message() << " (" << e.what() << ")" << endl; - return EXIT_FAILURE; - } - catch (const std::exception & e) - { - cout << endl; - cout << "Unhandled exception:" << endl - << " * " << e.what() << endl; - return EXIT_FAILURE; - } - catch (...) - { - cout << endl; - cout << "Unhandled exception:" << endl - << " * Unknown exception type. Ouch..." << endl; - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} - - - - diff --git a/doc/api/index.html.part b/doc/api/index.html.part index bdd0f72b8..2fcce7d4a 100644 --- a/doc/api/index.html.part +++ b/doc/api/index.html.part @@ -114,13 +114,6 @@ how concepts map on to different language bindings.</p> <td>How to use EnvironmentFactory and the resultant Environment</td> </tr> <tr> - <td>example_formatter</td> - <td><a href="cplusplus/examples.html">C++</a></td> - <td></td> - <td></td> - <td>How to create a formatter</td> - </tr> - <tr> <td>example_mask</td> <td><a href="cplusplus/examples.html">C++</a></td> <td><a href="ruby/example_mask.html">Ruby</a></td> @@ -177,13 +170,6 @@ how concepts map on to different language bindings.</p> <td>How to use the standard Selection, Generator and Filter classes</td> </tr> <tr> - <td>example_stringify_formatter</td> - <td><a href="cplusplus/examples.html">C++</a></td> - <td></td> - <td></td> - <td>How to use StringifyFormatter</td> - </tr> - <tr> <td>example_version_operator</td> <td><a href="cplusplus/examples.html">C++</a></td> <td><a href="ruby/example_version_operator.html">Ruby</a></td> diff --git a/paludis/files.m4 b/paludis/files.m4 index cfc72e865..41a393da0 100644 --- a/paludis/files.m4 +++ b/paludis/files.m4 @@ -49,6 +49,7 @@ add(`filter', `hh', `cc', `fwd', `test') add(`filter_handler', `hh', `cc', `fwd') add(`filtered_generator', `hh', `cc', `fwd', `test') add(`format_messages_output_manager', `hh', `fwd', `cc') +add(`formatted_pretty_printer', `hh', `fwd', `cc') add(`formatter', `hh', `fwd', `cc') add(`forward_at_finish_output_manager', `hh', `fwd', `cc') add(`fs_merger', `hh', `cc', `fwd', `se', `test', `testscript') @@ -102,6 +103,7 @@ add(`syncer', `hh', `cc') add(`tar_merger', `hh', `cc', `fwd', `test', `testscript', `se') add(`tee_output_manager', `hh', `cc', `fwd') add(`unchoices_key', `hh', `cc', `fwd') +add(`unformatted_pretty_printer', `hh', `cc', `fwd') add(`unmerger', `hh', `cc') add(`user_dep_spec', `hh', `cc', `se', `fwd', `test') add(`version_operator', `hh', `cc', `fwd', `se', `test') diff --git a/paludis/formatted_pretty_printer-fwd.hh b/paludis/formatted_pretty_printer-fwd.hh new file mode 100644 index 000000000..85a6480ff --- /dev/null +++ b/paludis/formatted_pretty_printer-fwd.hh @@ -0,0 +1,28 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2010 Ciaran McCreesh + * + * 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_PALUDIS_FORMATTED_PRETTY_PRINTER_FWD_HH +#define PALUDIS_GUARD_PALUDIS_FORMATTED_PRETTY_PRINTER_FWD_HH 1 + +namespace paludis +{ + struct FormattedPrettyPrinter; +} + +#endif diff --git a/paludis/formatted_pretty_printer.cc b/paludis/formatted_pretty_printer.cc new file mode 100644 index 000000000..fbea1960a --- /dev/null +++ b/paludis/formatted_pretty_printer.cc @@ -0,0 +1,236 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2010 Ciaran McCreesh + * + * 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 <paludis/formatted_pretty_printer.hh> +#include <paludis/util/pimp-impl.hh> +#include <paludis/selection.hh> +#include <paludis/generator.hh> +#include <paludis/filtered_generator.hh> +#include <paludis/filter.hh> +#include <paludis/environment.hh> +#include <paludis/package_database.hh> +#include <paludis/metadata_key.hh> +#include <paludis/package_id.hh> + +using namespace paludis; + +namespace paludis +{ + template <> + struct Imp<FormattedPrettyPrinter> + { + const Environment * const env; + const std::shared_ptr<const PackageID> package_id; + + Imp(const Environment * const e, const std::shared_ptr<const PackageID> & i) : + env(e), + package_id(i) + { + } + }; +} + +FormattedPrettyPrinter::FormattedPrettyPrinter( + const Environment * const e, + const std::shared_ptr<const PackageID> & i) : + Pimp<FormattedPrettyPrinter>(e, i) +{ +} + +FormattedPrettyPrinter::~FormattedPrettyPrinter() = default; + +const std::string +FormattedPrettyPrinter::prettify(const PackageDepSpec & v) const +{ + if (_imp->env) + { + { + auto ids((*_imp->env)[selection::SomeArbitraryVersion(generator::Matches(v, { }) | + filter::InstalledAtRoot(_imp->env->preferred_root_key()->value()))]); + if (! ids->empty()) + return format_installed(stringify(v)); + } + { + auto ids((*_imp->env)[selection::SomeArbitraryVersion(generator::Matches(v, { }) | + filter::SupportsAction<InstallAction>() | filter::NotMasked())]); + if (! ids->empty()) + return format_installed(stringify(v)); + } + + return format_masked(stringify(v)); + } + else + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const BlockDepSpec & v) const +{ + if (_imp->env) + { + { + auto ids((*_imp->env)[selection::SomeArbitraryVersion(generator::Matches(v.blocking(), { }) | + filter::InstalledAtRoot(_imp->env->preferred_root_key()->value()))]); + if (! ids->empty()) + return format_masked(stringify(v)); + } + + return format_installable(stringify(v)); + } + else + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const ConditionalDepSpec & v) const +{ + if (_imp->env && _imp->package_id) + { + if (v.condition_met(_imp->env, _imp->package_id)) + return format_enabled(stringify(v)); + else + return format_disabled(stringify(v)); + } + else + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const NamedSetDepSpec & v) const +{ + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const SimpleURIDepSpec & v) const +{ + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const PlainTextDepSpec & v) const +{ + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const LicenseDepSpec & v) const +{ + if (_imp->env && _imp->package_id) + { + if (_imp->env->accept_license(v.text(), _imp->package_id)) + return format_enabled(stringify(v)); + else + return format_disabled(stringify(v)); + } + else + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const FetchableURIDepSpec & v) const +{ + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const URILabelsDepSpec & v) const +{ + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const DependenciesLabelsDepSpec & v) const +{ + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const PlainTextLabelDepSpec & v) const +{ + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const std::shared_ptr<const PackageID> & v) const +{ + if (_imp->env) + { + auto repo(_imp->env->package_database()->fetch_repository(v->repository_name())); + if (repo->installed_root_key()) + return format_installed(stringify(*v)); + else if (! v->masked()) + return format_installable(stringify(*v)); + else + return format_masked(stringify(*v)); + } + else + return format_plain(stringify(*v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const bool v) const +{ + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const long v) const +{ + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const std::string & v) const +{ + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const std::pair<const std::string, std::string> & v) const +{ + if (v.first.empty()) + return format_plain(v.second); + else + return format_plain(v.first + ": " + v.second); +} + +const std::string +FormattedPrettyPrinter::prettify(const FSPath & v) const +{ + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const KeywordName & v) const +{ + if (_imp->env && _imp->package_id) + { + auto k(std::make_shared<KeywordNameSet>()); + k->insert(v); + + if (_imp->env->accept_keywords(k, _imp->package_id)) + return format_enabled(stringify(v)); + else + return format_disabled(stringify(v)); + } + else + return format_plain(stringify(v)); +} + diff --git a/paludis/formatted_pretty_printer.hh b/paludis/formatted_pretty_printer.hh new file mode 100644 index 000000000..ea07cbf68 --- /dev/null +++ b/paludis/formatted_pretty_printer.hh @@ -0,0 +1,78 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2010 Ciaran McCreesh + * + * 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_PALUDIS_FORMATTED_PRETTY_PRINTER_HH +#define PALUDIS_GUARD_PALUDIS_FORMATTED_PRETTY_PRINTER_HH 1 + +#include <paludis/formatted_pretty_printer-fwd.hh> +#include <paludis/util/pimp.hh> +#include <paludis/pretty_printer.hh> +#include <paludis/environment-fwd.hh> +#include <paludis/package_id-fwd.hh> +#include <memory> + +namespace paludis +{ + class PALUDIS_VISIBLE FormattedPrettyPrinter : + public PrettyPrinter, + private Pimp<FormattedPrettyPrinter> + { + protected: + virtual const std::string format_enabled(const std::string &) const = 0; + virtual const std::string format_disabled(const std::string &) const = 0; + virtual const std::string format_installed(const std::string &) const = 0; + virtual const std::string format_installable(const std::string &) const = 0; + virtual const std::string format_masked(const std::string &) const = 0; + virtual const std::string format_plain(const std::string &) const = 0; + + public: + FormattedPrettyPrinter( + const Environment * const, + const std::shared_ptr<const PackageID> &); + ~FormattedPrettyPrinter(); + + virtual const std::string prettify(const PackageDepSpec &) const; + virtual const std::string prettify(const BlockDepSpec &) const; + virtual const std::string prettify(const ConditionalDepSpec &) const; + virtual const std::string prettify(const NamedSetDepSpec &) const; + virtual const std::string prettify(const SimpleURIDepSpec &) const; + virtual const std::string prettify(const PlainTextDepSpec &) const; + virtual const std::string prettify(const LicenseDepSpec &) const; + virtual const std::string prettify(const FetchableURIDepSpec &) const; + virtual const std::string prettify(const URILabelsDepSpec &) const; + virtual const std::string prettify(const DependenciesLabelsDepSpec &) const; + virtual const std::string prettify(const PlainTextLabelDepSpec &) const; + + virtual const std::string prettify(const std::shared_ptr<const PackageID> &) const; + + virtual const std::string prettify(const bool) const; + + virtual const std::string prettify(const long) const; + + virtual const std::string prettify(const std::string &) const; + + virtual const std::string prettify(const std::pair<const std::string, std::string> &) const; + + virtual const std::string prettify(const FSPath &) const; + + virtual const std::string prettify(const KeywordName &) const; + }; +} + +#endif diff --git a/paludis/literal_metadata_key.cc b/paludis/literal_metadata_key.cc index 5a64b8e62..79895fce8 100644 --- a/paludis/literal_metadata_key.cc +++ b/paludis/literal_metadata_key.cc @@ -371,39 +371,6 @@ LiteralMetadataValueKey<T_>::type() const return _imp->type; } -ExtraLiteralMetadataValueKeyMethods<long>::~ExtraLiteralMetadataValueKeyMethods() -{ -} - -std::string -ExtraLiteralMetadataValueKeyMethods<long>::pretty_print() const -{ - long v(static_cast<const LiteralMetadataValueKey<long> *>(this)->value()); - return stringify(v); -} - -ExtraLiteralMetadataValueKeyMethods<bool>::~ExtraLiteralMetadataValueKeyMethods() -{ -} - -std::string -ExtraLiteralMetadataValueKeyMethods<bool>::pretty_print() const -{ - bool v(static_cast<const LiteralMetadataValueKey<bool> *>(this)->value()); - return stringify(v); -} - -ExtraLiteralMetadataValueKeyMethods<std::shared_ptr<const PackageID> >::~ExtraLiteralMetadataValueKeyMethods() -{ -} - -std::string -ExtraLiteralMetadataValueKeyMethods<std::shared_ptr<const PackageID> >::pretty_print(const Formatter<PackageID> & f) const -{ - std::shared_ptr<const PackageID> v(static_cast<const LiteralMetadataValueKey<std::shared_ptr<const PackageID> > *>(this)->value()); - return f.format(*v, format::Plain()); -} - template <typename T_> LiteralMetadataValueKey<T_>::LiteralMetadataValueKey(const std::string & r, const std::string & h, const MetadataKeyType t, const T_ & v) : diff --git a/paludis/literal_metadata_key.hh b/paludis/literal_metadata_key.hh index 1f49f5061..9a4bb03b4 100644 --- a/paludis/literal_metadata_key.hh +++ b/paludis/literal_metadata_key.hh @@ -38,68 +38,6 @@ namespace paludis { - /** - * Implement extra methods for LiteralMetadataValueKey. - * - * \ingroup g_metadata_key - * \since 0.26 - */ - template <typename T_> - class ExtraLiteralMetadataValueKeyMethods - { - }; - - /** - * Implement extra methods for LiteralMetadataValueKey for PackageID. - * - * \ingroup g_metadata_key - * \since 0.26 - */ - template <> - class PALUDIS_VISIBLE ExtraLiteralMetadataValueKeyMethods<std::shared_ptr<const PackageID> > : - public virtual ExtraMetadataValueKeyMethods<std::shared_ptr<const PackageID> > - { - public: - virtual ~ExtraLiteralMetadataValueKeyMethods() = 0; - - virtual std::string pretty_print(const Formatter<PackageID> &) const - PALUDIS_ATTRIBUTE((warn_unused_result)); - }; - - /** - * Implement extra methods for LiteralMetadataValueKey for long. - * - * \ingroup g_metadata_key - * \since 0.28 - */ - template <> - class PALUDIS_VISIBLE ExtraLiteralMetadataValueKeyMethods<long> : - public virtual ExtraMetadataValueKeyMethods<long> - { - public: - virtual ~ExtraLiteralMetadataValueKeyMethods() = 0; - - virtual std::string pretty_print() const - PALUDIS_ATTRIBUTE((warn_unused_result)); - }; - - /** - * Implement extra methods for LiteralMetadataValueKey for bool. - * - * \ingroup g_metadata_key - * \since 0.34.1 - */ - template <> - class PALUDIS_VISIBLE ExtraLiteralMetadataValueKeyMethods<bool> : - public virtual ExtraMetadataValueKeyMethods<bool> - { - public: - virtual ~ExtraLiteralMetadataValueKeyMethods() = 0; - - virtual std::string pretty_print() const - PALUDIS_ATTRIBUTE((warn_unused_result)); - }; - template <typename T_> class PALUDIS_VISIBLE PrettyPrintableLiteralMetadataValueKey : public MetadataValueKey<T_> @@ -120,8 +58,7 @@ namespace paludis template <typename T_> class PALUDIS_VISIBLE LiteralMetadataValueKey : public std::conditional<MetadataValueKeyIsPrettyPrintable<T_>::value, PrettyPrintableLiteralMetadataValueKey<T_>, MetadataValueKey<T_> >::type, - private Pimp<LiteralMetadataValueKey<T_> >, - public ExtraLiteralMetadataValueKeyMethods<T_> + private Pimp<LiteralMetadataValueKey<T_> > { private: typename Pimp<LiteralMetadataValueKey<T_> >::ImpPtr & _imp; diff --git a/paludis/metadata_key.cc b/paludis/metadata_key.cc index 496eebb62..70dccaf8f 100644 --- a/paludis/metadata_key.cc +++ b/paludis/metadata_key.cc @@ -44,18 +44,6 @@ MetadataTimeKey::~MetadataTimeKey() { } -ExtraMetadataValueKeyMethods<long>::~ExtraMetadataValueKeyMethods() -{ -} - -ExtraMetadataValueKeyMethods<bool>::~ExtraMetadataValueKeyMethods() -{ -} - -ExtraMetadataValueKeyMethods<std::shared_ptr<const PackageID> >::~ExtraMetadataValueKeyMethods() -{ -} - template <typename T_> MetadataCollectionKey<T_>::~MetadataCollectionKey() { diff --git a/paludis/metadata_key.hh b/paludis/metadata_key.hh index 3b3320c41..2652d7002 100644 --- a/paludis/metadata_key.hh +++ b/paludis/metadata_key.hh @@ -185,75 +185,6 @@ namespace paludis }; /** - * Extra methods for MetadataValueKey with certain item types. - * - * \ingroup g_metadata_key - * \since 0.26 - */ - template <typename C_> - class ExtraMetadataValueKeyMethods - { - }; - - /** - * Extra methods for MetadataValueKey with long value type. - * - * \ingroup g_metadata_key - * \since 0.26 - */ - template <> - class PALUDIS_VISIBLE ExtraMetadataValueKeyMethods<long> - { - public: - virtual ~ExtraMetadataValueKeyMethods() = 0; - - /** - * Return a formatted version of our value. - */ - virtual std::string pretty_print() const - PALUDIS_ATTRIBUTE((warn_unused_result)) = 0; - }; - - /** - * Extra methods for MetadataValueKey with bool value type. - * - * \ingroup g_metadata_key - * \since 0.26 - */ - template <> - class PALUDIS_VISIBLE ExtraMetadataValueKeyMethods<bool> - { - public: - virtual ~ExtraMetadataValueKeyMethods() = 0; - - /** - * Return a formatted version of our value. - */ - virtual std::string pretty_print() const - PALUDIS_ATTRIBUTE((warn_unused_result)) = 0; - }; - - /** - * Extra methods for MetadataValueKey with PackageID value type. - * - * \ingroup g_metadata_key - * \since 0.26 - */ - template <> - class PALUDIS_VISIBLE ExtraMetadataValueKeyMethods<std::shared_ptr<const PackageID> > - { - public: - virtual ~ExtraMetadataValueKeyMethods() = 0; - - /** - * Return a formatted version of our value, using the supplied Formatter to - * format the item. - */ - virtual std::string pretty_print(const Formatter<PackageID> &) const - PALUDIS_ATTRIBUTE((warn_unused_result)) = 0; - }; - - /** * Selects whether a MetadataValueKey instantiation is a * PrettyPrintableMetadataKey. * @@ -295,8 +226,7 @@ namespace paludis template <typename C_> class PALUDIS_VISIBLE MetadataValueKey : public std::conditional<MetadataValueKeyIsPrettyPrintable<C_>::value, PrettyPrintableMetadataKey, MetadataKey>::type, - public ImplementAcceptMethods<MetadataKey, MetadataValueKey<C_> >, - public virtual ExtraMetadataValueKeyMethods<C_> + public ImplementAcceptMethods<MetadataKey, MetadataValueKey<C_> > { public: virtual ~MetadataValueKey() = 0; @@ -353,14 +283,6 @@ namespace paludis */ virtual const std::shared_ptr<const C_> value() const PALUDIS_ATTRIBUTE((warn_unused_result)) = 0; - - /** - * Return a single-line formatted version of our value, using the - * supplied Formatter to format individual items. - */ - virtual std::string pretty_print_flat(const Formatter< - typename std::remove_const<typename RemoveSharedPtr<typename C_::value_type>::Type>::type> &) const - PALUDIS_ATTRIBUTE((warn_unused_result)) = 0; }; /** @@ -384,20 +306,6 @@ namespace paludis */ virtual const std::shared_ptr<const C_> value() const PALUDIS_ATTRIBUTE((warn_unused_result)) = 0; - - /** - * Return a multiline-line indented and formatted version of our - * value, using the supplied Formatter to format individual items. - */ - virtual std::string pretty_print(const typename C_::ItemFormatter &) const - PALUDIS_ATTRIBUTE((warn_unused_result)) = 0; - - /** - * Return a single-line formatted version of our value, using the - * supplied Formatter to format individual items. - */ - virtual std::string pretty_print_flat(const typename C_::ItemFormatter &) const - PALUDIS_ATTRIBUTE((warn_unused_result)) = 0; }; /** @@ -426,20 +334,6 @@ namespace paludis PALUDIS_ATTRIBUTE((warn_unused_result)) = 0; /** - * Return a multiline-line indented and formatted version of our - * value, using the supplied Formatter to format individual items. - */ - virtual std::string pretty_print(const FetchableURISpecTree::ItemFormatter &) const - PALUDIS_ATTRIBUTE((warn_unused_result)) = 0; - - /** - * Return a single-line formatted version of our value, using the - * supplied Formatter to format individual items. - */ - virtual std::string pretty_print_flat(const FetchableURISpecTree::ItemFormatter &) const - PALUDIS_ATTRIBUTE((warn_unused_result)) = 0; - - /** * Return a URILabel that represents the initial label to use when * deciding the behaviour of individual items in the heirarchy. */ @@ -473,20 +367,6 @@ namespace paludis PALUDIS_ATTRIBUTE((warn_unused_result)) = 0; /** - * Return a multiline-line indented and formatted version of our - * value, using the supplied Formatter to format individual items. - */ - virtual std::string pretty_print(const DependencySpecTree::ItemFormatter &) const - PALUDIS_ATTRIBUTE((warn_unused_result)) = 0; - - /** - * Return a single-line formatted version of our value, using the - * supplied Formatter to format individual items. - */ - virtual std::string pretty_print_flat(const DependencySpecTree::ItemFormatter &) const - PALUDIS_ATTRIBUTE((warn_unused_result)) = 0; - - /** * Return a DependenciesLabelSequence that represents the initial labels to use when * deciding the behaviour of individual items in the heirarchy. */ diff --git a/paludis/repositories/e/depend_rdepend_TEST.cc b/paludis/repositories/e/depend_rdepend_TEST.cc index e0a4a2684..c8d885356 100644 --- a/paludis/repositories/e/depend_rdepend_TEST.cc +++ b/paludis/repositories/e/depend_rdepend_TEST.cc @@ -35,6 +35,7 @@ #include <paludis/filter.hh> #include <paludis/stringify_formatter.hh> #include <paludis/metadata_key.hh> +#include <paludis/unformatted_pretty_printer.hh> #include <test/test_framework.hh> #include <test/test_runner.hh> @@ -153,17 +154,15 @@ namespace n::want_phase() = &want_all_phases )); - StringifyFormatter f; - { std::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Package( QualifiedPackageName("cat/eapi" + eapi + "donly")))]->begin()); - TEST_CHECK_EQUAL(id->build_dependencies_key()->pretty_print_flat(f), "the/depend"); + TEST_CHECK_EQUAL(id->build_dependencies_key()->pretty_print_value(UnformattedPrettyPrinter(), { }), "the/depend"); if (special) - TEST_CHECK_EQUAL(id->run_dependencies_key()->pretty_print_flat(f), "the/depend"); + TEST_CHECK_EQUAL(id->run_dependencies_key()->pretty_print_value(UnformattedPrettyPrinter(), { }), "the/depend"); else - TEST_CHECK_EQUAL(id->run_dependencies_key()->pretty_print_flat(f), ""); + TEST_CHECK_EQUAL(id->run_dependencies_key()->pretty_print_value(UnformattedPrettyPrinter(), { }), ""); id->perform_action(action); @@ -173,19 +172,19 @@ namespace QualifiedPackageName("cat/eapi" + eapi + "donly")) | filter::InstalledAtRoot(root))]->begin()); - TEST_CHECK_EQUAL(v_id->build_dependencies_key()->pretty_print_flat(f), "the/depend"); + TEST_CHECK_EQUAL(v_id->build_dependencies_key()->pretty_print_value(UnformattedPrettyPrinter(), { }), "the/depend"); if (special) - TEST_CHECK_EQUAL(v_id->run_dependencies_key()->pretty_print_flat(f), "the/depend"); + TEST_CHECK_EQUAL(v_id->run_dependencies_key()->pretty_print_value(UnformattedPrettyPrinter(), { }), "the/depend"); else - TEST_CHECK_EQUAL(v_id->run_dependencies_key()->pretty_print_flat(f), ""); + TEST_CHECK_EQUAL(v_id->run_dependencies_key()->pretty_print_value(UnformattedPrettyPrinter(), { }), ""); } { std::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Package( QualifiedPackageName("cat/eapi" + eapi + "ronly")))]->begin()); - TEST_CHECK_EQUAL(id->build_dependencies_key()->pretty_print_flat(f), ""); - TEST_CHECK_EQUAL(id->run_dependencies_key()->pretty_print_flat(f), "the/rdepend"); + TEST_CHECK_EQUAL(id->build_dependencies_key()->pretty_print_value(UnformattedPrettyPrinter(), { }), ""); + TEST_CHECK_EQUAL(id->run_dependencies_key()->pretty_print_value(UnformattedPrettyPrinter(), { }), "the/rdepend"); id->perform_action(action); @@ -195,16 +194,16 @@ namespace QualifiedPackageName("cat/eapi" + eapi + "ronly")) | filter::InstalledAtRoot(root))]->begin()); - TEST_CHECK_EQUAL(v_id->build_dependencies_key()->pretty_print_flat(f), ""); - TEST_CHECK_EQUAL(v_id->run_dependencies_key()->pretty_print_flat(f), "the/rdepend"); + TEST_CHECK_EQUAL(v_id->build_dependencies_key()->pretty_print_value(UnformattedPrettyPrinter(), { }), ""); + TEST_CHECK_EQUAL(v_id->run_dependencies_key()->pretty_print_value(UnformattedPrettyPrinter(), { }), "the/rdepend"); } { std::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Package( QualifiedPackageName("cat/eapi" + eapi + "both")))]->begin()); - TEST_CHECK_EQUAL(id->build_dependencies_key()->pretty_print_flat(f), "the/depend"); - TEST_CHECK_EQUAL(id->run_dependencies_key()->pretty_print_flat(f), "the/rdepend"); + TEST_CHECK_EQUAL(id->build_dependencies_key()->pretty_print_value(UnformattedPrettyPrinter(), { }), "the/depend"); + TEST_CHECK_EQUAL(id->run_dependencies_key()->pretty_print_value(UnformattedPrettyPrinter(), { }), "the/rdepend"); id->perform_action(action); @@ -214,8 +213,8 @@ namespace QualifiedPackageName("cat/eapi" + eapi + "both")) | filter::InstalledAtRoot(root))]->begin()); - TEST_CHECK_EQUAL(v_id->build_dependencies_key()->pretty_print_flat(f), "the/depend"); - TEST_CHECK_EQUAL(v_id->run_dependencies_key()->pretty_print_flat(f), "the/rdepend"); + TEST_CHECK_EQUAL(v_id->build_dependencies_key()->pretty_print_value(UnformattedPrettyPrinter(), { }), "the/depend"); + TEST_CHECK_EQUAL(v_id->run_dependencies_key()->pretty_print_value(UnformattedPrettyPrinter(), { }), "the/rdepend"); } } }; diff --git a/paludis/repositories/e/required_use_verifier.cc b/paludis/repositories/e/required_use_verifier.cc index 3dc58edf9..e46d26293 100644 --- a/paludis/repositories/e/required_use_verifier.cc +++ b/paludis/repositories/e/required_use_verifier.cc @@ -27,6 +27,7 @@ #include <paludis/metadata_key.hh> #include <paludis/choice.hh> #include <paludis/stringify_formatter.hh> +#include <paludis/unformatted_pretty_printer.hh> #include <list> #include <algorithm> @@ -132,7 +133,7 @@ RequiredUseVerifier::visit(const RequiredUseSpecTree::NodeType<AllDepSpec>::Type if (_imp->top) { if (_imp->stack.begin()->any_unmet) - _imp->unmet_requirements->push_back(_imp->id->required_use_key()->pretty_print_flat(StringifyFormatter())); + _imp->unmet_requirements->push_back(_imp->id->required_use_key()->pretty_print_value(UnformattedPrettyPrinter(), { })); } } diff --git a/paludis/repositories/unpackaged/installed_repository.cc b/paludis/repositories/unpackaged/installed_repository.cc index 357f02cb3..5ca5b3d98 100644 --- a/paludis/repositories/unpackaged/installed_repository.cc +++ b/paludis/repositories/unpackaged/installed_repository.cc @@ -50,6 +50,7 @@ #include <paludis/hook.hh> #include <paludis/common_sets.hh> #include <paludis/package_database.hh> +#include <paludis/unformatted_pretty_printer.hh> #include <sstream> #include <sys/time.h> @@ -347,15 +348,13 @@ InstalledUnpackagedRepository::merge(const MergeParams & m) if (m.package_id()->build_dependencies_key()) { SafeOFStream build_dependencies_file(target_ver_dir / "build_dependencies", -1, true); - StringifyFormatter f; - build_dependencies_file << m.package_id()->build_dependencies_key()->pretty_print_flat(f) << std::endl; + build_dependencies_file << m.package_id()->build_dependencies_key()->pretty_print_value(UnformattedPrettyPrinter(), { }) << std::endl; } if (m.package_id()->run_dependencies_key()) { SafeOFStream run_dependencies_file(target_ver_dir / "run_dependencies", -1, true); - StringifyFormatter f; - run_dependencies_file << m.package_id()->run_dependencies_key()->pretty_print_flat(f) << std::endl; + run_dependencies_file << m.package_id()->run_dependencies_key()->pretty_print_value(UnformattedPrettyPrinter(), { }) << std::endl; } NDBAMMerger merger( diff --git a/paludis/unformatted_pretty_printer-fwd.hh b/paludis/unformatted_pretty_printer-fwd.hh new file mode 100644 index 000000000..5992da6d2 --- /dev/null +++ b/paludis/unformatted_pretty_printer-fwd.hh @@ -0,0 +1,28 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2010 Ciaran McCreesh + * + * 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_PALUDIS_UNFORMATTED_PRETTY_PRINTER_FWD_HH +#define PALUDIS_GUARD_PALUDIS_UNFORMATTED_PRETTY_PRINTER_FWD_HH 1 + +namespace paludis +{ + struct UnformattedPrettyPrinter; +} + +#endif diff --git a/paludis/unformatted_pretty_printer.cc b/paludis/unformatted_pretty_printer.cc new file mode 100644 index 000000000..793cf77bc --- /dev/null +++ b/paludis/unformatted_pretty_printer.cc @@ -0,0 +1,150 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2010 Ciaran McCreesh + * + * 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 <paludis/unformatted_pretty_printer.hh> +#include <paludis/util/stringify.hh> +#include <paludis/name.hh> + +using namespace paludis; + +UnformattedPrettyPrinter::UnformattedPrettyPrinter() = default; + +const std::string +UnformattedPrettyPrinter::indentify(const int i) const +{ + return std::string(i * 4, ' '); +} + +const std::string +UnformattedPrettyPrinter::newline() const +{ + return "\n"; +} + +const std::string +UnformattedPrettyPrinter::prettify(const PackageDepSpec & v) const +{ + return stringify(v); +} + +const std::string +UnformattedPrettyPrinter::prettify(const BlockDepSpec & v) const +{ + return stringify(v); +} + +const std::string +UnformattedPrettyPrinter::prettify(const ConditionalDepSpec & v) const +{ + return stringify(v); +} + +const std::string +UnformattedPrettyPrinter::prettify(const NamedSetDepSpec & v) const +{ + return stringify(v); +} + +const std::string +UnformattedPrettyPrinter::prettify(const SimpleURIDepSpec & v) const +{ + return stringify(v); +} + +const std::string +UnformattedPrettyPrinter::prettify(const PlainTextDepSpec & v) const +{ + return stringify(v); +} + +const std::string +UnformattedPrettyPrinter::prettify(const LicenseDepSpec & v) const +{ + return stringify(v); +} + +const std::string +UnformattedPrettyPrinter::prettify(const FetchableURIDepSpec & v) const +{ + return stringify(v); +} + +const std::string +UnformattedPrettyPrinter::prettify(const URILabelsDepSpec & v) const +{ + return stringify(v); +} + +const std::string +UnformattedPrettyPrinter::prettify(const DependenciesLabelsDepSpec & v) const +{ + return stringify(v); +} + +const std::string +UnformattedPrettyPrinter::prettify(const PlainTextLabelDepSpec & v) const +{ + return stringify(v); +} + +const std::string +UnformattedPrettyPrinter::prettify(const std::shared_ptr<const PackageID> & v) const +{ + return stringify(*v); +} + +const std::string +UnformattedPrettyPrinter::prettify(const bool v) const +{ + return stringify(v); +} + +const std::string +UnformattedPrettyPrinter::prettify(const long v) const +{ + return stringify(v); +} + +const std::string +UnformattedPrettyPrinter::prettify(const std::string & v) const +{ + return stringify(v); +} + +const std::string +UnformattedPrettyPrinter::prettify(const std::pair<const std::string, std::string> & v) const +{ + if (v.first.empty()) + return v.second; + else + return v.first + ": " + v.second; +} + +const std::string +UnformattedPrettyPrinter::prettify(const FSPath & v) const +{ + return stringify(v); +} + +const std::string +UnformattedPrettyPrinter::prettify(const KeywordName & v) const +{ + return stringify(v); +} + diff --git a/paludis/unformatted_pretty_printer.hh b/paludis/unformatted_pretty_printer.hh new file mode 100644 index 000000000..a9de9b09f --- /dev/null +++ b/paludis/unformatted_pretty_printer.hh @@ -0,0 +1,64 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2010 Ciaran McCreesh + * + * 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_PALUDIS_UNFORMATTED_PRETTY_PRINTER_HH +#define PALUDIS_GUARD_PALUDIS_UNFORMATTED_PRETTY_PRINTER_HH 1 + +#include <paludis/pretty_printer.hh> + +namespace paludis +{ + class PALUDIS_VISIBLE UnformattedPrettyPrinter : + public PrettyPrinter + { + public: + UnformattedPrettyPrinter(); + + virtual const std::string indentify(const int) const; + virtual const std::string newline() const; + + virtual const std::string prettify(const PackageDepSpec &) const; + virtual const std::string prettify(const BlockDepSpec &) const; + virtual const std::string prettify(const ConditionalDepSpec &) const; + virtual const std::string prettify(const NamedSetDepSpec &) const; + virtual const std::string prettify(const SimpleURIDepSpec &) const; + virtual const std::string prettify(const PlainTextDepSpec &) const; + virtual const std::string prettify(const LicenseDepSpec &) const; + virtual const std::string prettify(const FetchableURIDepSpec &) const; + virtual const std::string prettify(const URILabelsDepSpec &) const; + virtual const std::string prettify(const DependenciesLabelsDepSpec &) const; + virtual const std::string prettify(const PlainTextLabelDepSpec &) const; + + virtual const std::string prettify(const std::shared_ptr<const PackageID> &) const; + + virtual const std::string prettify(const bool) const; + + virtual const std::string prettify(const long) const; + + virtual const std::string prettify(const std::string &) const; + + virtual const std::string prettify(const std::pair<const std::string, std::string> &) const; + + virtual const std::string prettify(const FSPath &) const; + + virtual const std::string prettify(const KeywordName &) const; + }; +} + +#endif diff --git a/python/additional_tests.cc b/python/additional_tests.cc index 3065923db..1a1dbc51c 100644 --- a/python/additional_tests.cc +++ b/python/additional_tests.cc @@ -195,8 +195,6 @@ namespace metadata_key { test_metadata_key(m); m.value(); - StringifyFormatter ff; - m.pretty_print_flat(ff); } template <typename C_> @@ -204,9 +202,6 @@ namespace metadata_key { test_metadata_key(m); m.value(); - StringifyFormatter ff; - m.pretty_print(ff); - m.pretty_print_flat(ff); } template <> @@ -214,9 +209,6 @@ namespace metadata_key { test_metadata_key(m); m.value(); - StringifyFormatter ff; - m.pretty_print(ff); - m.pretty_print_flat(ff); m.initial_label(); } } diff --git a/python/metadata_key.cc b/python/metadata_key.cc index 9fa882861..31fed32e3 100644 --- a/python/metadata_key.cc +++ b/python/metadata_key.cc @@ -198,16 +198,6 @@ struct MetadataPackageIDKeyWrapper : throw PythonMethodNotImplemented("MetadataPackageIDKey", "value"); } - virtual std::string pretty_print(const Formatter<PackageID> &) const - { - Lock l(get_mutex()); - - if (bp::override f = get_override("pretty_print")) - return f(); - else - throw PythonMethodNotImplemented("MetadataPackageIDKey", "pretty_print"); - } - virtual const std::string raw_name() const { Lock l(get_mutex()); @@ -649,19 +639,6 @@ struct MetadataCollectionKeyWrapper : throw PythonMethodNotImplemented("MetadataCollectionKey", "value"); } - std::string pretty_print_flat(const Formatter< - typename std::remove_const< - typename RemoveSharedPtr<typename C_::value_type>::Type>::type> & formatter) const - PALUDIS_ATTRIBUTE((warn_unused_result)) - { - Lock l(get_mutex()); - - if (bp::override f = this->get_override("pretty_print_flat")) - return f(boost::cref(formatter)); - else - throw PythonMethodNotImplemented("MetadataCollectionKey", "pretty_print_flat"); - } - virtual const std::string raw_name() const { Lock l(get_mutex()); @@ -716,17 +693,6 @@ struct MetadataSpecTreeKeyWrapper : throw PythonMethodNotImplemented("MetadataSpecTreeKey", "value"); } - virtual std::string pretty_print(const typename C_::ItemFormatter & formatter) const - PALUDIS_ATTRIBUTE((warn_unused_result)) - { - Lock l(get_mutex()); - - if (bp::override f = this->get_override("pretty_print")) - return f(boost::cref(formatter)); - else - throw PythonMethodNotImplemented("MetadataSpecTreeKey", "pretty_print"); - } - virtual std::string pretty_print_flat(const typename C_::ItemFormatter & formatter) const PALUDIS_ATTRIBUTE((warn_unused_result)) { @@ -792,28 +758,6 @@ struct MetadataSpecTreeKeyWrapper<FetchableURISpecTree> : throw PythonMethodNotImplemented("MetadataSpecTreeKey", "value"); } - virtual std::string pretty_print(const FetchableURISpecTree::ItemFormatter & formatter) const - PALUDIS_ATTRIBUTE((warn_unused_result)) - { - Lock l(get_mutex()); - - if (bp::override f = this->get_override("pretty_print")) - return f(boost::cref(formatter)); - else - throw PythonMethodNotImplemented("MetadataSpecTreeKey", "pretty_print"); - } - - virtual std::string pretty_print_flat(const FetchableURISpecTree::ItemFormatter & formatter) const - PALUDIS_ATTRIBUTE((warn_unused_result)) - { - Lock l(get_mutex()); - - if (bp::override f = this->get_override("pretty_print_flat")) - return f(boost::cref(formatter)); - else - throw PythonMethodNotImplemented("MetadataSpecTreeKey", "pretty_print_flat"); - } - virtual const std::shared_ptr<const URILabel> initial_label() const PALUDIS_ATTRIBUTE((warn_unused_result)) { @@ -879,28 +823,6 @@ struct MetadataSpecTreeKeyWrapper<DependencySpecTree> : throw PythonMethodNotImplemented("MetadataSpecTreeKey", "value"); } - virtual std::string pretty_print(const DependencySpecTree::ItemFormatter & formatter) const - PALUDIS_ATTRIBUTE((warn_unused_result)) - { - Lock l(get_mutex()); - - if (bp::override f = this->get_override("pretty_print")) - return f(boost::cref(formatter)); - else - throw PythonMethodNotImplemented("MetadataSpecTreeKey", "pretty_print"); - } - - virtual std::string pretty_print_flat(const DependencySpecTree::ItemFormatter & formatter) const - PALUDIS_ATTRIBUTE((warn_unused_result)) - { - Lock l(get_mutex()); - - if (bp::override f = this->get_override("pretty_print_flat")) - return f(boost::cref(formatter)); - else - throw PythonMethodNotImplemented("MetadataSpecTreeKey", "pretty_print_flat"); - } - virtual const std::shared_ptr<const DependenciesLabelSequence> initial_labels() const PALUDIS_ATTRIBUTE((warn_unused_result)) { @@ -976,12 +898,6 @@ struct class_set_key : ("value() -> " + set + "\n" "Fetch our value.").c_str() ); - - def("pretty_print_flat", bp::pure_virtual(&MetadataCollectionKey<C_>::pretty_print_flat), - ("pretty_print_flat(" + set +"Formatter) -> string\n" - "Return a single-line formatted version of our value, using the\n" - "supplied Formatter to format individual items.").c_str() - ); } }; @@ -1011,18 +927,6 @@ struct class_spec_tree_key : ("value() -> " + spec_tree + "\n" "Fetch our value").c_str() ); - - def("pretty_print", bp::pure_virtual(&MetadataSpecTreeKey<C_>::pretty_print), - ("pretty_print(" + spec_tree + "Formatter) -> string\n" - "Return a multiline-line indented and formatted version of our\n" - "value, using the supplied Formatter to format individual items.").c_str() - ); - - def("pretty_print_flat", bp::pure_virtual(&MetadataSpecTreeKey<C_>::pretty_print_flat), - ("pretty_print_flat(" + spec_tree + "Formatter) -> string\n" - "Return a single-line formatted version of our value, using the\n" - "supplied Formatter to format individual items.").c_str() - ); } }; @@ -1055,18 +959,6 @@ struct class_spec_tree_key<FetchableURISpecTree> : "Fetch our value").c_str() ); - def("pretty_print", bp::pure_virtual(&MetadataSpecTreeKey<FetchableURISpecTree>::pretty_print), - ("pretty_print(" + spec_tree + "Formatter) -> string\n" - "Return a multiline-line indented and formatted version of our\n" - "value, using the supplied Formatter to format individual items.").c_str() - ); - - def("pretty_print_flat", bp::pure_virtual(&MetadataSpecTreeKey<FetchableURISpecTree>::pretty_print_flat), - ("pretty_print_flat(" + spec_tree + "Formatter) -> string\n" - "Return a single-line formatted version of our value, using the\n" - "supplied Formatter to format individual items.").c_str() - ); - def("initial_label", bp::pure_virtual(&MetadataSpecTreeKey<FetchableURISpecTree>::initial_label), "initial_label() -> URILabel\n" "Return a URILabel that represents the initial label to use when\n" @@ -1104,18 +996,6 @@ struct class_spec_tree_key<DependencySpecTree> : "Fetch our value").c_str() ); - def("pretty_print", bp::pure_virtual(&MetadataSpecTreeKey<DependencySpecTree>::pretty_print), - ("pretty_print(" + spec_tree + "Formatter) -> string\n" - "Return a multiline-line indented and formatted version of our\n" - "value, using the supplied Formatter to format individual items.").c_str() - ); - - def("pretty_print_flat", bp::pure_virtual(&MetadataSpecTreeKey<DependencySpecTree>::pretty_print_flat), - ("pretty_print_flat(" + spec_tree + "Formatter) -> string\n" - "Return a single-line formatted version of our value, using the\n" - "supplied Formatter to format individual items.").c_str() - ); - def("initial_labels", bp::pure_virtual(&MetadataSpecTreeKey<DependencySpecTree>::initial_labels), "initial_label() -> DependenciesLabelSequence\n" "Return a DependenciesLabelSequence that represents the initial labels to use when\n" diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am index 72679dc73..39a20a3b3 100644 --- a/src/clients/cave/Makefile.am +++ b/src/clients/cave/Makefile.am @@ -119,6 +119,7 @@ noinst_LIBRARIES = libcave.a # See note above for adding commands libcave_a_SOURCES = \ colour_formatter.cc colour_formatter.hh colour_formatter-fmt.hh \ + colour_pretty_printer.cc colour_pretty_printer.hh colour_pretty_printer-fmt.hh \ command.cc command.hh \ command_line.cc command_line.hh \ command_command_line.cc command_command_line.hh \ diff --git a/src/clients/cave/cmd_display_resolution.cc b/src/clients/cave/cmd_display_resolution.cc index fb6f5f2f4..ad0d913c7 100755 --- a/src/clients/cave/cmd_display_resolution.cc +++ b/src/clients/cave/cmd_display_resolution.cc @@ -23,6 +23,7 @@ #include "command_command_line.hh" #include "colours.hh" #include "colour_formatter.hh" +#include "colour_pretty_printer.hh" #include "format_user_config.hh" #include <paludis/args/do_help.hh> #include <paludis/util/safe_ifstream.hh> @@ -523,7 +524,7 @@ namespace } void display_choices( - const std::shared_ptr<Environment> &, + const std::shared_ptr<Environment> & env, const DisplayResolutionCommandLine & cmdline, const std::shared_ptr<const PackageID> & id, const std::shared_ptr<const WhyChangedChoices> & changed_choices, @@ -534,7 +535,7 @@ namespace if (! id->choices_key()) return; - ColourFormatter formatter(0); + ColourPrettyPrinter printer(env.get(), id, 0); std::shared_ptr<const Choices> old_choices; if (old_id && old_id->choices_key()) @@ -581,16 +582,16 @@ namespace if ((changed_state.is_indeterminate() && (*i)->enabled()) || (changed_state.is_true())) { if ((*i)->locked()) - t = formatter.format(**i, format::Forced()); + t = printer.prettify_choice_value_forced(*i); else - t = formatter.format(**i, format::Enabled()); + t = printer.prettify_choice_value_enabled(*i); } else { if ((*i)->locked()) - t = formatter.format(**i, format::Masked()); + t = printer.prettify_choice_value_masked(*i); else - t = formatter.format(**i, format::Disabled()); + t = printer.prettify_choice_value_disabled(*i); } bool changed(false), added(false); @@ -610,13 +611,11 @@ namespace } if (changed) - { - t = formatter.decorate(**i, t, format::Changed()); - } + t = t + "*"; else if (added) { if (old_id) - t = formatter.decorate(**i, t, format::Added()); + t = t + "+"; } s_prefix.first.append(t); @@ -866,6 +865,8 @@ namespace struct MaskedByKeyVisitor { + const Environment * const env; + const std::shared_ptr<const PackageID> id; const std::string indent; void visit(const MetadataValueKey<std::shared_ptr<const PackageID> > & k) @@ -923,91 +924,93 @@ namespace void visit(const MetadataCollectionKey<Set<std::string> > & k) { - ColourFormatter formatter(0); - cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_flat(formatter)))); + ColourPrettyPrinter printer(env, id, 0); + cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_value(printer, { })))); } void visit(const MetadataCollectionKey<Map<std::string, std::string> > & k) { - ColourFormatter formatter(0); - cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_flat(formatter)))); + ColourPrettyPrinter printer(env, id, 0); + cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_value(printer, { })))); } void visit(const MetadataCollectionKey<Sequence<std::string> > & k) { - ColourFormatter formatter(0); - cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_flat(formatter)))); + ColourPrettyPrinter printer(env, id, 0); + cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_value(printer, { })))); } void visit(const MetadataCollectionKey<FSPathSequence> & k) { - ColourFormatter formatter(0); - cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_flat(formatter)))); + ColourPrettyPrinter printer(env, id, 0); + cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_value(printer, { })))); } void visit(const MetadataCollectionKey<PackageIDSequence> & k) { - ColourFormatter formatter(0); - cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_flat(formatter)))); + ColourPrettyPrinter printer(env, id, 0); + cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_value(printer, { })))); } void visit(const MetadataSpecTreeKey<FetchableURISpecTree> & k) { - ColourFormatter formatter(0); - cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_flat(formatter)))); + ColourPrettyPrinter printer(env, id, 0); + cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_value(printer, { })))); } void visit(const MetadataSpecTreeKey<SimpleURISpecTree> & k) { - ColourFormatter formatter(0); - cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_flat(formatter)))); + ColourPrettyPrinter printer(env, id, 0); + cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_value(printer, { })))); } void visit(const MetadataSpecTreeKey<LicenseSpecTree> & k) { - ColourFormatter formatter(0); - cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_flat(formatter)))); + ColourPrettyPrinter printer(env, id, 0); + cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_value(printer, { })))); } void visit(const MetadataSpecTreeKey<DependencySpecTree> & k) { - ColourFormatter formatter(0); - cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_flat(formatter)))); + ColourPrettyPrinter printer(env, id, 0); + cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_value(printer, { })))); } void visit(const MetadataCollectionKey<KeywordNameSet> & k) { - ColourFormatter formatter(0); - cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_flat(formatter)))); + ColourPrettyPrinter printer(env, id, 0); + cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_value(printer, { })))); } void visit(const MetadataSpecTreeKey<ProvideSpecTree> & k) { - ColourFormatter formatter(0); - cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_flat(formatter)))); + ColourPrettyPrinter printer(env, id, 0); + cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_value(printer, { })))); } void visit(const MetadataSpecTreeKey<PlainTextSpecTree> & k) { - ColourFormatter formatter(0); - cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_flat(formatter)))); + ColourPrettyPrinter printer(env, id, 0); + cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_value(printer, { })))); } void visit(const MetadataSpecTreeKey<RequiredUseSpecTree> & k) { - ColourFormatter formatter(0); - cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_flat(formatter)))); + ColourPrettyPrinter printer(env, id, 0); + cout << fuc(fs_mask_by(), fv<'i'>(indent), fv<'k'>(k.human_name()), fv<'v'>(stringify(k.pretty_print_value(printer, { })))); } void visit(const MetadataValueKey<std::shared_ptr<const Choices> > & k) { - ColourFormatter formatter(0); + ColourPrettyPrinter printer(env, id, 0); cout << fuc(fs_mask_by_valueless(), fv<'i'>(indent), fv<'k'>(k.human_name())); } }; struct MaskedByVisitor { + const Environment * const env; + const std::shared_ptr<const PackageID> id; const std::string colour; const std::string indent; @@ -1019,7 +1022,7 @@ namespace void visit(const RepositoryMask & m) const { cout << fuc(fs_masked_by(), fv<'i'>(indent), fv<'c'>(colour), fv<'d'>(m.description())); - MaskedByKeyVisitor v{indent + " "}; + MaskedByKeyVisitor v{env, id, indent + " "}; if (m.mask_key()) m.mask_key()->accept(v); } @@ -1027,7 +1030,7 @@ namespace void visit(const UnacceptedMask & m) const { cout << fuc(fs_masked_by(), fv<'i'>(indent), fv<'c'>(colour), fv<'d'>(m.description())); - MaskedByKeyVisitor v{indent + " "}; + MaskedByKeyVisitor v{env, id, indent + " "}; if (m.unaccepted_key()) m.unaccepted_key()->accept(v); } @@ -1045,7 +1048,7 @@ namespace }; void display_masks( - const std::shared_ptr<Environment> &, + const std::shared_ptr<Environment> & env, const ChangesToMakeDecision & decision) { if (! decision.origin_id()->masked()) @@ -1053,7 +1056,7 @@ namespace for (auto m(decision.origin_id()->begin_masks()), m_end(decision.origin_id()->end_masks()) ; m != m_end ; ++m) - (*m)->accept(MaskedByVisitor{c::bold_red().colour_string(), " "}); + (*m)->accept(MaskedByVisitor{env.get(), decision.origin_id(), c::bold_red().colour_string(), " "}); } struct Totals @@ -1398,7 +1401,7 @@ namespace for (PackageID::MasksConstIterator m(u->package_id()->begin_masks()), m_end(u->package_id()->end_masks()) ; m != m_end ; ++m) - (*m)->accept(MaskedByVisitor{"", " "}); + (*m)->accept(MaskedByVisitor{env.get(), u->package_id(), "", " "}); std::set<std::string> duplicates; for (Constraints::ConstIterator c(u->unmet_constraints()->begin()), diff --git a/src/clients/cave/cmd_dump_cave_formats_conf.cc b/src/clients/cave/cmd_dump_cave_formats_conf.cc index 8539aed96..048edcce3 100644 --- a/src/clients/cave/cmd_dump_cave_formats_conf.cc +++ b/src/clients/cave/cmd_dump_cave_formats_conf.cc @@ -147,6 +147,8 @@ namespace #include "cmd_verify-fmt.hh" }{ #include "colour_formatter-fmt.hh" + }{ +#include "colour_pretty_printer-fmt.hh" } } }; diff --git a/src/clients/cave/cmd_import.cc b/src/clients/cave/cmd_import.cc index 6c1734f1b..2effd6d0f 100644 --- a/src/clients/cave/cmd_import.cc +++ b/src/clients/cave/cmd_import.cc @@ -39,6 +39,7 @@ #include <paludis/stringify_formatter.hh> #include <paludis/repository_factory.hh> #include <paludis/package_database.hh> +#include <paludis/unformatted_pretty_printer.hh> #include <iostream> #include <cstdlib> @@ -237,13 +238,12 @@ ImportCommand::run( throw args::DoHelp("--" + cmdline.a_preserve_metadata.long_name() + " specified but " "no old ID available"); - StringifyFormatter f; if (old_id->short_description_key()) description = old_id->short_description_key()->value(); if (old_id->build_dependencies_key()) - build_dependencies = old_id->build_dependencies_key()->pretty_print_flat(f); + build_dependencies = old_id->build_dependencies_key()->pretty_print_value(UnformattedPrettyPrinter(), { }); if (old_id->run_dependencies_key()) - run_dependencies = old_id->run_dependencies_key()->pretty_print_flat(f); + run_dependencies = old_id->run_dependencies_key()->pretty_print_value(UnformattedPrettyPrinter(), { }); } if (cmdline.a_description.specified()) diff --git a/src/clients/cave/cmd_info.cc b/src/clients/cave/cmd_info.cc index 66e56d9bf..0e60e5f34 100644 --- a/src/clients/cave/cmd_info.cc +++ b/src/clients/cave/cmd_info.cc @@ -20,6 +20,7 @@ #include "cmd_info.hh" #include "cmd_perform.hh" #include "colour_formatter.hh" +#include "colour_pretty_printer.hh" #include "colours.hh" #include "exceptions.hh" #include "format_user_config.hh" @@ -42,6 +43,7 @@ #include <paludis/util/simple_visitor_cast.hh> #include <paludis/util/pretty_print.hh> #include <paludis/util/timestamp.hh> +#include <paludis/util/make_null_shared_ptr.hh> #include <paludis/action.hh> #include <paludis/about_metadata.hh> #include <cstdlib> @@ -134,10 +136,12 @@ namespace struct InfoDisplayer { + const Environment * const env; const InfoCommandLine & cmdline; const int indent; - InfoDisplayer(const InfoCommandLine & c, const int i) : + InfoDisplayer(const Environment * const e, const InfoCommandLine & c, const int i) : + env(e), cmdline(c), indent(i) { @@ -150,39 +154,39 @@ namespace for (std::set<std::shared_ptr<const MetadataKey>, MetadataKeyComparator>::const_iterator s(keys.begin()), s_end(keys.end()) ; s != s_end ; ++s) { - InfoDisplayer i(cmdline, indent + 1); + InfoDisplayer i(env, cmdline, indent + 1); (*s)->accept(i); } } void visit(const MetadataCollectionKey<KeywordNameSet> & k) { - ColourFormatter f(indent); - cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(k.pretty_print_flat(f))); + ColourPrettyPrinter printer(env, make_null_shared_ptr(), indent); + cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(k.pretty_print_value(printer, { }))); } void visit(const MetadataCollectionKey<Set<std::string> > & k) { - ColourFormatter f(indent); - cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(k.pretty_print_flat(f))); + ColourPrettyPrinter printer(env, make_null_shared_ptr(), indent); + cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(k.pretty_print_value(printer, { }))); } void visit(const MetadataCollectionKey<Map<std::string, std::string> > & k) { - ColourFormatter f(indent); - cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(k.pretty_print_flat(f))); + ColourPrettyPrinter printer(env, make_null_shared_ptr(), indent); + cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(k.pretty_print_value(printer, { }))); } void visit(const MetadataCollectionKey<Sequence<std::string> > & k) { - ColourFormatter f(indent); - cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(k.pretty_print_flat(f))); + ColourPrettyPrinter printer(env, make_null_shared_ptr(), indent); + cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(k.pretty_print_value(printer, { }))); } void visit(const MetadataCollectionKey<PackageIDSequence> & k) { - ColourFormatter f(indent); - cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(k.pretty_print_flat(f))); + ColourPrettyPrinter printer(env, make_null_shared_ptr(), indent); + cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(k.pretty_print_value(printer, { }))); } void visit(const MetadataCollectionKey<FSPathSequence> & k) @@ -193,79 +197,79 @@ namespace void visit(const MetadataSpecTreeKey<LicenseSpecTree> & k) { - ColourFormatter f(indent); - cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(k.pretty_print_flat(f))); + ColourPrettyPrinter printer(env, make_null_shared_ptr(), indent); + cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(k.pretty_print_value(printer, { }))); } void visit(const MetadataSpecTreeKey<SimpleURISpecTree> & k) { - ColourFormatter f(indent); - cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(k.pretty_print_flat(f))); + ColourPrettyPrinter printer(env, make_null_shared_ptr(), indent); + cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(k.pretty_print_value(printer, { }))); } void visit(const MetadataSpecTreeKey<PlainTextSpecTree> & k) { - ColourFormatter f(indent); - cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(k.pretty_print_flat(f))); + ColourPrettyPrinter printer(env, make_null_shared_ptr(), indent); + cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(k.pretty_print_value(printer, { }))); } void visit(const MetadataSpecTreeKey<RequiredUseSpecTree> & k) { - ColourFormatter f(indent); - cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(k.pretty_print_flat(f))); + ColourPrettyPrinter printer(env, make_null_shared_ptr(), indent); + cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(k.pretty_print_value(printer, { }))); } void visit(const MetadataSpecTreeKey<FetchableURISpecTree> & k) { - ColourFormatter f(indent); - cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(k.pretty_print_flat(f))); + ColourPrettyPrinter printer(env, make_null_shared_ptr(), indent); + cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(k.pretty_print_value(printer, { }))); } void visit(const MetadataSpecTreeKey<ProvideSpecTree> & k) { - ColourFormatter f(indent); - cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(k.pretty_print_flat(f))); + ColourPrettyPrinter printer(env, make_null_shared_ptr(), indent); + cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(k.pretty_print_value(printer, { }))); } void visit(const MetadataSpecTreeKey<DependencySpecTree> & k) { - ColourFormatter f(indent); - cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(k.pretty_print_flat(f))); + ColourPrettyPrinter printer(env, make_null_shared_ptr(), indent); + cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(k.pretty_print_value(printer, { }))); } void visit(const MetadataValueKey<std::string> & k) { - ColourFormatter f(indent); + ColourPrettyPrinter printer(env, make_null_shared_ptr(), indent); cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(stringify(k.value()))); } void visit(const MetadataValueKey<SlotName> & k) { - ColourFormatter f(indent); + ColourPrettyPrinter printer(env, make_null_shared_ptr(), indent); cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(stringify(k.value()))); } void visit(const MetadataValueKey<long> & k) { - ColourFormatter f(indent); + ColourPrettyPrinter printer(env, make_null_shared_ptr(), indent); cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(stringify(k.value()))); } void visit(const MetadataValueKey<bool> & k) { - ColourFormatter f(indent); + ColourPrettyPrinter printer(env, make_null_shared_ptr(), indent); cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(stringify(k.value()))); } void visit(const MetadataValueKey<FSPath> & k) { - ColourFormatter f(indent); + ColourPrettyPrinter printer(env, make_null_shared_ptr(), indent); cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(stringify(k.value()))); } void visit(const MetadataValueKey<std::shared_ptr<const PackageID> > & k) { - ColourFormatter f(indent); + ColourPrettyPrinter printer(env, make_null_shared_ptr(), indent); cout << fuc(fs_metadata(), fv<'h'>(k.human_name()), fv<'i'>(std::string(indent, ' ')), fv<'s'>(stringify(*k.value()))); } @@ -289,7 +293,7 @@ namespace void do_one_repository( const InfoCommandLine & cmdline, - const std::shared_ptr<Environment> &, + const std::shared_ptr<Environment> & env, const std::shared_ptr<const Repository> & repo) { cout << fuc(fs_repository_heading(), fv<'s'>(stringify(repo->name()))); @@ -300,7 +304,7 @@ namespace if ((*k)->type() == mkt_internal) continue; - InfoDisplayer i(cmdline, 1); + InfoDisplayer i(env.get(), cmdline, 1); (*k)->accept(i); } cout << endl; @@ -318,7 +322,7 @@ namespace if ((*k)->type() == mkt_internal) continue; - InfoDisplayer i(cmdline, 1); + InfoDisplayer i(env.get(), cmdline, 1); (*k)->accept(i); } cout << endl; @@ -326,7 +330,7 @@ namespace void do_about( const InfoCommandLine & cmdline, - const std::shared_ptr<Environment> &) + const std::shared_ptr<Environment> & env) { cout << fuc(fs_heading(), fv<'s'>("Package Manager Information")); std::set<std::shared_ptr<const MetadataKey>, MetadataKeyComparator> keys(AboutMetadata::get_instance()->begin_metadata(), @@ -337,7 +341,7 @@ namespace if ((*k)->type() == mkt_internal) continue; - InfoDisplayer i(cmdline, 1); + InfoDisplayer i(env.get(), cmdline, 1); (*k)->accept(i); } cout << endl; diff --git a/src/clients/cave/cmd_show.cc b/src/clients/cave/cmd_show.cc index 02bd903ba..be967aec4 100644 --- a/src/clients/cave/cmd_show.cc +++ b/src/clients/cave/cmd_show.cc @@ -19,6 +19,7 @@ #include "cmd_show.hh" #include "colour_formatter.hh" +#include "colour_pretty_printer.hh" #include "colours.hh" #include "exceptions.hh" #include "select_format_for_spec.hh" @@ -344,6 +345,7 @@ namespace struct InfoDisplayer { + const std::shared_ptr<const Environment> env; const ShowCommandLine & cmdline; const int indent; const bool important; @@ -352,10 +354,13 @@ namespace const bool old_id_is_installed; std::ostream & out; - InfoDisplayer(const ShowCommandLine & c, const int i, const bool m, + InfoDisplayer( + const std::shared_ptr<const Environment> & e, + const ShowCommandLine & c, const int i, const bool m, const std::shared_ptr<const PackageID> & k, const std::shared_ptr<const PackageID> & o, const bool b, std::ostream & ou) : + env(e), cmdline(c), indent(i), important(m), @@ -377,7 +382,7 @@ namespace for (std::set<std::shared_ptr<const MetadataKey>, MetadataKeyComparator>::const_iterator s(keys.begin()), s_end(keys.end()) ; s != s_end ; ++s) { - InfoDisplayer i(cmdline, indent + 1, ((*s)->type() == mkt_significant), maybe_current_id, maybe_old_id, old_id_is_installed, out); + InfoDisplayer i(env, cmdline, indent + 1, ((*s)->type() == mkt_significant), maybe_current_id, maybe_old_id, old_id_is_installed, out); if (want_key(cmdline, *s, maybe_current_id)) accept_visitor(i)(**s); } @@ -385,11 +390,11 @@ namespace void visit(const MetadataCollectionKey<KeywordNameSet> & k) { - ColourFormatter f(indent); + ColourPrettyPrinter printer(env.get(), maybe_current_id, indent); out << fuc( (cmdline.a_raw_names.specified() ? fs_metadata_value_raw() : fs_metadata_value_human()), fv<'s'>(cmdline.a_raw_names.specified() ? k.raw_name() : k.human_name()), - fv<'v'>(k.pretty_print_flat(f)), + fv<'v'>(k.pretty_print_value(printer, { })), fv<'i'>(std::string(indent, ' ')), fv<'b'>(important ? "true" : ""), fv<'p'>("") @@ -398,11 +403,11 @@ namespace void visit(const MetadataCollectionKey<Set<std::string> > & k) { - ColourFormatter f(indent); + ColourPrettyPrinter printer(env.get(), maybe_current_id, indent); out << fuc( (cmdline.a_raw_names.specified() ? fs_metadata_value_raw() : fs_metadata_value_human()), fv<'s'>(cmdline.a_raw_names.specified() ? k.raw_name() : k.human_name()), - fv<'v'>(k.pretty_print_flat(f)), + fv<'v'>(k.pretty_print_value(printer, { })), fv<'i'>(std::string(indent, ' ')), fv<'b'>(important ? "true" : ""), fv<'p'>("") @@ -411,11 +416,11 @@ namespace void visit(const MetadataCollectionKey<Map<std::string, std::string> > & k) { - ColourFormatter f(indent); + ColourPrettyPrinter printer(env.get(), maybe_current_id, indent); out << fuc( (cmdline.a_raw_names.specified() ? fs_metadata_value_raw() : fs_metadata_value_human()), fv<'s'>(cmdline.a_raw_names.specified() ? k.raw_name() : k.human_name()), - fv<'v'>(k.pretty_print_flat(f)), + fv<'v'>(k.pretty_print_value(printer, { })), fv<'i'>(std::string(indent, ' ')), fv<'b'>(important ? "true" : ""), fv<'p'>("") @@ -424,11 +429,11 @@ namespace void visit(const MetadataCollectionKey<Sequence<std::string> > & k) { - ColourFormatter f(indent); + ColourPrettyPrinter printer(env.get(), maybe_current_id, indent); out << fuc( (cmdline.a_raw_names.specified() ? fs_metadata_value_raw() : fs_metadata_value_human()), fv<'s'>(cmdline.a_raw_names.specified() ? k.raw_name() : k.human_name()), - fv<'v'>(k.pretty_print_flat(f)), + fv<'v'>(k.pretty_print_value(printer, { })), fv<'i'>(std::string(indent, ' ')), fv<'b'>(important ? "true" : ""), fv<'p'>("") @@ -437,11 +442,11 @@ namespace void visit(const MetadataCollectionKey<PackageIDSequence> & k) { - ColourFormatter f(indent); + ColourPrettyPrinter printer(env.get(), maybe_current_id, indent); out << fuc( (cmdline.a_raw_names.specified() ? fs_metadata_value_raw() : fs_metadata_value_human()), fv<'s'>(cmdline.a_raw_names.specified() ? k.raw_name() : k.human_name()), - fv<'v'>(k.pretty_print_flat(f)), + fv<'v'>(k.pretty_print_value(printer, { })), fv<'i'>(std::string(indent, ' ')), fv<'b'>(important ? "true" : ""), fv<'p'>("") @@ -462,11 +467,11 @@ namespace void visit(const MetadataSpecTreeKey<LicenseSpecTree> & k) { - ColourFormatter f(indent); + ColourPrettyPrinter printer(env.get(), maybe_current_id, indent); out << fuc( (cmdline.a_raw_names.specified() ? fs_metadata_value_raw() : fs_metadata_value_human()), fv<'s'>(cmdline.a_raw_names.specified() ? k.raw_name() : k.human_name()), - fv<'v'>(k.pretty_print_flat(f)), + fv<'v'>(k.pretty_print_value(printer, { })), fv<'i'>(std::string(indent, ' ')), fv<'b'>(important ? "true" : ""), fv<'p'>("") @@ -477,11 +482,11 @@ namespace { if (cmdline.a_complex_keys.specified() || important) { - ColourFormatter f(indent); + ColourPrettyPrinter printer(env.get(), maybe_current_id, indent); out << fuc( (cmdline.a_raw_names.specified() ? fs_metadata_value_raw() : fs_metadata_value_human()), fv<'s'>(cmdline.a_raw_names.specified() ? k.raw_name() : k.human_name()), - fv<'v'>(k.pretty_print_flat(f)), + fv<'v'>(k.pretty_print_value(printer, { })), fv<'i'>(std::string(indent, ' ')), fv<'b'>(important ? "true" : ""), fv<'p'>("") @@ -493,12 +498,12 @@ namespace { if (cmdline.a_complex_keys.specified() || important) { - ColourFormatter f(indent); + ColourPrettyPrinter printer(env.get(), maybe_current_id, indent); if (cmdline.a_flat.specified()) out << fuc( (cmdline.a_raw_names.specified() ? fs_metadata_value_raw() : fs_metadata_value_human()), fv<'s'>(cmdline.a_raw_names.specified() ? k.raw_name() : k.human_name()), - fv<'v'>(k.pretty_print_flat(f)), + fv<'v'>(k.pretty_print_value(printer, { })), fv<'i'>(std::string(indent, ' ')), fv<'b'>(important ? "true" : ""), fv<'p'>("") @@ -513,7 +518,7 @@ namespace fv<'b'>(important ? "true" : ""), fv<'p'>("") ); - out << k.pretty_print(f); + out << k.pretty_print_value(printer, { ppo_multiline_allowed }); } } } @@ -522,12 +527,12 @@ namespace { if (cmdline.a_complex_keys.specified() || important) { - ColourFormatter f(indent); + ColourPrettyPrinter printer(env.get(), maybe_current_id, indent); if (cmdline.a_flat.specified()) out << fuc( (cmdline.a_raw_names.specified() ? fs_metadata_value_raw() : fs_metadata_value_human()), fv<'s'>(cmdline.a_raw_names.specified() ? k.raw_name() : k.human_name()), - fv<'v'>(k.pretty_print_flat(f)), + fv<'v'>(k.pretty_print_value(printer, { })), fv<'i'>(std::string(indent, ' ')), fv<'b'>(important ? "true" : ""), fv<'p'>("") @@ -542,7 +547,7 @@ namespace fv<'b'>(important ? "true" : ""), fv<'p'>("") ); - out << k.pretty_print(f); + out << k.pretty_print_value(printer, { ppo_multiline_allowed }); } } } @@ -551,12 +556,12 @@ namespace { if (cmdline.a_complex_keys.specified() || important) { - ColourFormatter f(indent); + ColourPrettyPrinter printer(env.get(), maybe_current_id, indent); if (cmdline.a_flat.specified()) out << fuc( (cmdline.a_raw_names.specified() ? fs_metadata_value_raw() : fs_metadata_value_human()), fv<'s'>(cmdline.a_raw_names.specified() ? k.raw_name() : k.human_name()), - fv<'v'>(k.pretty_print_flat(f)), + fv<'v'>(k.pretty_print_value(printer, { })), fv<'i'>(std::string(indent, ' ')), fv<'b'>(important ? "true" : ""), fv<'p'>("") @@ -571,7 +576,7 @@ namespace fv<'b'>(important ? "true" : ""), fv<'p'>("") ); - out << k.pretty_print(f); + out << k.pretty_print_value(printer, { ppo_multiline_allowed }); } } } @@ -580,11 +585,11 @@ namespace { if (cmdline.a_complex_keys.specified() || important) { - ColourFormatter f(indent); + ColourPrettyPrinter printer(env.get(), maybe_current_id, indent); out << fuc( (cmdline.a_raw_names.specified() ? fs_metadata_value_raw() : fs_metadata_value_human()), fv<'s'>(cmdline.a_raw_names.specified() ? k.raw_name() : k.human_name()), - fv<'v'>(k.pretty_print_flat(f)), + fv<'v'>(k.pretty_print_value(printer, { })), fv<'i'>(std::string(indent, ' ')), fv<'b'>(important ? "true" : ""), fv<'p'>("") @@ -596,12 +601,12 @@ namespace { if (cmdline.a_complex_keys.specified() || important) { - ColourFormatter f(indent); + ColourPrettyPrinter printer(env.get(), maybe_current_id, indent); if (cmdline.a_flat.specified()) out << fuc( (cmdline.a_raw_names.specified() ? fs_metadata_value_raw() : fs_metadata_value_human()), fv<'s'>(cmdline.a_raw_names.specified() ? k.raw_name() : k.human_name()), - fv<'v'>(k.pretty_print_flat(f)), + fv<'v'>(k.pretty_print_value(printer, { })), fv<'i'>(std::string(indent, ' ')), fv<'b'>(important ? "true" : ""), fv<'p'>("") @@ -616,7 +621,7 @@ namespace fv<'b'>(important ? "true" : ""), fv<'p'>("") ); - out << k.pretty_print(f); + out << k.pretty_print_value(printer, { ppo_multiline_allowed }); } } } @@ -962,11 +967,13 @@ namespace struct MaskDisplayer { + const std::shared_ptr<const Environment> env; const ShowCommandLine & cmdline; const int indent; std::ostream & out; - MaskDisplayer(const ShowCommandLine & c, const int i, std::ostream & o) : + MaskDisplayer(const std::shared_ptr<const Environment> & e, const ShowCommandLine & c, const int i, std::ostream & o) : + env(e), cmdline(c), indent(i), out(o) @@ -977,7 +984,7 @@ namespace { if (m.unaccepted_key()) { - InfoDisplayer i(cmdline, indent, false, make_null_shared_ptr(), make_null_shared_ptr(), false, out); + InfoDisplayer i(env, cmdline, indent, false, make_null_shared_ptr(), make_null_shared_ptr(), false, out); m.unaccepted_key()->accept(i); } else @@ -1033,7 +1040,7 @@ namespace { if (m.mask_key()) { - InfoDisplayer i(cmdline, indent, false, make_null_shared_ptr(), make_null_shared_ptr(), false, out); + InfoDisplayer i(env, cmdline, indent, false, make_null_shared_ptr(), make_null_shared_ptr(), false, out); m.mask_key()->accept(i); } else @@ -1062,7 +1069,7 @@ namespace for (std::set<std::shared_ptr<const MetadataKey>, MetadataKeyComparator>::const_iterator k(keys.begin()), k_end(keys.end()) ; k != k_end ; ++k) { - InfoDisplayer i(cmdline, 0, ((*k)->type() == mkt_significant), make_null_shared_ptr(), make_null_shared_ptr(), false, cout); + InfoDisplayer i(env, cmdline, 0, ((*k)->type() == mkt_significant), make_null_shared_ptr(), make_null_shared_ptr(), false, cout); if (want_key(cmdline, *k, make_null_shared_ptr())) accept_visitor(i)(**k); } @@ -1071,7 +1078,7 @@ namespace void do_one_package_id( const ShowCommandLine & cmdline, - const std::shared_ptr<Environment> &, + const std::shared_ptr<Environment> & env, const std::shared_ptr<const PackageID> & best, const std::shared_ptr<const PackageID> & maybe_old_id, const bool old_id_is_installed, @@ -1083,7 +1090,7 @@ namespace k(keys.begin()), k_end(keys.end()) ; k != k_end ; ++k) { bool explicit_key(cmdline.a_key.end_args() != std::find(cmdline.a_key.begin_args(), cmdline.a_key.end_args(), (*k)->raw_name())); - InfoDisplayer i(cmdline, 1, ((*k)->type() == mkt_significant) || explicit_key, best, maybe_old_id, old_id_is_installed, out); + InfoDisplayer i(env, cmdline, 1, ((*k)->type() == mkt_significant) || explicit_key, best, maybe_old_id, old_id_is_installed, out); if (want_key(cmdline, *k, best)) accept_visitor(i)(**k); } @@ -1091,14 +1098,14 @@ namespace if (best->masked()) { out << fuc(fs_package_id_masks(), fv<'s'>("Masked")); - MaskDisplayer d(cmdline, 2, out); + MaskDisplayer d(env, cmdline, 2, out); std::for_each(indirect_iterator(best->begin_masks()), indirect_iterator(best->end_masks()), accept_visitor(d)); } if (best->begin_overridden_masks() != best->end_overridden_masks()) { out << fuc(fs_package_id_masks_overridden(), fv<'s'>("Overridden Masks")); - MaskDisplayer d(cmdline, 2, out); + MaskDisplayer d(env, cmdline, 2, out); for (PackageID::OverriddenMasksConstIterator m(best->begin_overridden_masks()), m_end(best->end_overridden_masks()) ; m != m_end ; ++m) (*m)->mask()->accept(d); diff --git a/src/clients/cave/colour_pretty_printer-fmt.hh b/src/clients/cave/colour_pretty_printer-fmt.hh new file mode 100644 index 000000000..684a76ffa --- /dev/null +++ b/src/clients/cave/colour_pretty_printer-fmt.hh @@ -0,0 +1,35 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +const auto fs_pretty_print_enabled = make_format_string_fetcher("pretty-print/enabled", 1) + << c::green_or_pink() << param<'s'>() << c::normal(); + +const auto fs_pretty_print_disabled = make_format_string_fetcher("pretty-print/disabled", 1) + << c::red() << param<'s'>() << c::normal(); + +const auto fs_pretty_print_installed = make_format_string_fetcher("pretty-print/installed", 1) + << c::bold_blue_or_pink() << param<'s'>() << c::normal(); + +const auto fs_pretty_print_installable = make_format_string_fetcher("pretty-print/installable", 1) + << c::blue_or_pink() << param<'s'>() << c::normal(); + +const auto fs_pretty_print_masked = make_format_string_fetcher("pretty-print/masked", 1) + << c::red() << param<'s'>() << c::normal(); + +const auto fs_pretty_print_plain = make_format_string_fetcher("pretty-print/plain", 1) + << param<'s'>(); + +const auto fs_pretty_print_indent = make_format_string_fetcher("pretty-print/indent", 1) + << "%{column 30}" << param<'i'>() << param<'i'>() << param<'i'>() << param<'i'>(); + +const auto fs_pretty_print_choice_value_enabled = make_format_string_fetcher("pretty-print-choice-value/enabled", 1) + << c::green_or_pink() << param<'k'>() << c::normal() << param<'v'>(); + +const auto fs_pretty_print_choice_value_disabled = make_format_string_fetcher("pretty-print-choice-value/disabled", 1) + << c::red() << "-" << param<'s'>() << c::normal(); + +const auto fs_pretty_print_choice_value_forced = make_format_string_fetcher("pretty-print-choice-value/forced", 1) + << c::green_or_pink() << "(" << param<'k'>() << param<'v'>() << ")" << c::normal(); + +const auto fs_pretty_print_choice_value_masked = make_format_string_fetcher("pretty-print-choice-value/masked", 1) + << c::red() << "(-" << param<'s'>() << ")" << c::normal(); + diff --git a/src/clients/cave/colour_pretty_printer.cc b/src/clients/cave/colour_pretty_printer.cc new file mode 100644 index 000000000..1f1e09f27 --- /dev/null +++ b/src/clients/cave/colour_pretty_printer.cc @@ -0,0 +1,121 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2010 Ciaran McCreesh + * + * 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 "colour_pretty_printer.hh" +#include "colours.hh" +#include "format_user_config.hh" +#include <paludis/util/stringify.hh> +#include <paludis/name.hh> +#include <paludis/choice.hh> + +using namespace paludis; +using namespace cave; + +ColourPrettyPrinter::ColourPrettyPrinter( + const Environment * const env, + const std::shared_ptr<const PackageID> & id, + const int initial_indent) : + FormattedPrettyPrinter(env, id), + _initial_indent(initial_indent) +{ +} + +namespace +{ +#include "colour_pretty_printer-fmt.hh" +} + +const std::string +ColourPrettyPrinter::format_enabled(const std::string & v) const +{ + return fuc(fs_pretty_print_enabled(), fv<'s'>(v)); +} + +const std::string +ColourPrettyPrinter::format_disabled(const std::string & v) const +{ + return fuc(fs_pretty_print_disabled(), fv<'s'>(v)); +} + +const std::string +ColourPrettyPrinter::format_installed(const std::string & v) const +{ + return fuc(fs_pretty_print_installed(), fv<'s'>(v)); +} + +const std::string +ColourPrettyPrinter::format_installable(const std::string & v) const +{ + return fuc(fs_pretty_print_installable(), fv<'s'>(v)); +} + +const std::string +ColourPrettyPrinter::format_masked(const std::string & v) const +{ + return fuc(fs_pretty_print_masked(), fv<'s'>(v)); +} + +const std::string +ColourPrettyPrinter::format_plain(const std::string & v) const +{ + return fuc(fs_pretty_print_plain(), fv<'s'>(v)); +} + +const std::string +ColourPrettyPrinter::indentify(const int i) const +{ + return fuc(fs_pretty_print_indent(), fv<'i'>(std::string(_initial_indent + i, ' '))); +} + +const std::string +ColourPrettyPrinter::newline() const +{ + return "\n"; +} + +const std::string +ColourPrettyPrinter::prettify_choice_value_forced(const std::shared_ptr<const ChoiceValue> & v) const +{ + return fuc(fs_pretty_print_choice_value_forced(), + fv<'k'>(stringify(v->unprefixed_name())), + fv<'v'>(v->parameter().empty() ? "" : "=" + v->parameter())); +} + +const std::string +ColourPrettyPrinter::prettify_choice_value_enabled(const std::shared_ptr<const ChoiceValue> & v) const +{ + return fuc(fs_pretty_print_choice_value_enabled(), + fv<'k'>(stringify(v->unprefixed_name())), + fv<'v'>(v->parameter().empty() ? "" : "=" + v->parameter())); +} + +const std::string +ColourPrettyPrinter::prettify_choice_value_masked(const std::shared_ptr<const ChoiceValue> & v) const +{ + return fuc(fs_pretty_print_choice_value_masked(), + fv<'s'>(stringify(v->unprefixed_name()))); +} + +const std::string +ColourPrettyPrinter::prettify_choice_value_disabled(const std::shared_ptr<const ChoiceValue> & v) const +{ + return fuc(fs_pretty_print_choice_value_disabled(), + fv<'s'>(stringify(v->unprefixed_name()))); +} + diff --git a/src/clients/cave/colour_pretty_printer.hh b/src/clients/cave/colour_pretty_printer.hh new file mode 100644 index 000000000..f49befb62 --- /dev/null +++ b/src/clients/cave/colour_pretty_printer.hh @@ -0,0 +1,62 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2010 Ciaran McCreesh + * + * 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_CLIENTS_CAVE_COLOUR_PRETTY_PRINTER_HH +#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_COLOUR_PRETTY_PRINTER_HH 1 + +#include <paludis/formatted_pretty_printer.hh> +#include <paludis/choice-fwd.hh> + +namespace paludis +{ + namespace cave + { + class ColourPrettyPrinter : + public FormattedPrettyPrinter + { + private: + int _initial_indent; + + protected: + virtual const std::string format_enabled(const std::string &) const; + virtual const std::string format_disabled(const std::string &) const; + virtual const std::string format_installed(const std::string &) const; + virtual const std::string format_installable(const std::string &) const; + virtual const std::string format_masked(const std::string &) const; + virtual const std::string format_plain(const std::string &) const; + + public: + ColourPrettyPrinter( + const Environment * const env, + const std::shared_ptr<const PackageID> & id, + const int initial_indent); + + virtual const std::string indentify(const int) const; + virtual const std::string newline() const; + + const std::string prettify_choice_value_forced(const std::shared_ptr<const ChoiceValue> &) const; + const std::string prettify_choice_value_enabled(const std::shared_ptr<const ChoiceValue> &) const; + const std::string prettify_choice_value_masked(const std::shared_ptr<const ChoiceValue> &) const; + const std::string prettify_choice_value_disabled(const std::shared_ptr<const ChoiceValue> &) const; + }; + } +} + + +#endif diff --git a/src/clients/cave/format_plain_metadata_key.cc b/src/clients/cave/format_plain_metadata_key.cc index 8394b13a2..c33f6a5ca 100644 --- a/src/clients/cave/format_plain_metadata_key.cc +++ b/src/clients/cave/format_plain_metadata_key.cc @@ -28,6 +28,7 @@ #include <paludis/stringify_formatter.hh> #include <paludis/metadata_key.hh> #include <paludis/mask.hh> +#include <paludis/unformatted_pretty_printer.hh> #include <sstream> using namespace paludis; @@ -95,80 +96,67 @@ namespace void visit(const MetadataSpecTreeKey<DependencySpecTree> & k) { - StringifyFormatter f; - s << k.pretty_print_flat(f); + s << k.pretty_print_value(UnformattedPrettyPrinter(), { }); } void visit(const MetadataSpecTreeKey<ProvideSpecTree> & k) { - StringifyFormatter f; - s << k.pretty_print_flat(f); + s << k.pretty_print_value(UnformattedPrettyPrinter(), { }); } void visit(const MetadataSpecTreeKey<FetchableURISpecTree> & k) { - StringifyFormatter f; - s << k.pretty_print_flat(f); + s << k.pretty_print_value(UnformattedPrettyPrinter(), { }); } void visit(const MetadataSpecTreeKey<PlainTextSpecTree> & k) { - StringifyFormatter f; - s << k.pretty_print_flat(f); + s << k.pretty_print_value(UnformattedPrettyPrinter(), { }); } void visit(const MetadataSpecTreeKey<RequiredUseSpecTree> & k) { - StringifyFormatter f; - s << k.pretty_print_flat(f); + s << k.pretty_print_value(UnformattedPrettyPrinter(), { }); } void visit(const MetadataSpecTreeKey<SimpleURISpecTree> & k) { - StringifyFormatter f; - s << k.pretty_print_flat(f); + s << k.pretty_print_value(UnformattedPrettyPrinter(), { }); } void visit(const MetadataSpecTreeKey<LicenseSpecTree> & k) { - StringifyFormatter f; - s << k.pretty_print_flat(f); + s << k.pretty_print_value(UnformattedPrettyPrinter(), { }); } void visit(const MetadataCollectionKey<FSPathSequence> & k) { - StringifyFormatter f; - s << k.pretty_print_flat(f); + s << k.pretty_print_value(UnformattedPrettyPrinter(), { }); } void visit(const MetadataCollectionKey<PackageIDSequence> & k) { - StringifyFormatter f; - s << k.pretty_print_flat(f); + s << k.pretty_print_value(UnformattedPrettyPrinter(), { }); } void visit(const MetadataCollectionKey<Sequence<std::string> > & k) { - StringifyFormatter f; - s << k.pretty_print_flat(f); + s << k.pretty_print_value(UnformattedPrettyPrinter(), { }); } void visit(const MetadataCollectionKey<Set<std::string> > & k) { - StringifyFormatter f; - s << k.pretty_print_flat(f); + s << k.pretty_print_value(UnformattedPrettyPrinter(), { }); } void visit(const MetadataCollectionKey<Map<std::string, std::string> > & k) { - StringifyFormatter f; - s << k.pretty_print_flat(f); + s << k.pretty_print_value(UnformattedPrettyPrinter(), { }); } void visit(const MetadataCollectionKey<KeywordNameSet> & k) { - StringifyFormatter f; - s << k.pretty_print_flat(f); + s << k.pretty_print_value(UnformattedPrettyPrinter(), { }); } void visit(const MetadataSectionKey &) diff --git a/src/clients/importare/importare.cc b/src/clients/importare/importare.cc index 62bce7a53..bfab58147 100644 --- a/src/clients/importare/importare.cc +++ b/src/clients/importare/importare.cc @@ -39,6 +39,7 @@ #include <paludis/filtered_generator.hh> #include <paludis/selection.hh> #include <paludis/user_dep_spec.hh> +#include <paludis/unformatted_pretty_printer.hh> #include <algorithm> #include <iterator> @@ -171,13 +172,12 @@ main(int argc, char *argv[]) throw args::DoHelp("--" + CommandLine::get_instance()->a_preserve_metadata.long_name() + " specified but " "no old ID available"); - StringifyFormatter f; if (old_id->short_description_key()) description = old_id->short_description_key()->value(); if (old_id->build_dependencies_key()) - build_dependencies = old_id->build_dependencies_key()->pretty_print_flat(f); + build_dependencies = old_id->build_dependencies_key()->pretty_print_value(UnformattedPrettyPrinter(), { }); if (old_id->run_dependencies_key()) - run_dependencies = old_id->run_dependencies_key()->pretty_print_flat(f); + run_dependencies = old_id->run_dependencies_key()->pretty_print_value(UnformattedPrettyPrinter(), { }); } if (CommandLine::get_instance()->a_description.specified()) diff --git a/src/clients/inquisitio/key_extractor.cc b/src/clients/inquisitio/key_extractor.cc index ff5c597d0..203866958 100644 --- a/src/clients/inquisitio/key_extractor.cc +++ b/src/clients/inquisitio/key_extractor.cc @@ -33,6 +33,7 @@ #include <paludis/dep_spec.hh> #include <paludis/environment.hh> #include <paludis/choice.hh> +#include <paludis/unformatted_pretty_printer.hh> #include <functional> #include <algorithm> @@ -360,8 +361,7 @@ namespace { if (_flatten) { - StringifyFormatter f; - result = _m(s.pretty_print_flat(f)); + result = _m(s.pretty_print_value(UnformattedPrettyPrinter(), { })); } else { @@ -375,8 +375,7 @@ namespace { if (_flatten) { - StringifyFormatter f; - result = _m(s.pretty_print_flat(f)); + result = _m(s.pretty_print_value(UnformattedPrettyPrinter(), { })); } else { @@ -390,8 +389,7 @@ namespace { if (_flatten) { - StringifyFormatter f; - result = _m(s.pretty_print_flat(f)); + result = _m(s.pretty_print_value(UnformattedPrettyPrinter(), { })); } else { @@ -405,8 +403,7 @@ namespace { if (_flatten) { - StringifyFormatter f; - result = _m(s.pretty_print_flat(f)); + result = _m(s.pretty_print_value(UnformattedPrettyPrinter(), { })); } else { @@ -420,8 +417,7 @@ namespace { if (_flatten) { - StringifyFormatter f; - result = _m(s.pretty_print_flat(f)); + result = _m(s.pretty_print_value(UnformattedPrettyPrinter(), { })); } else { @@ -435,8 +431,7 @@ namespace { if (_flatten) { - StringifyFormatter f; - result = _m(s.pretty_print_flat(f)); + result = _m(s.pretty_print_value(UnformattedPrettyPrinter(), { })); } else { @@ -450,8 +445,7 @@ namespace { if (_flatten) { - StringifyFormatter f; - result = _m(s.pretty_print_flat(f)); + result = _m(s.pretty_print_value(UnformattedPrettyPrinter(), { })); } else { @@ -465,8 +459,7 @@ namespace { if (_flatten) { - StringifyFormatter f; - result = _m(s.pretty_print_flat(f)); + result = _m(s.pretty_print_value(UnformattedPrettyPrinter(), { })); } else { diff --git a/src/clients/paludis/applets.cc b/src/clients/paludis/applets.cc index 5050fb775..04982ab42 100644 --- a/src/clients/paludis/applets.cc +++ b/src/clients/paludis/applets.cc @@ -102,80 +102,67 @@ namespace void visit(const MetadataSpecTreeKey<PlainTextSpecTree> & k) { - StringifyFormatter f; - std::cout << k.pretty_print_flat(f) << std::endl; + std::cout << k.pretty_print_value(UnformattedPrettyPrinter(), { }) << std::endl; } void visit(const MetadataSpecTreeKey<RequiredUseSpecTree> & k) { - StringifyFormatter f; - std::cout << k.pretty_print_flat(f) << std::endl; + std::cout << k.pretty_print_value(UnformattedPrettyPrinter(), { }) << std::endl; } void visit(const MetadataSpecTreeKey<ProvideSpecTree> & k) { - StringifyFormatter f; - std::cout << k.pretty_print_flat(f) << std::endl; + std::cout << k.pretty_print_value(UnformattedPrettyPrinter(), { }) << std::endl; } void visit(const MetadataSpecTreeKey<FetchableURISpecTree> & k) { - StringifyFormatter f; - std::cout << k.pretty_print_flat(f) << std::endl; + std::cout << k.pretty_print_value(UnformattedPrettyPrinter(), { }) << std::endl; } void visit(const MetadataSpecTreeKey<DependencySpecTree> & k) { - StringifyFormatter f; - std::cout << k.pretty_print_flat(f) << std::endl; + std::cout << k.pretty_print_value(UnformattedPrettyPrinter(), { }) << std::endl; } void visit(const MetadataSpecTreeKey<SimpleURISpecTree> & k) { - StringifyFormatter f; - std::cout << k.pretty_print_flat(f) << std::endl; + std::cout << k.pretty_print_value(UnformattedPrettyPrinter(), { }) << std::endl; } void visit(const MetadataSpecTreeKey<LicenseSpecTree> & k) { - StringifyFormatter f; - std::cout << k.pretty_print_flat(f) << std::endl; + std::cout << k.pretty_print_value(UnformattedPrettyPrinter(), { }) << std::endl; } void visit(const MetadataCollectionKey<FSPathSequence> & k) { - StringifyFormatter f; - std::cout << k.pretty_print_flat(f) << std::endl; + std::cout << k.pretty_print_value(UnformattedPrettyPrinter(), { }) << std::endl; } void visit(const MetadataCollectionKey<PackageIDSequence> & k) { - StringifyFormatter f; - std::cout << k.pretty_print_flat(f) << std::endl; + std::cout << k.pretty_print_value(UnformattedPrettyPrinter(), { }) << std::endl; } void visit(const MetadataCollectionKey<KeywordNameSet> & k) { - StringifyFormatter f; - std::cout << k.pretty_print_flat(f) << std::endl; + std::cout << k.pretty_print_value(UnformattedPrettyPrinter(), { }) << std::endl; } void visit(const MetadataCollectionKey<Set<std::string> > & k) { - StringifyFormatter f; - std::cout << k.pretty_print_flat(f) << std::endl; + std::cout << k.pretty_print_value(UnformattedPrettyPrinter(), { }) << std::endl; } void visit(const MetadataCollectionKey<Map<std::string, std::string> > & k) { - StringifyFormatter f; - std::cout << k.pretty_print_flat(f) << std::endl; + std::cout << k.pretty_print_value(UnformattedPrettyPrinter(), { }) << std::endl; } void visit(const MetadataCollectionKey<Sequence<std::string> > & k) { - StringifyFormatter f; - std::cout << k.pretty_print_flat(f) << std::endl; + std::cout << k.pretty_print_value(UnformattedPrettyPrinter(), { }) << std::endl; } void visit(const MetadataValueKey<std::shared_ptr<const PackageID> > & k) diff --git a/src/clients/paludis/info.cc b/src/clients/paludis/info.cc index 35defcfa3..c14aef63d 100644 --- a/src/clients/paludis/info.cc +++ b/src/clients/paludis/info.cc @@ -21,6 +21,7 @@ #include "command_line.hh" #include "src/output/colour.hh" #include "src/output/colour_formatter.hh" +#include "src/output/colour_pretty_printer.hh" #include <paludis/about.hh> #include <paludis/user_dep_spec.hh> #include <paludis/util/sequence.hh> @@ -33,6 +34,7 @@ #include <paludis/util/timestamp.hh> #include <paludis/util/accept_visitor.hh> #include <paludis/util/process.hh> +#include <paludis/util/make_null_shared_ptr.hh> #include <paludis/package_database.hh> #include <paludis/environment.hh> #include <paludis/package_id.hh> @@ -75,9 +77,11 @@ namespace struct InfoDisplayer { + const Environment * const env; std::string indent; - InfoDisplayer(const std::string & i) : + InfoDisplayer(const Environment * const e, const std::string & i) : + env(e), indent(i) { } @@ -88,7 +92,7 @@ namespace cout << indent << colour(cl_heading, k.human_name() + ":") << endl; std::set<std::shared_ptr<const MetadataKey>, MetadataKeyComparator > keys( k.begin_metadata(), k.end_metadata()); - InfoDisplayer i(indent + " "); + InfoDisplayer i(env, indent + " "); for (std::set<std::shared_ptr<const MetadataKey>, MetadataKeyComparator>::const_iterator e(keys.begin()), e_end(keys.end()) ; e != e_end ; ++e) if ((*e)->type() != mkt_internal) @@ -143,80 +147,80 @@ namespace void visit(const MetadataSpecTreeKey<PlainTextSpecTree> & k) { - ColourFormatter f; - cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_flat(f) << endl; + ColourPrettyPrinter printer(env, make_null_shared_ptr()); + cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_value(printer, { }) << endl; } void visit(const MetadataSpecTreeKey<RequiredUseSpecTree> & k) { - ColourFormatter f; - cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_flat(f) << endl; + ColourPrettyPrinter printer(env, make_null_shared_ptr()); + cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_value(printer, { }) << endl; } void visit(const MetadataSpecTreeKey<LicenseSpecTree> & k) { - ColourFormatter f; - cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_flat(f) << endl; + ColourPrettyPrinter printer(env, make_null_shared_ptr()); + cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_value(printer, { }) << endl; } void visit(const MetadataSpecTreeKey<FetchableURISpecTree> & k) { - ColourFormatter f; - cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_flat(f) << endl; + ColourPrettyPrinter printer(env, make_null_shared_ptr()); + cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_value(printer, { }) << endl; } void visit(const MetadataSpecTreeKey<SimpleURISpecTree> & k) { - ColourFormatter f; - cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_flat(f) << endl; + ColourPrettyPrinter printer(env, make_null_shared_ptr()); + cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_value(printer, { }) << endl; } void visit(const MetadataSpecTreeKey<DependencySpecTree> & k) { - ColourFormatter f; - cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_flat(f) << endl; + ColourPrettyPrinter printer(env, make_null_shared_ptr()); + cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_value(printer, { }) << endl; } void visit(const MetadataSpecTreeKey<ProvideSpecTree> & k) { - ColourFormatter f; - cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_flat(f) << endl; + ColourPrettyPrinter printer(env, make_null_shared_ptr()); + cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_value(printer, { }) << endl; } void visit(const MetadataCollectionKey<FSPathSequence> & k) { - ColourFormatter f; - cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_flat(f) << endl; + ColourPrettyPrinter printer(env, make_null_shared_ptr()); + cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_value(printer, { }) << endl; } void visit(const MetadataCollectionKey<PackageIDSequence> & k) { - ColourFormatter f; - cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_flat(f) << endl; + ColourPrettyPrinter printer(env, make_null_shared_ptr()); + cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_value(printer, { }) << endl; } void visit(const MetadataCollectionKey<KeywordNameSet> & k) { - ColourFormatter f; - cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_flat(f) << endl; + ColourPrettyPrinter printer(env, make_null_shared_ptr()); + cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_value(printer, { }) << endl; } void visit(const MetadataCollectionKey<Set<std::string> > & k) { - ColourFormatter f; - cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_flat(f) << endl; + ColourPrettyPrinter printer(env, make_null_shared_ptr()); + cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_value(printer, { }) << endl; } void visit(const MetadataCollectionKey<Map<std::string, std::string> > & k) { - ColourFormatter f; - cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_flat(f) << endl; + ColourPrettyPrinter printer(env, make_null_shared_ptr()); + cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_value(printer, { }) << endl; } void visit(const MetadataCollectionKey<Sequence<std::string> > & k) { - ColourFormatter f; - cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_flat(f) << endl; + ColourPrettyPrinter printer(env, make_null_shared_ptr()); + cout << std::setw(30) << (indent + k.human_name() + ":") << " " << k.pretty_print_value(printer, { }) << endl; } void visit(const MetadataValueKey<std::shared_ptr<const Choices> > & k) @@ -357,7 +361,7 @@ do_info(const std::shared_ptr<const Environment> & env) cout << colour(cl_heading, "Environment:") << endl; std::set<std::shared_ptr<const MetadataKey>, MetadataKeyComparator> keys( env->begin_metadata(), env->end_metadata()); - InfoDisplayer i(" "); + InfoDisplayer i(env.get(), " "); for (std::set<std::shared_ptr<const MetadataKey>, MetadataKeyComparator>::const_iterator k(keys.begin()), k_end(keys.end()) ; k != k_end ; ++k) if ((*k)->type() != mkt_internal) @@ -371,7 +375,7 @@ do_info(const std::shared_ptr<const Environment> & env) { cout << "Repository " << colour(cl_repository_name, r->name()) << ":" << endl; std::set<std::shared_ptr<const MetadataKey>, MetadataKeyComparator> keys(r->begin_metadata(), r->end_metadata()); - InfoDisplayer i(" "); + InfoDisplayer i(env.get(), " "); for (std::set<std::shared_ptr<const MetadataKey>, MetadataKeyComparator>::const_iterator k(keys.begin()), k_end(keys.end()) ; k != k_end ; ++k) if ((*k)->type() != mkt_internal) diff --git a/src/output/Makefile.am b/src/output/Makefile.am index 29e2b3a6d..cae2bae70 100644 --- a/src/output/Makefile.am +++ b/src/output/Makefile.am @@ -7,6 +7,7 @@ noinst_LIBRARIES = liboutput.a liboutput_a_SOURCES = \ colour.cc colour.hh \ colour_formatter.cc colour_formatter.hh \ + colour_pretty_printer.cc colour_pretty_printer.hh \ console_task.cc console_task.hh \ console_install_task.cc console_install_task.hh \ console_query_task.cc console_query_task.hh \ diff --git a/src/output/colour_pretty_printer.cc b/src/output/colour_pretty_printer.cc new file mode 100644 index 000000000..f97eb3695 --- /dev/null +++ b/src/output/colour_pretty_printer.cc @@ -0,0 +1,110 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2010 Ciaran McCreesh + * + * 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 "colour_pretty_printer.hh" +#include "colour.hh" +#include <paludis/choice.hh> +#include <paludis/name.hh> + +using namespace paludis; + +ColourPrettyPrinter::ColourPrettyPrinter(const Environment * const e, const std::shared_ptr<const PackageID> & i) : + FormattedPrettyPrinter(e, i) +{ +} + +ColourPrettyPrinter::~ColourPrettyPrinter() = default; + +const std::string +ColourPrettyPrinter::format_enabled(const std::string & s) const +{ + return colour(cl_flag_on, s); +} + +const std::string +ColourPrettyPrinter::format_disabled(const std::string & s) const +{ + return colour(cl_flag_off, s); +} + +const std::string +ColourPrettyPrinter::format_installed(const std::string & s) const +{ + return colour(cl_none, s); +} + +const std::string +ColourPrettyPrinter::format_installable(const std::string & s) const +{ + return colour(cl_installable_package_name, s); +} + +const std::string +ColourPrettyPrinter::format_masked(const std::string & s) const +{ + return colour(cl_masked, s); +} + +const std::string +ColourPrettyPrinter::format_plain(const std::string & s) const +{ + return colour(cl_none, s); +} + +const std::string +ColourPrettyPrinter::indentify(const int i) const +{ + return std::string(12 + (4 * i), ' '); +} + +const std::string +ColourPrettyPrinter::newline() const +{ + return "\n"; +} + +const std::string +ColourPrettyPrinter::prettify(const std::shared_ptr<const ChoiceValue> & v) const +{ + if (v->enabled()) + { + if (v->locked()) + { + std::string s(colour(cl_flag_on, "(" + stringify(v->unprefixed_name()))); + if (! v->parameter().empty()) + s.append("=" + v->parameter()); + return s + colour(cl_flag_on, ")"); + } + else + { + std::string s(colour(cl_flag_on, stringify(v->unprefixed_name()))); + if (! v->parameter().empty()) + s.append("=" + v->parameter()); + return s; + } + } + else + { + if (v->locked()) + return colour(cl_flag_off, "(-" + stringify(v->unprefixed_name()) + ")"); + else + return colour(cl_flag_off, "-" + stringify(v->unprefixed_name())); + } +} + diff --git a/src/output/colour_pretty_printer.hh b/src/output/colour_pretty_printer.hh new file mode 100644 index 000000000..a300b53ed --- /dev/null +++ b/src/output/colour_pretty_printer.hh @@ -0,0 +1,51 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2010 Ciaran McCreesh + * + * 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_OUTPUT_COLOUR_PRETTY_PRINTER_HH +#define PALUDIS_GUARD_SRC_OUTPUT_COLOUR_PRETTY_PRINTER_HH 1 + +#include <paludis/formatted_pretty_printer.hh> +#include <paludis/environment-fwd.hh> +#include <paludis/package_id-fwd.hh> +#include <paludis/choice-fwd.hh> + +class ColourPrettyPrinter : + public paludis::FormattedPrettyPrinter +{ + protected: + virtual const std::string format_enabled(const std::string &) const; + virtual const std::string format_disabled(const std::string &) const; + virtual const std::string format_installed(const std::string &) const; + virtual const std::string format_installable(const std::string &) const; + virtual const std::string format_masked(const std::string &) const; + virtual const std::string format_plain(const std::string &) const; + + public: + ColourPrettyPrinter(const paludis::Environment * const, const std::shared_ptr<const paludis::PackageID> &); + ~ColourPrettyPrinter(); + + virtual const std::string indentify(const int) const; + virtual const std::string newline() const; + + using FormattedPrettyPrinter::prettify; + + const std::string prettify(const std::shared_ptr<const paludis::ChoiceValue> &) const; +}; + +#endif diff --git a/src/output/console_query_task.cc b/src/output/console_query_task.cc index 1c080c940..88e091270 100644 --- a/src/output/console_query_task.cc +++ b/src/output/console_query_task.cc @@ -20,6 +20,7 @@ #include "console_query_task.hh" #include "mask_displayer.hh" #include "colour_formatter.hh" +#include "colour_pretty_printer.hh" #include <paludis/util/tokeniser.hh> #include <paludis/util/pimp-impl.hh> #include <paludis/util/set.hh> @@ -333,16 +334,16 @@ namespace { if (k.type() == type) { - ColourFormatter formatter; + ColourPrettyPrinter printer(env, id); if (task->want_raw()) { task->output_left_column(k.raw_name() + ":", in); - task->output_right_column(k.pretty_print_flat(formatter)); + task->output_right_column(k.pretty_print_value(printer, { })); } else { task->output_left_column(k.human_name() + ":", in); - task->output_right_column(k.pretty_print_flat(formatter)); + task->output_right_column(k.pretty_print_value(printer, { })); } } } @@ -351,16 +352,16 @@ namespace { if (k.type() == type) { - ColourFormatter formatter; + ColourPrettyPrinter printer(env, id); if (task->want_raw()) { task->output_left_column(k.raw_name() + ":", in); - task->output_right_column(k.pretty_print_flat(formatter)); + task->output_right_column(k.pretty_print_value(printer, { })); } else { task->output_left_column(k.human_name() + ":", in); - task->output_right_column(k.pretty_print_flat(formatter)); + task->output_right_column(k.pretty_print_value(printer, { })); } } } @@ -369,16 +370,16 @@ namespace { if (k.type() == type) { - ColourFormatter formatter; + ColourPrettyPrinter printer(env, id); if (task->want_raw()) { task->output_left_column(k.raw_name() + ":", in); - task->output_right_column(k.pretty_print_flat(formatter)); + task->output_right_column(k.pretty_print_value(printer, { })); } else { task->output_left_column(k.human_name() + ":", in); - task->output_right_column(k.pretty_print_flat(formatter)); + task->output_right_column(k.pretty_print_value(printer, { })); } } } @@ -387,16 +388,16 @@ namespace { if (k.type() == type) { - ColourFormatter formatter; + ColourPrettyPrinter printer(env, id); if (task->want_raw()) { task->output_left_column(k.raw_name() + ":", in); - task->output_right_column(k.pretty_print_flat(formatter)); + task->output_right_column(k.pretty_print_value(printer, { })); } else { task->output_left_column(k.human_name() + ":", in); - task->output_right_column(k.pretty_print_flat(formatter)); + task->output_right_column(k.pretty_print_value(printer, { })); } } } @@ -405,16 +406,16 @@ namespace { if (k.type() == type) { - ColourFormatter formatter; + ColourPrettyPrinter printer(env, id); if (task->want_raw()) { task->output_left_column(k.raw_name() + ":", in); - task->output_right_column(k.pretty_print_flat(formatter)); + task->output_right_column(k.pretty_print_value(printer, { })); } else { task->output_left_column(k.human_name() + ":", in); - task->output_right_column(k.pretty_print_flat(formatter)); + task->output_right_column(k.pretty_print_value(printer, { })); } } } @@ -423,17 +424,17 @@ namespace { if (k.type() == type) { - ColourFormatter formatter; + ColourPrettyPrinter printer(env, id); if (task->want_raw()) { task->output_left_column(k.raw_name() + ":", in); - task->output_right_column(k.pretty_print_flat(formatter)); + task->output_right_column(k.pretty_print_value(printer, { })); } else { task->output_left_column(k.human_name() + ":", in); task->output_right_column(""); - task->output_stream() << k.pretty_print(formatter); + task->output_stream() << k.pretty_print_value(printer, { ppo_multiline_allowed }); } } } @@ -442,16 +443,16 @@ namespace { if (k.type() == type) { - ColourFormatter formatter; + ColourPrettyPrinter printer(env, id); if (task->want_raw()) { task->output_left_column(k.raw_name() + ":", in); - task->output_right_column(k.pretty_print_flat(formatter)); + task->output_right_column(k.pretty_print_value(printer, { })); } else { task->output_left_column(k.human_name() + ":", in); - task->output_stream() << k.pretty_print_flat(formatter); + task->output_stream() << k.pretty_print_value(printer, { }); task->output_right_column(""); } } @@ -461,16 +462,16 @@ namespace { if (k.type() == type) { - ColourFormatter formatter; + ColourPrettyPrinter printer(env, id); if (task->want_raw()) { task->output_left_column(k.raw_name() + ":", in); - task->output_right_column(k.pretty_print_flat(formatter)); + task->output_right_column(k.pretty_print_value(printer, { })); } else { task->output_left_column(k.human_name() + ":", in); - task->output_stream() << k.pretty_print_flat(formatter); + task->output_stream() << k.pretty_print_value(printer, { }); task->output_right_column(""); } } @@ -480,11 +481,11 @@ namespace { if (k.type() == type) { - ColourFormatter formatter; + ColourPrettyPrinter printer(env, id); if (task->want_raw()) { task->output_left_column(k.raw_name() + ":", in); - task->output_right_column(k.pretty_print_flat(formatter)); + task->output_right_column(k.pretty_print_value(printer, { })); } else { @@ -494,10 +495,10 @@ namespace if (is_complex) { task->output_right_column(""); - task->output_stream() << k.pretty_print(formatter); + task->output_stream() << k.pretty_print_value(printer, { ppo_multiline_allowed }); } else - task->output_right_column(k.pretty_print_flat(formatter)); + task->output_right_column(k.pretty_print_value(printer, { })); } } } @@ -506,17 +507,17 @@ namespace { if (k.type() == type) { - ColourFormatter formatter; + ColourPrettyPrinter printer(env, id); if (task->want_raw()) { task->output_left_column(k.raw_name() + ":", in); - task->output_right_column(k.pretty_print_flat(formatter)); + task->output_right_column(k.pretty_print_value(printer, { })); } else { task->output_left_column(k.human_name() + ":", in); task->output_right_column(""); - task->output_stream() << k.pretty_print(formatter); + task->output_stream() << k.pretty_print_value(printer, { ppo_multiline_allowed }); } } } @@ -525,17 +526,17 @@ namespace { if (k.type() == type) { - ColourFormatter formatter; + ColourPrettyPrinter printer(env, id); if (task->want_raw()) { task->output_left_column(k.raw_name() + ":", in); - task->output_right_column(k.pretty_print_flat(formatter)); + task->output_right_column(k.pretty_print_value(printer, { })); } else { task->output_left_column(k.human_name() + ":", in); task->output_right_column(""); - task->output_stream() << k.pretty_print(formatter); + task->output_stream() << k.pretty_print_value(printer, { ppo_multiline_allowed }); } } } @@ -544,17 +545,17 @@ namespace { if (k.type() == type) { - ColourFormatter formatter; + ColourPrettyPrinter printer(env, id); if (task->want_raw()) { task->output_left_column(k.raw_name() + ":", in); - task->output_right_column(k.pretty_print_flat(formatter)); + task->output_right_column(k.pretty_print_value(printer, { })); } else { task->output_left_column(k.human_name() + ":", in); task->output_right_column(""); - task->output_stream() << k.pretty_print(formatter); + task->output_stream() << k.pretty_print_value(printer, { ppo_multiline_allowed }); } } } @@ -563,16 +564,16 @@ namespace { if (k.type() == type) { - ColourFormatter formatter; + ColourPrettyPrinter printer(env, id); if (task->want_raw()) { task->output_left_column(k.raw_name() + ":", in); - task->output_right_column(k.pretty_print_flat(formatter)); + task->output_right_column(k.pretty_print_value(printer, { })); } else { task->output_left_column(k.human_name() + ":", in); - task->output_right_column(k.pretty_print_flat(formatter)); + task->output_right_column(k.pretty_print_value(printer, { })); } } } @@ -632,6 +633,7 @@ namespace { if (k.type() == type) { + ColourPrettyPrinter printer(env, id); if (task->want_raw()) { task->output_left_column(k.raw_name() + ":", in); @@ -640,7 +642,7 @@ namespace else { task->output_left_column(k.human_name() + ":", in); - task->output_right_column(k.pretty_print()); + task->output_right_column(k.pretty_print_value(printer, { })); } } } @@ -649,6 +651,7 @@ namespace { if (k.type() == type) { + ColourPrettyPrinter printer(env, id); if (task->want_raw()) { task->output_left_column(k.raw_name() + ":", in); @@ -657,7 +660,7 @@ namespace else { task->output_left_column(k.human_name() + ":", in); - task->output_right_column(k.pretty_print()); + task->output_right_column(k.pretty_print_value(printer, { })); } } } @@ -748,7 +751,7 @@ namespace void visit(const MetadataValueKey<std::shared_ptr<const Choices> > & k) { - ColourFormatter formatter; + ColourPrettyPrinter printer(env, id); if (k.type() == type) { if (task->want_raw()) @@ -767,23 +770,7 @@ namespace if (! v.empty()) v.append(" "); - std::string t; - if ((*i)->enabled()) - { - if ((*i)->locked()) - t = formatter.format(**i, format::Forced()); - else - t = formatter.format(**i, format::Enabled()); - } - else - { - if ((*i)->locked()) - t = formatter.format(**i, format::Masked()); - else - t = formatter.format(**i, format::Disabled()); - } - - v.append(t); + v.append(printer.prettify(*i)); } task->output_right_column(v); } @@ -821,23 +808,7 @@ namespace if (! s.empty()) s.append(" "); - std::string t; - if ((*i)->enabled()) - { - if ((*i)->locked()) - t = formatter.format(**i, format::Forced()); - else - t = formatter.format(**i, format::Enabled()); - } - else - { - if ((*i)->locked()) - t = formatter.format(**i, format::Masked()); - else - t = formatter.format(**i, format::Disabled()); - } - - s.append(t); + s.append(printer.prettify(*i)); } } diff --git a/src/output/mask_displayer.cc b/src/output/mask_displayer.cc index cc1c1a7c2..7f6002e43 100644 --- a/src/output/mask_displayer.cc +++ b/src/output/mask_displayer.cc @@ -19,7 +19,7 @@ #include "mask_displayer.hh" #include "colour.hh" -#include "colour_formatter.hh" +#include "colour_pretty_printer.hh" #include <paludis/util/pimp-impl.hh> #include <paludis/util/join.hh> #include <paludis/util/sequence.hh> @@ -58,8 +58,16 @@ namespace { struct KeyPrettyPrinter { + const Environment * const env; + const std::shared_ptr<const PackageID> id; std::ostringstream s; + KeyPrettyPrinter(const Environment * const e, const std::shared_ptr<const PackageID> & i) : + env(e), + id(i) + { + } + void visit(const MetadataValueKey<std::shared_ptr<const PackageID> > & k) { s << *k.value(); @@ -98,7 +106,7 @@ namespace else s << " "; - KeyPrettyPrinter p; + KeyPrettyPrinter p(env, id); (*m)->accept(p); s << p.s.str(); need_comma = true; @@ -128,80 +136,80 @@ namespace void visit(const MetadataCollectionKey<Set<std::string> > & k) { - ColourFormatter formatter; - s << k.pretty_print_flat(formatter); + ColourPrettyPrinter printer(env, id); + s << k.pretty_print_value(printer, { }); } void visit(const MetadataCollectionKey<Map<std::string, std::string> > & k) { - ColourFormatter formatter; - s << k.pretty_print_flat(formatter); + ColourPrettyPrinter printer(env, id); + s << k.pretty_print_value(printer, { }); } void visit(const MetadataCollectionKey<Sequence<std::string> > & k) { - ColourFormatter formatter; - s << k.pretty_print_flat(formatter); + ColourPrettyPrinter printer(env, id); + s << k.pretty_print_value(printer, { }); } void visit(const MetadataCollectionKey<FSPathSequence> & k) { - ColourFormatter formatter; - s << k.pretty_print_flat(formatter); + ColourPrettyPrinter printer(env, id); + s << k.pretty_print_value(printer, { }); } void visit(const MetadataCollectionKey<PackageIDSequence> & k) { - ColourFormatter formatter; - s << k.pretty_print_flat(formatter); + ColourPrettyPrinter printer(env, id); + s << k.pretty_print_value(printer, { }); } void visit(const MetadataSpecTreeKey<FetchableURISpecTree> & k) { - ColourFormatter formatter; - s << k.pretty_print_flat(formatter); + ColourPrettyPrinter printer(env, id); + s << k.pretty_print_value(printer, { }); } void visit(const MetadataSpecTreeKey<SimpleURISpecTree> & k) { - ColourFormatter formatter; - s << k.pretty_print_flat(formatter); + ColourPrettyPrinter printer(env, id); + s << k.pretty_print_value(printer, { }); } void visit(const MetadataSpecTreeKey<LicenseSpecTree> & k) { - ColourFormatter formatter; - s << k.pretty_print_flat(formatter); + ColourPrettyPrinter printer(env, id); + s << k.pretty_print_value(printer, { }); } void visit(const MetadataSpecTreeKey<DependencySpecTree> & k) { - ColourFormatter formatter; - s << k.pretty_print_flat(formatter); + ColourPrettyPrinter printer(env, id); + s << k.pretty_print_value(printer, { }); } void visit(const MetadataCollectionKey<KeywordNameSet> & k) { - ColourFormatter formatter; - s << k.pretty_print_flat(formatter); + ColourPrettyPrinter printer(env, id); + s << k.pretty_print_value(printer, { }); } void visit(const MetadataSpecTreeKey<ProvideSpecTree> & k) { - ColourFormatter formatter; - s << k.pretty_print_flat(formatter); + ColourPrettyPrinter printer(env, id); + s << k.pretty_print_value(printer, { }); } void visit(const MetadataSpecTreeKey<PlainTextSpecTree> & k) { - ColourFormatter formatter; - s << k.pretty_print_flat(formatter); + ColourPrettyPrinter printer(env, id); + s << k.pretty_print_value(printer, { }); } void visit(const MetadataSpecTreeKey<RequiredUseSpecTree> & k) { - ColourFormatter formatter; - s << k.pretty_print_flat(formatter); + ColourPrettyPrinter printer(env, id); + s << k.pretty_print_value(printer, { }); } void visit(const MetadataValueKey<std::shared_ptr<const Choices> > & k) @@ -235,7 +243,7 @@ MaskDisplayer::visit(const UnacceptedMask & m) if (m.unaccepted_key()) { - KeyPrettyPrinter k; + KeyPrettyPrinter k(_imp->env, _imp->id); m.unaccepted_key()->accept(k); _imp->s << k.s.str(); } @@ -259,7 +267,7 @@ MaskDisplayer::visit(const RepositoryMask & m) if (m.mask_key()) { - KeyPrettyPrinter k; + KeyPrettyPrinter k(_imp->env, _imp->id); m.mask_key()->accept(k); _imp->s << " (" << k.s.str() << ")"; } @@ -268,7 +276,7 @@ MaskDisplayer::visit(const RepositoryMask & m) { if (m.mask_key()) { - KeyPrettyPrinter k; + KeyPrettyPrinter k(_imp->env, _imp->id); m.mask_key()->accept(k); _imp->s << k.s.str(); } |