0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-16 15:00:51 +01:00

modules/console: Support alternative HTML output; start with 'net peer'.

This commit is contained in:
Jason Volk 2018-03-26 00:33:26 -07:00
parent 1ceaa73e5b
commit 16483aaea2
2 changed files with 61 additions and 2 deletions

View file

@ -135,6 +135,7 @@ find_cmd(const string_view &line)
struct opt struct opt
{ {
std::ostream &out; std::ostream &out;
bool html {false};
operator std::ostream &() operator std::ostream &()
{ {
@ -163,7 +164,12 @@ console_command(std::ostream &out,
const string_view &opts) const string_view &opts)
try try
{ {
opt opt{out}; opt opt
{
out,
has(opts, "html")
};
const cmd *const cmd const cmd *const cmd
{ {
find_cmd(line) find_cmd(line)
@ -595,9 +601,61 @@ console_cmd__db__list(opt &out, const string_view &line)
// net // net
// //
static bool
html__net__peer(opt &out, const string_view &line)
{
out << "<table>";
out << "<tr>";
out << "<td> HOST </td>";
out << "<td> ADDR </td>";
out << "<td> LINKS </td>";
out << "<td> REQS </td>";
out << "<td> ▲ BYTES </td>";
out << "<td> ▼ BYTES </td>";
out << "<td> ERROR </td>";
out << "</tr>";
for(const auto &p : server::peers)
{
using std::setw;
using std::left;
using std::right;
const auto &host{p.first};
const auto &peer{*p.second};
const net::ipport &ipp{peer.remote};
out << "<tr>";
out << "<td>" << host << "</td>";
out << "<td>" << ipp << "</td>";
out << "<td>" << peer.link_count() << "</td>";
out << "<td>" << peer.tag_count() << "</td>";
out << "<td>" << peer.write_total() << "</td>";
out << "<td>" << peer.read_total() << "</td>";
out << "<td>";
if(peer.err_has() && peer.err_msg())
out << peer.err_msg();
else if(peer.err_has())
out << "<unknown error>"_sv;
out << "</td>";
out << "</tr>";
}
out << "</table>";
return true;
}
bool bool
console_cmd__net__peer(opt &out, const string_view &line) console_cmd__net__peer(opt &out, const string_view &line)
{ {
if(out.html)
return html__net__peer(out, line);
for(const auto &p : server::peers) for(const auto &p : server::peers)
{ {
using std::setw; using std::setw;

View file

@ -184,7 +184,8 @@ noexcept try
pubsetbuf(out, buf); pubsetbuf(out, buf);
out << "<pre>"; out << "<pre>";
command(out, body, {}); static const string_view opts{"html"};
command(out, body, opts);
out << "</pre>"; out << "</pre>";
const auto str //TODO: X const auto str //TODO: X