Separator in "balance" now part of format string

This commit is contained in:
John Wiegley 2009-02-27 16:23:36 -04:00
parent d102641f2a
commit 56693fab9b
8 changed files with 46 additions and 23 deletions

View file

@ -199,6 +199,35 @@ void gather_statistics::operator()(post_t& post)
} }
} }
format_accounts::format_accounts(report_t& _report,
const string& format)
: report(_report), disp_pred()
{
TRACE_CTOR(format_accounts, "report&, const string&");
if (report.HANDLED(display_)) {
DEBUG("account.display",
"Account display predicate: " << report.HANDLER(display_).str());
disp_pred.predicate.parse(report.HANDLER(display_).str());
}
const char * f = format.c_str();
if (const char * p = std::strstr(f, "%/")) {
account_line_format.parse(string(f, 0, p - f));
const char * n = p + 2;
if (const char * p = std::strstr(n, "%/")) {
total_line_format.parse(string(n, 0, p - n));
separator_format.parse(string(p + 2));
} else {
total_line_format.parse(n);
}
} else {
account_line_format.parse(format);
total_line_format.parse(format);
}
}
void format_accounts::post_account(account_t& account) void format_accounts::post_account(account_t& account)
{ {
bind_scope_t bound_scope(report, account); bind_scope_t bound_scope(report, account);
@ -233,7 +262,7 @@ void format_accounts::post_account(account_t& account)
if (format_account) { if (format_account) {
account.xdata().add_flags(ACCOUNT_EXT_DISPLAYED); account.xdata().add_flags(ACCOUNT_EXT_DISPLAYED);
format.format(report.output_stream, bound_scope); account_line_format.format(report.output_stream, bound_scope);
} }
} }
@ -262,10 +291,10 @@ void format_accounts::flush()
account_t::xdata_t& xdata(report.session.master->xdata()); account_t::xdata_t& xdata(report.session.master->xdata());
if (! report.HANDLED(no_total) && top_displayed > 1 && xdata.total) { if (! report.HANDLED(no_total) && top_displayed > 1 && xdata.total) {
out << "--------------------\n";
xdata.value = xdata.total; xdata.value = xdata.total;
bind_scope_t bound_scope(report, *report.session.master); bind_scope_t bound_scope(report, *report.session.master);
format.format(out, bound_scope); separator_format.format(out, bound_scope);
total_line_format.format(out, bound_scope);
} }
out.flush(); out.flush();

View file

@ -135,24 +135,15 @@ class format_accounts : public item_handler<account_t>
{ {
protected: protected:
report_t& report; report_t& report;
format_t format; format_t account_line_format;
format_t total_line_format;
format_t separator_format;
item_predicate disp_pred; item_predicate disp_pred;
std::list<account_t *> posted_accounts; std::list<account_t *> posted_accounts;
public: public:
format_accounts(report_t& _report, format_accounts(report_t& _report, const string& _format);
const string& _format = "")
: report(_report), format(_format), disp_pred()
{
TRACE_CTOR(format_accounts, "report&, const string&, bool");
if (report.HANDLED(display_)) {
DEBUG("account.display",
"Account display predicate: " << report.HANDLER(display_).str());
disp_pred.predicate.parse(report.HANDLER(display_).str());
}
}
virtual ~format_accounts() { virtual ~format_accounts() {
TRACE_DTOR(format_accounts); TRACE_DTOR(format_accounts);
} }

View file

@ -243,7 +243,10 @@ public:
on("%(ansify_if(justify(scrub(display_total), 20, -1, true), \"red\", " on("%(ansify_if(justify(scrub(display_total), 20, -1, true), \"red\", "
" color & scrub(display_total) < 0))" " color & scrub(display_total) < 0))"
" %(!options.flat ? depth_spacer : \"\")" " %(!options.flat ? depth_spacer : \"\")"
"%-(ansify_if(partial_account(options.flat), \"blue\", color))\n"); "%-(ansify_if(partial_account(options.flat), \"blue\", color))\n%/"
"%(ansify_if(justify(scrub(display_total), 20, -1, true), \"red\", "
" color & scrub(display_total) < 0))\n%/"
"--------------------\n");
}); });
OPTION(report_t, base); OPTION(report_t, base);