summaryrefslogtreecommitdiff
path: root/mu/mu-cmd-server.cc
diff options
context:
space:
mode:
authorDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2022-05-06 22:07:15 +0300
committerDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2022-05-06 22:17:53 +0300
commitda8489d0f6bb15d14fba3cc9cf4de50eb9b1fbde (patch)
treeb97b5015a1ae0b7aacb475be0c708e5b29769457 /mu/mu-cmd-server.cc
parent2a5c1e239c6eb5ed90cf08a473e1973888ea34a2 (diff)
sexp: allow for some prettified string output
Allow for adding newlines between list items
Diffstat (limited to 'mu/mu-cmd-server.cc')
-rw-r--r--mu/mu-cmd-server.cc25
1 files changed, 16 insertions, 9 deletions
diff --git a/mu/mu-cmd-server.cc b/mu/mu-cmd-server.cc
index 85fd06a..54daea1 100644
--- a/mu/mu-cmd-server.cc
+++ b/mu/mu-cmd-server.cc
@@ -59,7 +59,7 @@ install_sig_handler(void)
for (i = 0; i != G_N_ELEMENTS(sigs); ++i)
if (sigaction(sigs[i], &action, NULL) != 0)
g_critical("set sigaction for %d failed: %s",
- sigs[i], g_strerror(errno));
+ sigs[i], g_strerror(errno));
}
/*
@@ -82,16 +82,22 @@ cookie(size_t n)
}
static void
-output_sexp_stdout(Sexp&& sexp, bool flush = false)
+output_sexp_stdout(Sexp&& sexp, Server::OutputFlags flags)
{
+ /* if requested, insert \n between list elements; note:
+ * is _not_ inherited by children */
+ if (any_of(flags & Server::OutputFlags::SplitList))
+ sexp.formatting_opts |= Sexp::FormattingOptions::SplitList;
+
const auto str{sexp.to_sexp_string()};
+
cookie(str.size() + 1);
if (G_UNLIKELY(::puts(str.c_str()) < 0)) {
g_critical("failed to write output '%s'", str.c_str());
::raise(SIGTERM); /* terminate ourselves */
}
- if (flush)
+ if (any_of(flags & Server::OutputFlags::Flush))
std::fflush(stdout);
}
@@ -103,7 +109,8 @@ report_error(const Mu::Error& err) noexcept
e.add_prop(":error", Sexp::make_number(static_cast<size_t>(err.code())));
e.add_prop(":message", Sexp::make_string(err.what()));
- output_sexp_stdout(Sexp::make_list(std::move(e)), true /*flush*/);
+ output_sexp_stdout(Sexp::make_list(std::move(e)),
+ Server::OutputFlags::Flush);
}
MuError
@@ -113,15 +120,15 @@ try {
Server server{store, output_sexp_stdout};
g_message("created server with store @ %s; maildir @ %s; debug-mode %s",
- store.properties().database_path.c_str(),
- store.properties().root_maildir.c_str(),
- opts->debug ? "yes" : "no");
+ store.properties().database_path.c_str(),
+ store.properties().root_maildir.c_str(),
+ opts->debug ? "yes" : "no");
tty = ::isatty(::fileno(stdout));
const auto eval = std::string{opts->commands ? "(help :full t)"
- : opts->eval ? opts->eval
- : ""};
+ : opts->eval ? opts->eval
+ : ""};
if (!eval.empty()) {
server.invoke(eval);
return MU_OK;