aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-17 19:34:27 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-17 19:34:27 +0100
commitcb75f47b4cb9e01cffe10037dfbd3e5955d882d3 (patch)
tree90514b263b18b7872e99e329d4adf9a9b5132b18
parentd38a317c4ea3bb6e577802ca3a8e70500252f549 (diff)
downloadpaludis-cb75f47b4cb9e01cffe10037dfbd3e5955d882d3.tar.gz
paludis-cb75f47b4cb9e01cffe10037dfbd3e5955d882d3.tar.xz
Defer config file loading
-rw-r--r--src/clients/cave/cmd_display_resolution.cc16
-rw-r--r--src/clients/cave/cmd_info.cc9
-rw-r--r--src/clients/cave/colours.cc62
-rw-r--r--src/clients/cave/colours.hh43
-rw-r--r--src/clients/cave/format_string.cc9
-rw-r--r--src/clients/cave/format_user_config.hh9
6 files changed, 91 insertions, 57 deletions
diff --git a/src/clients/cave/cmd_display_resolution.cc b/src/clients/cave/cmd_display_resolution.cc
index ba9c195..5b2a91c 100644
--- a/src/clients/cave/cmd_display_resolution.cc
+++ b/src/clients/cave/cmd_display_resolution.cc
@@ -976,7 +976,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(), " "});
+ (*m)->accept(MaskedByVisitor{c::bold_red().colour_string(), " "});
}
struct Totals
@@ -1092,7 +1092,7 @@ namespace
x = "-" + x;
if (decision.origin_id()->masked() || decision.if_changed_choices())
- c = c::red();
+ c = c::red().colour_string();
else
do
{
@@ -1100,19 +1100,19 @@ namespace
{
case dt_install_to_slash:
if (decision.if_via_new_binary_in())
- c = c::yellow();
+ c = c::yellow().colour_string();
if (maybe_totals)
++maybe_totals->installs_ct_count.insert(std::make_pair(decision.change_type(), 0)).first->second;
continue;
case dt_install_to_chroot:
- c = c::blue();
+ c = c::blue().colour_string();
if (maybe_totals)
++maybe_totals->installs_ct_count.insert(std::make_pair(decision.change_type(), 0)).first->second;
continue;
case dt_create_binary:
- c = c::green();
+ c = c::green().colour_string();
if (maybe_totals)
++maybe_totals->binary_installs_count;
continue;
@@ -1297,13 +1297,13 @@ namespace
{
std::string colour;
if (! u->unmet_constraints()->empty())
- colour = c::red();
+ colour = c::red().colour_string();
else if (u->package_id()->masked())
{
if (not_strongly_masked(u->package_id()))
- colour = c::bold_red();
+ colour = c::bold_red().colour_string();
else
- colour = c::red();
+ colour = c::red().colour_string();
}
cout << fuc(fs_unable_unsuitable_id(), fv<'c'>(colour), fv<'i'>(stringify(*u->package_id())));
diff --git a/src/clients/cave/cmd_info.cc b/src/clients/cave/cmd_info.cc
index 745196b..da449eb 100644
--- a/src/clients/cave/cmd_info.cc
+++ b/src/clients/cave/cmd_info.cc
@@ -409,9 +409,12 @@ InfoCommand::run(
if (cmdline.begin_parameters() == cmdline.end_parameters())
{
- cout << c::bold_red() << "No packages were specified on the command line, so detailed information is not" << c::normal() << endl;
- cout << c::bold_red() << "available. If you are using this information for a bug report, you should pass " << c::normal() << endl;
- cout << c::bold_red() << "the relevant package names as parameters." << c::normal() << endl;
+ cout << c::bold_red().colour_string() <<
+ "No packages were specified on the command line, so detailed information is not" << c::normal().colour_string() << endl;
+ cout << c::bold_red().colour_string() <<
+ "available. If you are using this information for a bug report, you should pass " << c::normal().colour_string() << endl;
+ cout << c::bold_red().colour_string() <<
+ "the relevant package names as parameters." << c::normal().colour_string() << endl;
cout << endl;
}
else
diff --git a/src/clients/cave/colours.cc b/src/clients/cave/colours.cc
index 87b61d9..61aef05 100644
--- a/src/clients/cave/colours.cc
+++ b/src/clients/cave/colours.cc
@@ -24,67 +24,67 @@
using namespace paludis;
using namespace cave;
-const std::string
+const Colour
paludis::cave::c::bold_blue()
{
- return FormatUserConfigFile::get_instance()->fetch("bold_blue", 0, "");
+ return Colour{"bold_blue"};
}
-const std::string
+const Colour
paludis::cave::c::blue()
{
- return FormatUserConfigFile::get_instance()->fetch("blue", 0, "");
+ return Colour{"blue"};
}
-const std::string
+const Colour
paludis::cave::c::bold_green()
{
- return FormatUserConfigFile::get_instance()->fetch("bold_green", 0, "");
+ return Colour{"bold_green"};
}
-const std::string
+const Colour
paludis::cave::c::green()
{
- return FormatUserConfigFile::get_instance()->fetch("green", 0, "");
+ return Colour{"green"};
}
-const std::string
+const Colour
paludis::cave::c::red()
{
- return FormatUserConfigFile::get_instance()->fetch("red", 0, "");
+ return Colour{"red"};
}
-const std::string
+const Colour
paludis::cave::c::bold_red()
{
- return FormatUserConfigFile::get_instance()->fetch("bold_red", 0, "");
+ return Colour{"bold_red"};
}
-const std::string
+const Colour
paludis::cave::c::yellow()
{
- return FormatUserConfigFile::get_instance()->fetch("yellow", 0, "");
+ return Colour{"yellow"};
}
-const std::string
+const Colour
paludis::cave::c::bold_yellow()
{
- return FormatUserConfigFile::get_instance()->fetch("bold_yellow", 0, "");
+ return Colour{"bold_yellow"};
}
-const std::string
+const Colour
paludis::cave::c::pink()
{
- return FormatUserConfigFile::get_instance()->fetch("pink", 0, "");
+ return Colour{"pink"};
}
-const std::string
+const Colour
paludis::cave::c::bold_pink()
{
- return FormatUserConfigFile::get_instance()->fetch("bold_pink", 0, "");
+ return Colour{"bold_pink"};
}
-const std::string
+const Colour
paludis::cave::c::bold_blue_or_pink()
{
#if PALUDIS_COLOUR_PINK
@@ -94,7 +94,7 @@ paludis::cave::c::bold_blue_or_pink()
#endif
}
-const std::string
+const Colour
paludis::cave::c::blue_or_pink()
{
#if PALUDIS_COLOUR_PINK
@@ -104,7 +104,7 @@ paludis::cave::c::blue_or_pink()
#endif
}
-const std::string
+const Colour
paludis::cave::c::bold_green_or_pink()
{
#if PALUDIS_COLOUR_PINK
@@ -114,7 +114,7 @@ paludis::cave::c::bold_green_or_pink()
#endif
}
-const std::string
+const Colour
paludis::cave::c::green_or_pink()
{
#if PALUDIS_COLOUR_PINK
@@ -124,15 +124,21 @@ paludis::cave::c::green_or_pink()
#endif
}
-const std::string
+const Colour
paludis::cave::c::normal()
{
- return FormatUserConfigFile::get_instance()->fetch("normal", 0, "");
+ return Colour{"normal"};
}
-const std::string
+const Colour
paludis::cave::c::bold_normal()
{
- return FormatUserConfigFile::get_instance()->fetch("bold_normal", 0, "");
+ return Colour{"bold_normal"};
+}
+
+std::string
+Colour::colour_string() const
+{
+ return FormatUserConfigFile::get_instance()->fetch(name, 0, "");
}
diff --git a/src/clients/cave/colours.hh b/src/clients/cave/colours.hh
index 28b7b48..f40e508 100644
--- a/src/clients/cave/colours.hh
+++ b/src/clients/cave/colours.hh
@@ -26,26 +26,33 @@ namespace paludis
{
namespace cave
{
+ struct Colour
+ {
+ std::string name;
+
+ std::string colour_string() const;
+ };
+
namespace c
{
- const std::string bold_blue();
- const std::string blue();
- const std::string bold_green();
- const std::string green();
- const std::string bold_red();
- const std::string red();
- const std::string bold_yellow();
- const std::string yellow();
- const std::string bold_pink();
- const std::string pink();
-
- const std::string bold_blue_or_pink();
- const std::string blue_or_pink();
- const std::string bold_green_or_pink();
- const std::string green_or_pink();
-
- const std::string bold_normal();
- const std::string normal();
+ const Colour bold_blue();
+ const Colour blue();
+ const Colour bold_green();
+ const Colour green();
+ const Colour bold_red();
+ const Colour red();
+ const Colour bold_yellow();
+ const Colour yellow();
+ const Colour bold_pink();
+ const Colour pink();
+
+ const Colour bold_blue_or_pink();
+ const Colour blue_or_pink();
+ const Colour bold_green_or_pink();
+ const Colour green_or_pink();
+
+ const Colour bold_normal();
+ const Colour normal();
}
}
}
diff --git a/src/clients/cave/format_string.cc b/src/clients/cave/format_string.cc
index 58b3f51..25e3a73 100644
--- a/src/clients/cave/format_string.cc
+++ b/src/clients/cave/format_string.cc
@@ -18,6 +18,7 @@
*/
#include "format_string.hh"
+#include "format_user_config.hh"
#include <paludis/util/map-impl.hh>
#include <paludis/util/stringify.hh>
#include <paludis/util/tokeniser.hh>
@@ -144,6 +145,14 @@ paludis::cave::format_string(
throw FormatStringError(f, "{if} parameter '" + tokens.at(1) + "' not a variable");
condition_stack.push_front(! m->find(tokens.at(1).at(0))->second.empty());
}
+ else if ("colour" == tokens.at(0))
+ {
+ if (tokens.size() != 2)
+ throw FormatStringError(f, "{colour} takes one parameter");
+
+ if (*condition_stack.begin())
+ result.append(FormatUserConfigFile::get_instance()->fetch(tokens.at(1), 0, ""));
+ }
else
throw FormatStringError(f, "unknown command '" + tokens.at(0) + "' inside {}");
diff --git a/src/clients/cave/format_user_config.hh b/src/clients/cave/format_user_config.hh
index dc682cf..86fcac5 100644
--- a/src/clients/cave/format_user_config.hh
+++ b/src/clients/cave/format_user_config.hh
@@ -27,6 +27,7 @@
#include <memory>
#include <utility>
#include "format_string.hh"
+#include "colours.hh"
namespace paludis
{
@@ -349,6 +350,14 @@ namespace paludis
return result;
}
+ template <char... cs_>
+ MakeFormatStringFetcher<cs_...> operator<< (MakeFormatStringFetcher<cs_...> && f, const Colour & c)
+ {
+ MakeFormatStringFetcher<cs_...> result{std::move(f.user_key), f.user_key_version, std::move(f.text)};
+ result.text.append("%{colour " + c.name + "}");
+ return result;
+ }
+
template <char c_, char... cs_>
typename MakeDeduplicatedMakeFormatStringFetcher<c_, cs_...>::Type
operator<< (MakeFormatStringFetcher<cs_...> && f, const FormatParam<c_> &)