summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/output.cc32
-rw-r--r--src/output.h8
-rw-r--r--src/report.cc22
-rw-r--r--src/report.h9
4 files changed, 57 insertions, 14 deletions
diff --git a/src/output.cc b/src/output.cc
index 2a6f0c20..71ec6d88 100644
--- a/src/output.cc
+++ b/src/output.cc
@@ -40,9 +40,10 @@
namespace ledger {
-format_posts::format_posts(report_t& _report,
- const string& format,
- bool _print_raw)
+format_posts::format_posts(report_t& _report,
+ const string& format,
+ bool _print_raw,
+ const optional<string>& _prepend_format)
: report(_report), last_xact(NULL), last_post(NULL),
print_raw(_print_raw)
{
@@ -65,6 +66,9 @@ format_posts::format_posts(report_t& _report,
first_line_format.parse_format(format);
next_lines_format.parse_format(format);
}
+
+ if (_prepend_format)
+ prepend_format.parse_format(*_prepend_format);
}
void format_posts::flush()
@@ -95,6 +99,10 @@ void format_posts::operator()(post_t& post)
else if (! post.has_xdata() ||
! post.xdata().has_flags(POST_EXT_DISPLAYED)) {
bind_scope_t bound_scope(report, post);
+
+ if (prepend_format)
+ out << prepend_format(bound_scope);
+
if (last_xact != post.xact) {
if (last_xact) {
bind_scope_t xact_scope(report, *last_xact);
@@ -115,8 +123,9 @@ void format_posts::operator()(post_t& post)
}
}
-format_accounts::format_accounts(report_t& _report,
- const string& format)
+format_accounts::format_accounts(report_t& _report,
+ const string& format,
+ const optional<string>& _prepend_format)
: report(_report), disp_pred()
{
TRACE_CTOR(format_accounts, "report&, const string&");
@@ -136,6 +145,9 @@ format_accounts::format_accounts(report_t& _report,
account_line_format.parse_format(format);
total_line_format.parse_format(format, account_line_format);
}
+
+ if (_prepend_format)
+ prepend_format.parse_format(*_prepend_format);
}
std::size_t format_accounts::post_account(account_t& account, const bool flat)
@@ -150,6 +162,11 @@ std::size_t format_accounts::post_account(account_t& account, const bool flat)
account.xdata().add_flags(ACCOUNT_EXT_DISPLAYED);
bind_scope_t bound_scope(report, account);
+
+ if (prepend_format)
+ static_cast<std::ostream&>(report.output_stream)
+ << prepend_format(bound_scope);
+
static_cast<std::ostream&>(report.output_stream)
<< account_line_format(bound_scope);
@@ -217,6 +234,11 @@ void format_accounts::flush()
! report.HANDLED(no_total) && ! report.HANDLED(percent)) {
bind_scope_t bound_scope(report, *report.session.journal->master);
out << separator_format(bound_scope);
+
+ if (prepend_format)
+ static_cast<std::ostream&>(report.output_stream)
+ << prepend_format(bound_scope);
+
out << total_line_format(bound_scope);
}
diff --git a/src/output.h b/src/output.h
index fedd08ff..778a9335 100644
--- a/src/output.h
+++ b/src/output.h
@@ -60,13 +60,15 @@ protected:
format_t first_line_format;
format_t next_lines_format;
format_t between_format;
+ format_t prepend_format;
xact_t * last_xact;
post_t * last_post;
bool print_raw;
public:
format_posts(report_t& _report, const string& format,
- bool _print_raw = false);
+ bool _print_raw = false,
+ const optional<string>& _prepend_format = none);
virtual ~format_posts() {
TRACE_DTOR(format_posts);
}
@@ -82,12 +84,14 @@ protected:
format_t account_line_format;
format_t total_line_format;
format_t separator_format;
+ format_t prepend_format;
predicate_t disp_pred;
std::list<account_t *> posted_accounts;
public:
- format_accounts(report_t& _report, const string& _format);
+ format_accounts(report_t& _report, const string& _format,
+ const optional<string>& _prepend_format = none);
virtual ~format_accounts() {
TRACE_DTOR(format_accounts);
}
diff --git a/src/report.cc b/src/report.cc
index 4e9cfe89..4d1a9700 100644
--- a/src/report.cc
+++ b/src/report.cc
@@ -631,6 +631,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
else OPT(pricesdb_format_);
else OPT(print_format_);
else OPT(payee_width_);
+ else OPT(prepend_format_);
break;
case 'q':
OPT(quantity);
@@ -854,7 +855,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
if (*(p + 1) == '\0' || is_eq(p, "bal") || is_eq(p, "balance")) {
return expr_t::op_t::wrap_functor
(reporter<account_t, acct_handler_ptr, &report_t::accounts_report>
- (new format_accounts(*this, report_format(HANDLER(balance_format_))),
+ (new format_accounts(*this, report_format(HANDLER(balance_format_)),
+ maybe_format(HANDLER(prepend_format_))),
*this, "#balance"));
}
else if (is_eq(p, "budget")) {
@@ -866,7 +868,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
return expr_t::op_t::wrap_functor
(reporter<account_t, acct_handler_ptr, &report_t::accounts_report>
- (new format_accounts(*this, report_format(HANDLER(budget_format_))),
+ (new format_accounts(*this, report_format(HANDLER(budget_format_)),
+ maybe_format(HANDLER(prepend_format_))),
*this, "#budget"));
}
break;
@@ -875,7 +878,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
if (is_eq(p, "csv")) {
return WRAP_FUNCTOR
(reporter<>
- (new format_posts(*this, report_format(HANDLER(csv_format_))),
+ (new format_posts(*this, report_format(HANDLER(csv_format_)),
+ maybe_format(HANDLER(prepend_format_))),
*this, "#csv"));
}
else if (is_eq(p, "cleared")) {
@@ -884,7 +888,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
return expr_t::op_t::wrap_functor
(reporter<account_t, acct_handler_ptr, &report_t::accounts_report>
- (new format_accounts(*this, report_format(HANDLER(cleared_format_))),
+ (new format_accounts(*this, report_format(HANDLER(cleared_format_)),
+ maybe_format(HANDLER(prepend_format_))),
*this, "#cleared"));
}
break;
@@ -913,12 +918,14 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
else if (is_eq(p, "prices"))
return expr_t::op_t::wrap_functor
(reporter<post_t, post_handler_ptr, &report_t::commodities_report>
- (new format_posts(*this, report_format(HANDLER(prices_format_))),
+ (new format_posts(*this, report_format(HANDLER(prices_format_)),
+ maybe_format(HANDLER(prepend_format_))),
*this, "#prices"));
else if (is_eq(p, "pricesdb"))
return expr_t::op_t::wrap_functor
(reporter<post_t, post_handler_ptr, &report_t::commodities_report>
- (new format_posts(*this, report_format(HANDLER(pricesdb_format_))),
+ (new format_posts(*this, report_format(HANDLER(pricesdb_format_)),
+ maybe_format(HANDLER(prepend_format_))),
*this, "#pricesdb"));
break;
@@ -926,7 +933,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
if (*(p + 1) == '\0' || is_eq(p, "reg") || is_eq(p, "register"))
return WRAP_FUNCTOR
(reporter<>
- (new format_posts(*this, report_format(HANDLER(register_format_))),
+ (new format_posts(*this, report_format(HANDLER(register_format_)),
+ false, maybe_format(HANDLER(prepend_format_))),
*this, "#register"));
else if (is_eq(p, "reload"))
return MAKE_FUNCTOR(report_t::reload_command);
diff --git a/src/report.h b/src/report.h
index 02fd2c8d..3afb0107 100644
--- a/src/report.h
+++ b/src/report.h
@@ -172,6 +172,12 @@ public:
return option.str();
}
+ optional<string> maybe_format(option_t<report_t>& option) {
+ if (option)
+ return option.str();
+ return none;
+ }
+
value_t reload_command(call_scope_t&);
value_t echo_command(call_scope_t& scope);
@@ -252,6 +258,7 @@ public:
HANDLER(period_).report(out);
HANDLER(plot_amount_format_).report(out);
HANDLER(plot_total_format_).report(out);
+ HANDLER(prepend_format_).report(out);
HANDLER(price).report(out);
HANDLER(prices_format_).report(out);
HANDLER(pricesdb_format_).report(out);
@@ -693,6 +700,8 @@ public:
"%(format_date(date, \"%Y-%m-%d\")) %(quantity(scrub(display_total)))\n");
});
+ OPTION(report_t, prepend_format_);
+
OPTION_(report_t, price, DO() { // -I
parent->HANDLER(display_amount_)
.set_expr(string("--price"), "price(amount_expr)");