Skip to content

Commit

Permalink
mu-info: improve docs; better colors
Browse files Browse the repository at this point in the history
  • Loading branch information
djcb committed Jul 6, 2023
1 parent c59d493 commit d96e9cc
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 58 deletions.
6 changes: 3 additions & 3 deletions man/mu-find.1.org
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ parameters, such as:
m *m*aildir
#+end_example

For the complate list, see *mu-fields(1)*.
For the complete list, try the command: ~mu info fields~.

The message flags are described in *mu-query(7)*. As an example, a message which
is 'seen', has an attachment and is signed would have 'asz' as its corresponding
Expand All @@ -100,7 +100,7 @@ specify the field to sort the search results by and the direction (i.e.,
to,t To:-recipient(s)
#+end_example

For the complete list use can use the *mu fields* command; see *mu-fields(1)*.
For the complete list, try the command: ~mu info fields~.

Thus, for example, to sort messages by date, you could specify:

Expand Down Expand Up @@ -283,4 +283,4 @@ default format), and UTF-8 for all other formats (=sexp=, =xml=).

* SEE ALSO

*mu(1)*, *mu-index(1)*, *mu-query(7)*, *mu-fields(1)*
*mu(1)*, *mu-index(1)*, *mu-query(7)*, *mu-info(1)*
7 changes: 4 additions & 3 deletions man/mu-query.7.org
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ bit longer than 'normal' queries.
* FIELDS

We already saw a number of search fields, such as *subject:* and *body:*. For the
full table with all details, including single-char shortcuts, see *mu-fields(1)*.
full table with all details, including single-char shortcuts, try the command:
~mu info fields~.

|------------+-----------+--------------------------------|
| field-name | alias | description |
Expand Down Expand Up @@ -325,7 +326,7 @@ hallo and (lang:nl or lang:de)

With current Xapian versions, the apostroph character is considered part of a
word. Thus, you cannot find =D'Artagnan= by searching for =Artagnan=. So, include
the apostroph in search or use a regexp search.
the apostrophe in search or use a regexp search.

Matching on spaces has changed compared to the old query-parser; this applies
e.g. to Maildirs that have spaces in their name, such as =Sent Items=. See *MAILDIR*
Expand All @@ -335,4 +336,4 @@ above.

* SEE ALSO

*mu-find(1)*, *mu-fields(1), *pcre(3)*
*mu-find(1)*, *mu-info(1), *pcre(3)*
136 changes: 87 additions & 49 deletions mu/mu-cmd-info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,73 @@
#include "mu-cmd.hh"
#include <message/mu-message.hh>
#include "utils/mu-utils.hh"
#include <fmt/ostream.h>

#include <thirdparty/tabulate.hpp>

using namespace Mu;
using namespace tabulate;

template <> struct fmt::formatter<Table> : ostream_formatter {};

static void
table_header(Table& table, const Options& opts)
colorify(Table& table, const Options& opts)
{
if (opts.nocolor)
if (opts.nocolor || table.size() == 0)
return;

(*table.begin()).format()
.font_style({FontStyle::bold})
.font_color(Color::blue);
for (auto&& c = 0U; c != table.row(0).size(); ++c) {
switch (c) {
case 0:
table.column(c).format()
.font_color(Color::green)
.font_style({FontStyle::bold});
break;
case 1:
table.column(c).format()
.font_color(Color::blue);
break;
case 2:
table.column(c).format()
.font_color(Color::magenta);
break;

case 3:
table.column(c).format()
.font_color(Color::yellow);
break;
case 4:
table.column(c).format()
.font_color(Color::green);
break;
case 5:
table.column(c).format()
.font_color(Color::blue);
break;
case 6:
table.column(c).format()
.font_color(Color::magenta);
break;

case 7:
table.column(c).format()
.font_color(Color::yellow);
break;
default:
table.column(c).format()
.font_color(Color::grey);
break;
}
}

for (auto&& c = 0U; c != table.row(0).size(); ++c)
table[0][c].format()
.font_color(Color::white)
.font_style({FontStyle::bold});

}


static Result<void>
topic_fields(const Options& opts)
{
Expand Down Expand Up @@ -75,9 +124,9 @@ topic_fields(const Options& opts)
if (field.is_internal())
return; // skip.

fields.add_row({format("%.*s", STR_V(field.name)),
field.alias.empty() ? "" : format("%.*s", STR_V(field.alias)),
field.shortcut ? format("%c", field.shortcut) : ""s,
fields.add_row({mu_format("{}", field.name),
field.alias.empty() ? "" : mu_format("{}", field.alias),
field.shortcut ? mu_format("{}", field.shortcut) : ""s,
searchable(field),
field.is_value() ? "yes" : "no",
field.include_in_sexp() ? "yes" : "no",
Expand All @@ -86,8 +135,7 @@ topic_fields(const Options& opts)
++row;
});

table_header(fields, opts);

colorify(fields, opts);
std::cout << fields << '\n';

return Ok();
Expand Down Expand Up @@ -120,38 +168,23 @@ topic_flags(const Options& opts)
}
}, info.category);

flags.add_row({format("%.*s", STR_V(info.name)),
format("%c", info.shortcut),
flags.add_row({mu_format("{}", info.name),
mu_format("{}", info.shortcut),
catname,
std::string{info.description}});
});

table_header(flags, opts);
colorify(flags, opts);

std::cout << flags << '\n';
return Ok();
}

static void
colorify(Table& table)
{
for (auto&& row: table) {

if (row.cells().size() < 2)
continue;

row.cells().at(0)->format().font_style({FontStyle::bold})
.font_color(Color::green);
row.cells().at(1)->format().font_color(Color::blue);
}
return Ok();
}


static Result<void>
topic_store(const Mu::Store& store, const Options& opts)
{
using namespace tabulate;

auto tstamp = [](::time_t t)->std::string {
if (t == 0)
return "never";
Expand All @@ -161,56 +194,58 @@ topic_store(const Mu::Store& store, const Options& opts)

Table info;
const auto conf{store.config()};
info.add_row({"property", "value"});
info.add_row({"maildir", store.root_maildir()});
info.add_row({"database-path", store.path()});
info.add_row({"schema-version",
format("%zu", conf.get<Config::Id::SchemaVersion>())});
info.add_row({"max-message-size", format("%zu", conf.get<Config::Id::MaxMessageSize>())});
info.add_row({"batch-size", format("%zu", conf.get<Config::Id::BatchSize>())});
mu_format("{}", conf.get<Config::Id::SchemaVersion>())});
info.add_row({"max-message-size", mu_format("{}", conf.get<Config::Id::MaxMessageSize>())});
info.add_row({"batch-size", mu_format("{}", conf.get<Config::Id::BatchSize>())});
info.add_row({"created", tstamp(conf.get<Config::Id::Created>())});

for (auto&& c : conf.get<Config::Id::PersonalAddresses>())
info.add_row({"personal-address", c});
for (auto&& c : conf.get<Config::Id::IgnoredAddresses>())
info.add_row({"ignored-address", c});

info.add_row({"messages in store", format("%zu", store.size())});
info.add_row({"messages in store", mu_format("{}", store.size())});
info.add_row({"last-change", tstamp(store.statistics().last_change)});
info.add_row({"last-index", tstamp(store.statistics().last_index)});

if (!opts.nocolor)
colorify(info);
colorify(info, opts);

std::cout << info << '\n';

return Ok();
}

static Result<void>
topic_common(const Options& opts)
topic_mu(const Options& opts)
{
Table info;

using namespace tabulate;

info.add_row({"mu version", std::string{VERSION}});
info.add_row({"store schema-version", format("%u", MU_STORE_SCHEMA_VERSION)});
info.add_row({"guile-support:",
info.add_row({"property", "value"});
info.add_row({"version", std::string{VERSION}});
info.add_row({"schema-version", mu_format("{}", MU_STORE_SCHEMA_VERSION)});
info.add_row({"guile-support",
#if BUILD_GUILE
"yes"
#else
"no"
#endif
});
info.add_row({"readline-support:",
info.add_row({"readline-support",
#if HAVE_LIBREADLINE
"yes"
#else
"no"
#endif
});

info.add_row({"cld2 language support:",
info.add_row({"cld2-support",
#if HAVE_CLD2
"yes"
#else
Expand All @@ -219,10 +254,12 @@ topic_common(const Options& opts)
});

if (!opts.nocolor)
colorify(info);
colorify(info, opts);

std::cout << info << '\n';

// mu_println("{}", info);

return Ok();
}

Expand All @@ -239,21 +276,22 @@ Mu::mu_cmd_info(const Mu::Store& store, const Options& opts)
else if (topic == "fields") {
topic_fields(opts);
return topic_flags(opts);
} else if (topic == "common") {
return topic_common(opts);
} else if (topic == "mu") {
return topic_mu(opts);
} else {
topic_common(opts);
topic_store(store, opts);

MaybeAnsi col{!opts.nocolor};
using Color = MaybeAnsi::Color;

auto topic = [&](const std::string& s)->std::string {
return " " + col.fg(Color::Green) + s.c_str() + col.reset();
auto topic = [&](auto&& t, auto&& d)->std::string {
return mu_format("{}{:<10}{} - {:>12}",
col.fg(Color::Green), t, col.reset(), d);
};

std::cout << "\nother available info topics ('mu info <topic>'):\n"
<< topic("store") << " - information about the message store (database)\n"
<< topic("fields") << " - information about message fields\n";
mu_println("\nother info topics ('mu info <topic>'):\n{}\n{}",
topic("store", "information about the message store (database)"),
topic("fields", "information about message fields"));
}

return Ok();
Expand Down
4 changes: 1 addition & 3 deletions mu/mu-cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ static Result<void>
cmd_fields(const Options& opts)
{
mu_printerrln("the 'mu fields' command has been superseded by 'mu info'; try:\n"
" mu info fields\n"
" mu info flags");

" mu info fields\n");
return Ok();
}

Expand Down

0 comments on commit d96e9cc

Please sign in to comment.