mu: use fmt-based apis in mu index/server and options
iostream is so 1998.
This commit is contained in:
@ -26,7 +26,7 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <cstdio>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@ -68,30 +68,34 @@ print_stats(const Indexer::Progress& stats, bool color)
|
||||
MaybeAnsi col{color};
|
||||
using Color = MaybeAnsi::Color;
|
||||
|
||||
std::cout << col.fg(Color::Yellow) << kars[++i % 4] << col.reset() << " indexing messages; "
|
||||
<< "checked: " << col.fg(Color::Green) << stats.checked << col.reset()
|
||||
<< "; updated/new: " << col.fg(Color::Green) << stats.updated << col.reset()
|
||||
<< "; cleaned-up: " << col.fg(Color::Green) << stats.removed << col.reset();
|
||||
mu_print("{}{}{} indexing messages; "
|
||||
"checked: {}{}{}; "
|
||||
"updated/new: {}{}{}; "
|
||||
"cleaned-up: {}{}{}",
|
||||
col.fg(Color::Yellow), kars[++i % 4], col.reset(),
|
||||
col.fg(Color::Green), static_cast<size_t>(stats.checked), col.reset(),
|
||||
col.fg(Color::Green), static_cast<size_t>(stats.updated), col.reset(),
|
||||
col.fg(Color::Green), static_cast<size_t>(stats.removed), col.reset());
|
||||
}
|
||||
|
||||
Result<void>
|
||||
Mu::mu_cmd_index(Store& store, const Options& opts)
|
||||
{
|
||||
const auto mdir{store.root_maildir()};
|
||||
if (G_UNLIKELY(access(mdir.c_str(), R_OK) != 0))
|
||||
if (G_UNLIKELY(::access(mdir.c_str(), R_OK) != 0))
|
||||
return Err(Error::Code::File, "'{}' is not readable: {}",
|
||||
mdir.c_str(), g_strerror(errno));
|
||||
mdir, g_strerror(errno));
|
||||
|
||||
MaybeAnsi col{!opts.nocolor};
|
||||
using Color = MaybeAnsi::Color;
|
||||
if (!opts.quiet) {
|
||||
if (opts.index.lazycheck)
|
||||
std::cout << "lazily ";
|
||||
mu_print("lazily ");
|
||||
|
||||
std::cout << "indexing maildir " << col.fg(Color::Green)
|
||||
<< store.root_maildir() << col.reset() << " -> store "
|
||||
<< col.fg(Color::Green) << store.path() << col.reset()
|
||||
<< std::endl;
|
||||
mu_println("indexing maildir {}{}{} -> "
|
||||
"store {}{}{}",
|
||||
col.fg(Color::Green), store.root_maildir(), col.reset(),
|
||||
col.fg(Color::Blue), store.path(), col.reset());
|
||||
}
|
||||
|
||||
Mu::Indexer::Config conf{};
|
||||
@ -108,11 +112,11 @@ Mu::mu_cmd_index(Store& store, const Options& opts)
|
||||
if (!opts.quiet)
|
||||
print_stats(indexer.progress(), !opts.nocolor);
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(250));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
|
||||
if (!opts.quiet) {
|
||||
std::cout << "\r";
|
||||
std::cout.flush();
|
||||
mu_print("\r");
|
||||
::fflush({});
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,7 +124,8 @@ Mu::mu_cmd_index(Store& store, const Options& opts)
|
||||
|
||||
if (!opts.quiet) {
|
||||
print_stats(store.indexer().progress(), !opts.nocolor);
|
||||
std::cout << std::endl;
|
||||
mu_print("\n");
|
||||
::fflush({});
|
||||
}
|
||||
|
||||
return Ok();
|
||||
|
||||
@ -136,9 +136,9 @@ Mu::mu_cmd_server(const Mu::Options& opts) try {
|
||||
setup_readline(histpath, 50);
|
||||
|
||||
install_sig_handler();
|
||||
std::cout << ";; Welcome to the " << PACKAGE_STRING << " command-server"
|
||||
<< (opts.debug ? " (debug-mode)" : "") << '\n'
|
||||
<< ";; Use (help) to get a list of commands, (quit) to quit.\n";
|
||||
mu_println(";; Welcome to the " PACKAGE_STRING " command-server{}\n"
|
||||
";; Use (help) to get a list of commands, (quit) to quit.",
|
||||
opts.debug ? " (debug-mode)" : "");
|
||||
|
||||
bool do_quit{};
|
||||
while (!MuTerminate && !do_quit) {
|
||||
|
||||
@ -661,7 +661,7 @@ static Result<Options>
|
||||
cmd_help(const CLI::App& app, Options& opts)
|
||||
{
|
||||
if (opts.help.command.empty()) {
|
||||
std::cout << app.help() << "\n";
|
||||
mu_println("{}", app.help());
|
||||
return Ok(std::move(opts));
|
||||
}
|
||||
|
||||
@ -718,12 +718,12 @@ License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
|
||||
This is free software: you are free to change and redistribute it.
|
||||
There is NO WARRANTY, to the extent permitted by law.
|
||||
)");
|
||||
app.set_version_flag("-V,--version", PACKAGE_VERSION);
|
||||
app.set_help_flag("-h,--help", "Show help informmation");
|
||||
app.set_help_all_flag("--help-all");
|
||||
app.require_subcommand(0, 1);
|
||||
app.set_version_flag("-V,--version", PACKAGE_VERSION);
|
||||
app.set_help_flag("-h,--help", "Show help informmation");
|
||||
app.set_help_all_flag("--help-all");
|
||||
app.require_subcommand(0, 1);
|
||||
|
||||
add_global_options(app, opts);
|
||||
add_global_options(app, opts);
|
||||
|
||||
/*
|
||||
* subcommands
|
||||
@ -731,7 +731,7 @@ There is NO WARRANTY, to the extent permitted by law.
|
||||
* we keep around a map of the subcommand pointers, so we can
|
||||
* easily find the chosen one (if any) later.
|
||||
*/
|
||||
for (auto&& cmdinfo: SubCommandInfos) {
|
||||
for (auto&& cmdinfo: SubCommandInfos) {
|
||||
//const auto cmdtype = cmdinfo.first;
|
||||
const auto name{std::string{cmdinfo.second.name}};
|
||||
const auto help{std::string{cmdinfo.second.help}};
|
||||
@ -756,12 +756,12 @@ There is NO WARRANTY, to the extent permitted by law.
|
||||
opts.muhome, "Specify alternative mu directory")
|
||||
->envname("MUHOME")
|
||||
->type_name("<dir>");
|
||||
}
|
||||
}
|
||||
|
||||
/* add scripts (if supported) as semi-subscommands as well */
|
||||
const auto scripts = add_scripts(app, opts);
|
||||
/* add scripts (if supported) as semi-subscommands as well */
|
||||
const auto scripts = add_scripts(app, opts);
|
||||
|
||||
try {
|
||||
try {
|
||||
app.parse(argc, argv);
|
||||
|
||||
// find the chosen sub command, if any.
|
||||
@ -789,11 +789,11 @@ There is NO WARRANTY, to the extent permitted by law.
|
||||
return cmd_help(app, opts);
|
||||
|
||||
} catch (const CLI::CallForHelp& cfh) {
|
||||
std::cout << app.help() << std::flush;
|
||||
mu_println("{}", app.help());
|
||||
} catch (const CLI::CallForAllHelp& cfah) {
|
||||
std::cout << app.help("", CLI::AppFormatMode::All) << std::flush;
|
||||
mu_println("{}", app.help("", CLI::AppFormatMode::All));
|
||||
} catch (const CLI::CallForVersion&) {
|
||||
std::cout << "version " << PACKAGE_VERSION << "\n";
|
||||
mu_println("version {}", PACKAGE_VERSION);
|
||||
} catch (const CLI::ParseError& pe) {
|
||||
return Err(Error::Code::InvalidArgument, "{}", pe.what());
|
||||
} catch (...) {
|
||||
|
||||
Reference in New Issue
Block a user