From a7c28aa20057525a9247d0ae69eb063b53b21811 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 22 May 2010 19:17:13 -0400 Subject: Added new option --prepend-width This is useful for making sure that the column containing the results of --prepend-format is a consistent width throughout the report (including those lines where it is not applied). Fixes 64F9D913-75E1-4830-A3D9-29B72442E68B --- src/output.cc | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/output.cc') diff --git a/src/output.cc b/src/output.cc index ec1faba6..183d80b3 100644 --- a/src/output.cc +++ b/src/output.cc @@ -42,8 +42,10 @@ namespace ledger { format_posts::format_posts(report_t& _report, const string& format, - const optional& _prepend_format) - : report(_report), last_xact(NULL), last_post(NULL) + const optional& _prepend_format, + std::size_t _prepend_width) + : report(_report), prepend_width(_prepend_width), + last_xact(NULL), last_post(NULL) { TRACE_CTOR(format_posts, "report&, const string&, bool"); @@ -82,8 +84,10 @@ void format_posts::operator()(post_t& post) ! post.xdata().has_flags(POST_EXT_DISPLAYED)) { bind_scope_t bound_scope(report, post); - if (prepend_format) + if (prepend_format) { + out.width(prepend_width); out << prepend_format(bound_scope); + } if (last_xact != post.xact) { if (last_xact) { @@ -107,8 +111,9 @@ void format_posts::operator()(post_t& post) format_accounts::format_accounts(report_t& _report, const string& format, - const optional& _prepend_format) - : report(_report), disp_pred() + const optional& _prepend_format, + std::size_t _prepend_width) + : report(_report), prepend_width(_prepend_width), disp_pred() { TRACE_CTOR(format_accounts, "report&, const string&"); @@ -144,9 +149,11 @@ std::size_t format_accounts::post_account(account_t& account, const bool flat) bind_scope_t bound_scope(report, account); - if (prepend_format) + if (prepend_format) { + static_cast(report.output_stream).width(prepend_width); static_cast(report.output_stream) << prepend_format(bound_scope); + } static_cast(report.output_stream) << account_line_format(bound_scope); @@ -216,9 +223,11 @@ void format_accounts::flush() bind_scope_t bound_scope(report, *report.session.journal->master); out << separator_format(bound_scope); - if (prepend_format) + if (prepend_format) { + static_cast(report.output_stream).width(prepend_width); static_cast(report.output_stream) << prepend_format(bound_scope); + } out << total_line_format(bound_scope); } -- cgit v1.2.3