fmt: more update to use new fmt-based APIs
This commit is contained in:
@ -112,14 +112,10 @@ output_plain(ItemType itype, OptContact contact, const Options& opts)
|
||||
const auto col2{opts.nocolor ? "" : MU_COLOR_GREEN};
|
||||
const auto coldef{opts.nocolor ? "" : MU_COLOR_DEFAULT};
|
||||
|
||||
print_encoded("%s%s%s%s%s%s%s\n",
|
||||
col1,
|
||||
contact->name.c_str(),
|
||||
coldef,
|
||||
contact->name.empty() ? "" : " ",
|
||||
col2,
|
||||
contact->email.c_str(),
|
||||
coldef);
|
||||
mu_print_encoded("{}{}{}{}{}{}{}\n",
|
||||
col1, contact->name, coldef,
|
||||
contact->name.empty() ? "" : " ",
|
||||
col2, contact->email, coldef);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -129,8 +125,8 @@ output_mutt_alias(ItemType itype, OptContact contact, const Options& opts)
|
||||
return;
|
||||
|
||||
const auto nick{guess_nick(*contact)};
|
||||
print_encoded("alias %s %s <%s>\n", nick.c_str(),
|
||||
contact->name.c_str(), contact->email.c_str());
|
||||
mu_print_encoded("alias {} {} <{}>\n", nick, contact->name, contact->email);
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
@ -139,12 +135,8 @@ output_mutt_address_book(ItemType itype, OptContact contact, const Options& opts
|
||||
if (itype == ItemType::Header)
|
||||
mu_print ("Matching addresses in the mu database:\n");
|
||||
|
||||
if (!contact)
|
||||
return;
|
||||
|
||||
print_encoded("%s\t%s\t\n",
|
||||
contact->email.c_str(),
|
||||
contact->name.c_str());
|
||||
if (contact)
|
||||
mu_print_encoded("{}\t{}\t\n", contact->email, contact->name);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -155,10 +147,8 @@ output_wanderlust(ItemType itype, OptContact contact, const Options& opts)
|
||||
|
||||
auto nick=guess_nick(*contact);
|
||||
|
||||
print_encoded("%s \"%s\" \"%s\"\n",
|
||||
contact->email.c_str(),
|
||||
nick.c_str(),
|
||||
contact->name.c_str());
|
||||
mu_print_encoded("{} \"{}\" \"{}\"\n", contact->email, nick, contact->name);
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
@ -167,9 +157,8 @@ output_org_contact(ItemType itype, OptContact contact, const Options& opts)
|
||||
if (!contact || contact->name.empty())
|
||||
return;
|
||||
|
||||
print_encoded("* %s\n:PROPERTIES:\n:EMAIL: %s\n:END:\n\n",
|
||||
contact->name.c_str(),
|
||||
contact->email.c_str());
|
||||
mu_print_encoded("* {}\n:PROPERTIES:\n:EMAIL: {}\n:END:\n\n",
|
||||
contact->name, contact->email);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -196,9 +185,9 @@ output_csv(ItemType itype, OptContact contact, const Options& opts)
|
||||
if (!contact)
|
||||
return;
|
||||
|
||||
print_encoded("%s,%s\n",
|
||||
contact->name.empty() ? "" : Mu::quote(contact->name).c_str(),
|
||||
Mu::quote(contact->email).c_str());
|
||||
mu_print_encoded("{},{}\n",
|
||||
contact->name.empty() ? "" : Mu::quote(contact->name),
|
||||
Mu::quote(contact->email));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -211,22 +200,22 @@ output_json(ItemType itype, OptContact contact, const Options& opts)
|
||||
mu_println (" {{");
|
||||
|
||||
const std::string name = contact->name.empty() ? "null" : Mu::quote(contact->name);
|
||||
print_encoded(
|
||||
" \"email\" : \"%s\",\n"
|
||||
" \"name\" : %s,\n"
|
||||
" \"display\" : %s,\n"
|
||||
" \"last-seen\" : %" PRId64 ",\n"
|
||||
" \"last-seen-iso\" : \"%s\",\n"
|
||||
" \"personal\" : %s,\n"
|
||||
" \"frequency\" : %zu\n",
|
||||
contact->email.c_str(),
|
||||
name.c_str(),
|
||||
Mu::quote(contact->display_name()).c_str(),
|
||||
mu_print_encoded(
|
||||
" \"email\" : \"{}\",\n"
|
||||
" \"name\" : {},\n"
|
||||
" \"display\" : {},\n"
|
||||
" \"last-seen\" : {},\n"
|
||||
" \"last-seen-iso\" : \"{}\",\n"
|
||||
" \"personal\" : {},\n"
|
||||
" \"frequency\" : {}\n",
|
||||
contact->email,
|
||||
name,
|
||||
Mu::quote(contact->display_name()),
|
||||
contact->message_date,
|
||||
time_to_string("%FT%TZ", contact->message_date, true/*utc*/).c_str(),
|
||||
time_to_string("%FT%TZ", contact->message_date, true/*utc*/),
|
||||
contact->personal ? "true" : "false",
|
||||
contact->frequency);
|
||||
mu_print (" }}");
|
||||
mu_print(" }}");
|
||||
}
|
||||
|
||||
if (itype == ItemType::Footer)
|
||||
|
||||
@ -117,8 +117,7 @@ show_part(const MessagePart& part, size_t index, bool color)
|
||||
|
||||
/* /\* disposition *\/ */
|
||||
color_maybe(MU_COLOR_MAGENTA);
|
||||
print_encoded(" [%s]", part.is_attachment() ?
|
||||
"attachment" : "inline");
|
||||
mu_print_encoded(" [{}]", part.is_attachment() ? "attachment" : "inline");
|
||||
/* size */
|
||||
if (part.size() > 0) {
|
||||
color_maybe(MU_COLOR_CYAN);
|
||||
|
||||
@ -98,13 +98,6 @@ topic_fields(const Options& opts)
|
||||
fields.add_row({"field-name", "alias", "short", "search",
|
||||
"value", "sexp", "example query", "description"});
|
||||
|
||||
auto disp= [&](std::string_view sv)->std::string {
|
||||
if (sv.empty())
|
||||
return "";
|
||||
else
|
||||
return format("%.*s", STR_V(sv));
|
||||
};
|
||||
|
||||
auto searchable=[&](const Field& field)->std::string {
|
||||
if (field.is_boolean_term())
|
||||
return "boolean";
|
||||
@ -130,8 +123,8 @@ topic_fields(const Options& opts)
|
||||
searchable(field),
|
||||
field.is_value() ? "yes" : "no",
|
||||
field.include_in_sexp() ? "yes" : "no",
|
||||
disp(field.example_query),
|
||||
disp(field.description)});
|
||||
field.example_query,
|
||||
field.description});
|
||||
++row;
|
||||
});
|
||||
|
||||
|
||||
@ -106,7 +106,7 @@ body_or_summary(const Message& message, const Options& opts)
|
||||
const auto summ{summarize(body->c_str(), *opts.view.summary_len)};
|
||||
print_field("Summary", summ, color);
|
||||
} else {
|
||||
print_encoded("%s", body->c_str());
|
||||
mu_print_encoded("{}", *body);
|
||||
if (!g_str_has_suffix(body->c_str(), "\n"))
|
||||
mu_println("");
|
||||
}
|
||||
|
||||
@ -57,6 +57,53 @@ using namespace Mu;
|
||||
* helpers
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* array of associated pair elements -- like an alist
|
||||
* but based on std::array and thus can be constexpr
|
||||
*/
|
||||
template<typename T1, typename T2, std::size_t N>
|
||||
using AssocPairs = std::array<std::pair<T1, T2>, N>;
|
||||
|
||||
|
||||
/**
|
||||
* Get the first value of the pair where the second element is @param s.
|
||||
*
|
||||
* @param p AssocPairs
|
||||
* @param s some second pair value
|
||||
*
|
||||
* @return the matching first pair value, or Nothing if not found.
|
||||
*/
|
||||
template<typename P>
|
||||
constexpr Option<typename P::value_type::first_type>
|
||||
to_first(const P& p, typename P::value_type::second_type s)
|
||||
{
|
||||
for (const auto& item: p)
|
||||
if (item.second == s)
|
||||
return item.first;
|
||||
return Nothing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the second value of the pair where the first element is @param f.
|
||||
*
|
||||
* @param p AssocPairs
|
||||
* @param f some first pair value
|
||||
*
|
||||
* @return the matching second pair value, or Nothing if not found.
|
||||
*/
|
||||
template<typename P>
|
||||
constexpr Option<typename P::value_type::second_type>
|
||||
to_second(const P& p, typename P::value_type::first_type f)
|
||||
{
|
||||
for (const auto& item: p)
|
||||
if (item.first == f)
|
||||
return item.second;
|
||||
return Nothing;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Options-specific array-bases type that maps some enum to a <name, description> pair
|
||||
*/
|
||||
@ -316,7 +363,7 @@ sub_find(CLI::App& sub, Options& opts)
|
||||
smap.emplace(std::string(1, field.shortcut), field.id);
|
||||
if (!sopts.empty())
|
||||
sopts += ", ";
|
||||
sopts += format("%.*s|%c", STR_V(field.name), field.shortcut);
|
||||
sopts += mu_format("{}|{}", field.name, field.shortcut);
|
||||
}
|
||||
});
|
||||
sub.add_option("--sortfield,-s", opts.find.sortfield,
|
||||
@ -326,7 +373,8 @@ sub_find(CLI::App& sub, Options& opts)
|
||||
->default_val(Field::Id::Date)
|
||||
->transform(CLI::CheckedTransformer(smap));
|
||||
|
||||
sub.add_flag("--reverse,-z", opts.find.reverse, "Sort in descending order");
|
||||
sub.add_flag("--reverse,-z", opts.find.reverse,
|
||||
"Sort in descending order");
|
||||
|
||||
sub.add_option("--bookmark,-b", opts.find.bookmark,
|
||||
"Use bookmarked query")
|
||||
@ -347,7 +395,8 @@ sub_find(CLI::App& sub, Options& opts)
|
||||
"Command to execute on message file")
|
||||
->type_name("<command>");
|
||||
|
||||
sub.add_option("query", opts.find.query, "Search query pattern(s)")
|
||||
sub.add_option("query", opts.find.query,
|
||||
"Search query pattern(s)")
|
||||
->type_name("<query>");
|
||||
}
|
||||
|
||||
@ -792,12 +841,45 @@ test_ids()
|
||||
|
||||
#ifdef BUILD_TESTS
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
enum struct TestEnum { A, B, C };
|
||||
constexpr AssocPairs<TestEnum, std::string_view, 3>
|
||||
test_epairs = {{
|
||||
{TestEnum::A, "a"},
|
||||
{TestEnum::B, "b"},
|
||||
{TestEnum::C, "c"},
|
||||
}};
|
||||
|
||||
static constexpr Option<std::string_view>
|
||||
to_name(TestEnum te)
|
||||
{
|
||||
return to_second(test_epairs, te);
|
||||
}
|
||||
|
||||
static constexpr Option<TestEnum>
|
||||
to_type(std::string_view name)
|
||||
{
|
||||
return to_first(test_epairs, name);
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
test_enum_pairs(void)
|
||||
{
|
||||
assert_equal(to_name(TestEnum::A).value(), "a");
|
||||
g_assert_true(to_type("c").value() == TestEnum::C);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
mu_test_init(&argc, &argv);
|
||||
|
||||
g_test_add_func("/options/ids", test_ids);
|
||||
g_test_add_func("/option/enum-pairs", test_enum_pairs);
|
||||
|
||||
return g_test_run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user