aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-17 12:40:50 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-17 12:40:50 +0100
commit930c799a1cc6bb6c33ce1b5fe029f2c4848d69b0 (patch)
treea81a933961b4fe9ea2fb4669cec5ff8ce7e86157
parentb16723cdaaac3e6e8771c52f356c6bc0781e2ae7 (diff)
downloadpaludis-930c799a1cc6bb6c33ce1b5fe029f2c4848d69b0.tar.gz
paludis-930c799a1cc6bb6c33ce1b5fe029f2c4848d69b0.tar.xz
fmt show contents
-rw-r--r--src/clients/cave/cmd_print_formats.cc18
-rw-r--r--src/clients/cave/cmd_show-fmt.hh13
-rw-r--r--src/clients/cave/cmd_show.cc13
-rw-r--r--src/clients/cave/format_user_config.hh34
4 files changed, 70 insertions, 8 deletions
diff --git a/src/clients/cave/cmd_print_formats.cc b/src/clients/cave/cmd_print_formats.cc
index 8413a11..4583323 100644
--- a/src/clients/cave/cmd_print_formats.cc
+++ b/src/clients/cave/cmd_print_formats.cc
@@ -71,6 +71,24 @@ namespace
return "%" + std::string(1, c_);
}
+ template <char c_>
+ std::string param_if()
+ {
+ return "%{if " + std::string(1, c_) + "}";
+ }
+
+ template <char c_>
+ std::string param_else()
+ {
+ return "%{else}";
+ }
+
+ template <char c_>
+ std::string param_endif()
+ {
+ return "%{endif}";
+ }
+
struct Storer
{
std::string user_key;
diff --git a/src/clients/cave/cmd_show-fmt.hh b/src/clients/cave/cmd_show-fmt.hh
index 67ab44a..edb9820 100644
--- a/src/clients/cave/cmd_show-fmt.hh
+++ b/src/clients/cave/cmd_show-fmt.hh
@@ -30,3 +30,16 @@ const auto fs_set_spec_installable = make_format_string_fetcher("show/set_spec_i
const auto fs_set_spec_unavailable = make_format_string_fetcher("show/set_spec_unavailable", 1)
<< param<'i'>() << param<'i'>() << param<'i'>() << param<'i'>() << c::bold_red() << param<'s'>() << c::normal() << "\\n";
+const auto fs_contents_file = make_format_string_fetcher("show/contents_file", 1)
+ << param_if<'b'>() << "%{column 30}" << param_endif<'b'>() << param<'r'>() << param_if<'b'>() << "\\n" << param_else<'b'>() << " " << param_endif<'b'>();
+
+const auto fs_contents_other = make_format_string_fetcher("show/contents_other", 1)
+ << param_if<'b'>() << "%{column 30}" << param_endif<'b'>() << param<'r'>() << param_if<'b'>() << "\\n" << param_else<'b'>() << " " << param_endif<'b'>();
+
+const auto fs_contents_dir = make_format_string_fetcher("show/contents_dir", 1)
+ << param_if<'b'>() << "%{column 30}" << param_endif<'b'>() << param<'r'>() << param_if<'b'>() << "\\n" << param_else<'b'>() << " " << param_endif<'b'>();
+
+const auto fs_contents_sym = make_format_string_fetcher("show/contents_sym", 1)
+ << param_if<'b'>() << "%{column 30}" << param_endif<'b'>() << param<'r'>() << " -> " << param<'v'>()
+ << param_if<'b'>() << "\\n" << param_else<'b'>() << " " << param_endif<'b'>();
+
diff --git a/src/clients/cave/cmd_show.cc b/src/clients/cave/cmd_show.cc
index 9c37c2f..54cbeae 100644
--- a/src/clients/cave/cmd_show.cc
+++ b/src/clients/cave/cmd_show.cc
@@ -254,26 +254,23 @@ namespace
void visit(const ContentsFileEntry & e)
{
- s << format_general_rhvib(f::show_contents_file(), stringify(e.location_key()->value()), e.location_key()->value().basename(),
- "", indent, indent);
+ s << fuc(fs_contents_file(), fv<'r'>(stringify(e.location_key()->value())), fv<'b'>(indent ? "true" : ""));
}
void visit(const ContentsDirEntry & e)
{
- s << format_general_rhvib(f::show_contents_dir(), stringify(e.location_key()->value()), e.location_key()->value().basename(),
- "", indent, indent);
+ s << fuc(fs_contents_dir(), fv<'r'>(stringify(e.location_key()->value())), fv<'b'>(indent ? "true" : ""));
}
void visit(const ContentsSymEntry & e)
{
- s << format_general_rhvib(f::show_contents_sym(), stringify(e.location_key()->value()), e.location_key()->value().basename(),
- e.target_key()->value(), indent, indent);
+ s << fuc(fs_contents_sym(), fv<'r'>(stringify(e.location_key()->value())), fv<'b'>(indent ? "true" : ""),
+ fv<'v'>(e.target_key()->value()));
}
void visit(const ContentsOtherEntry & e)
{
- s << format_general_rhvib(f::show_contents_other(), stringify(e.location_key()->value()), e.location_key()->value().basename(),
- "", indent, indent);
+ s << fuc(fs_contents_other(), fv<'r'>(stringify(e.location_key()->value())), fv<'b'>(indent ? "true" : ""));
}
};
diff --git a/src/clients/cave/format_user_config.hh b/src/clients/cave/format_user_config.hh
index 9faaed8..bf2bf93 100644
--- a/src/clients/cave/format_user_config.hh
+++ b/src/clients/cave/format_user_config.hh
@@ -315,6 +315,30 @@ namespace paludis
return FormatParam<c_>();
}
+ template <char c_>
+ struct FormatParamIf
+ {
+ std::string text;
+ };
+
+ template <char c_>
+ FormatParamIf<c_> param_if()
+ {
+ return FormatParamIf<c_>{"%{if " + std::string(1, c_) + "}"};
+ }
+
+ template <char c_>
+ FormatParamIf<c_> param_else()
+ {
+ return FormatParamIf<c_>{"%{else}"};
+ }
+
+ template <char c_>
+ FormatParamIf<c_> param_endif()
+ {
+ return FormatParamIf<c_>{"%{endif}"};
+ }
+
template <char... cs_>
MakeFormatStringFetcher<cs_...> operator<< (MakeFormatStringFetcher<cs_...> && f, const std::string & s)
{
@@ -333,6 +357,16 @@ namespace paludis
result.text.append(1, c_);
return result;
}
+
+ template <char c_, char... cs_>
+ typename MakeDeduplicatedMakeFormatStringFetcher<c_, cs_...>::Type
+ operator<< (MakeFormatStringFetcher<cs_...> && f, const FormatParamIf<c_> & c)
+ {
+ typename MakeDeduplicatedMakeFormatStringFetcher<c_, cs_...>::Type result{
+ std::move(f.user_key), f.user_key_version, std::move(f.text)};
+ result.text.append(c.text);
+ return result;
+ }
}
extern template class Singleton<cave::FormatUserConfigFile>;