aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-08-10 09:00:00 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-08-10 02:34:49 +0100
commit10175d72c26df4de39faacb1c62796cfc4e8fe92 (patch)
treeb1240e9375b829af9565b3d5b4a338c738daec28
parenta535e77f7963258b79e079a9caebdd1e7f26c928 (diff)
downloadpaludis-10175d72c26df4de39faacb1c62796cfc4e8fe92.tar.gz
paludis-10175d72c26df4de39faacb1c62796cfc4e8fe92.tar.xz
more purdy output
-rw-r--r--src/clients/cave/cmd_resolve_display_resolution.cc156
-rw-r--r--src/clients/cave/colour_formatter.cc47
-rw-r--r--src/clients/cave/colour_formatter.hh11
-rw-r--r--src/clients/cave/formats.cc30
-rw-r--r--src/clients/cave/formats.hh6
5 files changed, 246 insertions, 4 deletions
diff --git a/src/clients/cave/cmd_resolve_display_resolution.cc b/src/clients/cave/cmd_resolve_display_resolution.cc
index 5b1b705..530507e 100644
--- a/src/clients/cave/cmd_resolve_display_resolution.cc
+++ b/src/clients/cave/cmd_resolve_display_resolution.cc
@@ -18,20 +18,55 @@
*/
#include "cmd_resolve_display_resolution.hh"
+#include "colour_formatter.hh"
#include "formats.hh"
#include <paludis/resolver/resolver.hh>
#include <paludis/resolver/resolution.hh>
#include <paludis/resolver/decision.hh>
#include <paludis/resolver/destinations.hh>
+#include <paludis/resolver/constraint.hh>
+#include <paludis/resolver/reason.hh>
#include <paludis/util/stringify.hh>
+#include <paludis/util/simple_visitor_cast.hh>
+#include <paludis/util/join.hh>
#include <paludis/package_id.hh>
#include <paludis/version_spec.hh>
+#include <paludis/metadata_key.hh>
+#include <paludis/choice.hh>
#include <iostream>
+#include <set>
using namespace paludis;
using namespace cave;
using namespace paludis::resolver;
+namespace
+{
+ struct ReasonNameGetter
+ {
+ std::string visit(const DependencyReason & r) const
+ {
+ return stringify(r.from_id()->name());
+ }
+
+ std::string visit(const TargetReason &) const
+ {
+ return "target";
+ }
+
+ std::string visit(const SetReason & r) const
+ {
+ return r.reason_for_set()->accept_returning<std::string>(*this) +
+ " (" + stringify(r.set_name()) + ")";
+ }
+
+ std::string visit(const PresetReason &) const
+ {
+ return "";
+ }
+ };
+}
+
void
paludis::cave::display_resolution(
const std::tr1::shared_ptr<Environment> &,
@@ -50,6 +85,7 @@ paludis::cave::display_resolution(
throw InternalError(PALUDIS_HERE, "why did that happen?");
bool is_new(false), is_upgrade(false), is_downgrade(false), is_reinstall(false);
+ std::tr1::shared_ptr<const PackageID> old_id;
if ((*c)->destinations()->slash())
{
@@ -59,12 +95,15 @@ paludis::cave::display_resolution(
for (PackageIDSequence::ConstIterator x((*c)->destinations()->slash()->replacing()->begin()),
x_end((*c)->destinations()->slash()->replacing()->end()) ;
x != x_end ; ++x)
+ {
+ old_id = *x;
if ((*x)->version() == id->version())
is_reinstall = true;
else if ((*x)->version() < id->version())
is_upgrade = true;
else if ((*x)->version() > id->version())
is_downgrade = true;
+ }
/* pick the worst of what it is */
is_upgrade = is_upgrade && (! is_reinstall) && (! is_downgrade);
@@ -72,9 +111,9 @@ paludis::cave::display_resolution(
}
if (is_new)
- std::cout << "[n] " << c::bold_green() << id->canonical_form(idcf_no_version);
+ std::cout << "[n] " << c::bold_blue() << id->canonical_form(idcf_no_version);
else if (is_upgrade)
- std::cout << "[u] " << c::green() << id->canonical_form(idcf_no_version);
+ std::cout << "[u] " << c::blue() << id->canonical_form(idcf_no_version);
else if (is_reinstall)
std::cout << "[r] " << c::yellow() << id->canonical_form(idcf_no_version);
else if (is_downgrade)
@@ -98,6 +137,119 @@ paludis::cave::display_resolution(
}
std::cout << std::endl;
+
+ if (id->choices_key())
+ {
+ ColourFormatter formatter(0);
+
+ std::tr1::shared_ptr<const Choices> old_choices;
+ if (old_id && old_id->choices_key())
+ old_choices = old_id->choices_key()->value();
+
+ bool non_blank_prefix(false);
+ std::string s;
+ for (Choices::ConstIterator k(id->choices_key()->value()->begin()),
+ k_end(id->choices_key()->value()->end()) ;
+ k != k_end ; ++k)
+ {
+ if ((*k)->hidden())
+ continue;
+
+ bool shown_prefix(false);
+ for (Choice::ConstIterator i((*k)->begin()), i_end((*k)->end()) ;
+ i != i_end ; ++i)
+ {
+ if (! (*i)->explicitly_listed())
+ continue;
+
+ if (! shown_prefix)
+ {
+ if (non_blank_prefix || ! (*k)->show_with_no_prefix())
+ {
+ shown_prefix = true;
+ if (! s.empty())
+ s.append(" ");
+ s.append((*k)->raw_name() + ":");
+ }
+ }
+
+ 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());
+ }
+
+ bool changed(false), added(false);
+ if ((*k)->consider_added_or_changed())
+ {
+ if (old_choices)
+ {
+ std::tr1::shared_ptr<const ChoiceValue> old_choice(
+ old_choices->find_by_name_with_prefix((*i)->name_with_prefix()));
+ if (! old_choice)
+ added = true;
+ else if (old_choice->enabled() != (*i)->enabled())
+ changed = true;
+ }
+ else
+ added = true;
+ }
+
+ if (changed)
+ {
+ t = formatter.decorate(**i, t, format::Changed());
+ }
+ else if (added)
+ {
+ if (old_id)
+ t = formatter.decorate(**i, t, format::Added());
+ }
+
+ s.append(t);
+ }
+ }
+
+ if (s.empty())
+ break;
+
+ std::cout << " " << s << std::endl;
+ }
+
+ if (id->short_description_key())
+ std::cout << " \"" << id->short_description_key()->value() << "\"" << std::endl;
+
+ std::set<std::string> reason_names;
+ for (Constraints::ConstIterator r((*c)->constraints()->begin()),
+ r_end((*c)->constraints()->end()) ;
+ r != r_end ; ++r)
+ {
+ ReasonNameGetter g;
+ std::string s((*r)->reason()->accept_returning<std::string>(g));
+ if (! s.empty())
+ reason_names.insert(s);
+ }
+
+ if (! reason_names.empty())
+ {
+ if (reason_names.size() > 4)
+ std::cout << " Because of " << join(reason_names.begin(), next(reason_names.begin(), 3), ", ")
+ << ", " << (reason_names.size() - 3) << " more" << std::endl;
+ else
+ std::cout << " Because of " << join(reason_names.begin(), reason_names.end(), ", ") << std::endl;
+ }
}
std::cout << std::endl;
diff --git a/src/clients/cave/colour_formatter.cc b/src/clients/cave/colour_formatter.cc
index 7b987e4..1e02a62 100644
--- a/src/clients/cave/colour_formatter.cc
+++ b/src/clients/cave/colour_formatter.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2008 Ciaran McCreesh
+ * Copyright (c) 2008, 2009 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
@@ -22,6 +22,7 @@
#include "format_general.hh"
#include <paludis/util/stringify.hh>
#include <paludis/name.hh>
+#include <paludis/choice.hh>
using namespace paludis;
using namespace cave;
@@ -32,6 +33,50 @@ ColourFormatter::ColourFormatter(const int initial_indent) :
}
std::string
+ColourFormatter::format(const paludis::ChoiceValue & s, const paludis::format::Plain &) const
+{
+ return format_general_s(f::colour_formatter_choice_value_plain(), stringify(s.name_with_prefix()));
+}
+
+std::string
+ColourFormatter::format(const paludis::ChoiceValue & s, const paludis::format::Enabled &) const
+{
+ return format_general_kv(f::colour_formatter_choice_value_enabled(),
+ stringify(s.unprefixed_name()), s.parameter().empty() ? "" : "=" + s.parameter());
+}
+
+std::string
+ColourFormatter::format(const paludis::ChoiceValue & s, const paludis::format::Disabled &) const
+{
+ return format_general_s(f::colour_formatter_choice_value_disabled(), stringify(s.unprefixed_name()));
+}
+
+std::string
+ColourFormatter::format(const paludis::ChoiceValue & s, const paludis::format::Forced &) const
+{
+ return format_general_kv(f::colour_formatter_choice_value_forced(),
+ stringify(s.unprefixed_name()), s.parameter().empty() ? "" : "=" + s.parameter());
+}
+
+std::string
+ColourFormatter::format(const paludis::ChoiceValue & s, const paludis::format::Masked &) const
+{
+ return format_general_s(f::colour_formatter_choice_value_masked(), stringify(s.unprefixed_name()));
+}
+
+std::string
+ColourFormatter::decorate(const paludis::ChoiceValue &, const std::string & f, const paludis::format::Added &) const
+{
+ return f + "+";
+}
+
+std::string
+ColourFormatter::decorate(const paludis::ChoiceValue &, const std::string & f, const paludis::format::Changed &) const
+{
+ return f + "*";
+}
+
+std::string
ColourFormatter::format(const KeywordName & s, const format::Plain &) const
{
return format_general_s(f::colour_formatter_keyword_name_plain(), stringify(s));
diff --git a/src/clients/cave/colour_formatter.hh b/src/clients/cave/colour_formatter.hh
index e4d638e..6c8ff90 100644
--- a/src/clients/cave/colour_formatter.hh
+++ b/src/clients/cave/colour_formatter.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2008 Ciaran McCreesh
+ * Copyright (c) 2008, 2009 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
@@ -42,6 +42,7 @@ namespace paludis
public CanFormat<BlockDepSpec>,
public CanFormat<NamedSetDepSpec>,
public CanFormat<PlainTextLabelDepSpec>,
+ public CanFormat<ChoiceValue>,
public CanSpace
{
private:
@@ -50,6 +51,14 @@ namespace paludis
public:
ColourFormatter(const int initial_indent);
+ std::string format(const paludis::ChoiceValue &, const paludis::format::Plain &) const;
+ std::string format(const paludis::ChoiceValue &, const paludis::format::Enabled &) const;
+ std::string format(const paludis::ChoiceValue &, const paludis::format::Disabled &) const;
+ std::string format(const paludis::ChoiceValue &, const paludis::format::Forced &) const;
+ std::string format(const paludis::ChoiceValue &, const paludis::format::Masked &) const;
+ std::string decorate(const paludis::ChoiceValue &, const std::string &, const paludis::format::Added &) const;
+ std::string decorate(const paludis::ChoiceValue &, const std::string &, const paludis::format::Changed &) const;
+
std::string format(const KeywordName &, const format::Plain &) const;
std::string format(const KeywordName &, const format::Accepted &) const;
std::string format(const KeywordName &, const format::Unaccepted &) const;
diff --git a/src/clients/cave/formats.cc b/src/clients/cave/formats.cc
index 8409b85..6dcdb5a 100644
--- a/src/clients/cave/formats.cc
+++ b/src/clients/cave/formats.cc
@@ -275,6 +275,36 @@ paludis::cave::f::colour_formatter_license_dep_spec_unaccepted()
}
const std::string
+paludis::cave::f::colour_formatter_choice_value_plain()
+{
+ return "%s";
+}
+
+const std::string
+paludis::cave::f::colour_formatter_choice_value_enabled()
+{
+ return c::green() + "%k" + c::normal() + "%v";
+}
+
+const std::string
+paludis::cave::f::colour_formatter_choice_value_disabled()
+{
+ return c::red() + "-%s" + c::normal();
+}
+
+const std::string
+paludis::cave::f::colour_formatter_choice_value_forced()
+{
+ return c::green() + "(%k%v)" + c::normal();
+}
+
+const std::string
+paludis::cave::f::colour_formatter_choice_value_masked()
+{
+ return c::red() + "(-%s)" + c::normal();
+}
+
+const std::string
paludis::cave::f::colour_formatter_conditional_dep_spec_plain()
{
return "%s";
diff --git a/src/clients/cave/formats.hh b/src/clients/cave/formats.hh
index 281b941..23d59ce 100644
--- a/src/clients/cave/formats.hh
+++ b/src/clients/cave/formats.hh
@@ -85,6 +85,12 @@ namespace paludis
const std::string colour_formatter_keyword_name_accepted();
const std::string colour_formatter_keyword_name_unaccepted();
+ const std::string colour_formatter_choice_value_plain();
+ const std::string colour_formatter_choice_value_enabled();
+ const std::string colour_formatter_choice_value_disabled();
+ const std::string colour_formatter_choice_value_forced();
+ const std::string colour_formatter_choice_value_masked();
+
const std::string colour_formatter_string_plain();
const std::string colour_formatter_package_id_plain();