summaryrefslogtreecommitdiff
path: root/src/print.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2012-02-26 02:17:45 -0600
committerJohn Wiegley <johnw@newartisans.com>2012-02-26 02:18:04 -0600
commit40ab81308025e9655074da37671c444b4257f867 (patch)
tree2cf9e77d73f88c7ec4e3919d7df71811f9184501 /src/print.cc
parent4ebcce3067f7b8df36a76ab16cd0a693a82ccbc5 (diff)
downloadfork-ledger-40ab81308025e9655074da37671c444b4257f867.tar.gz
fork-ledger-40ab81308025e9655074da37671c444b4257f867.tar.bz2
fork-ledger-40ab81308025e9655074da37671c444b4257f867.zip
Don't print amounts when not necessary in 'print'
Diffstat (limited to 'src/print.cc')
-rw-r--r--src/print.cc30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/print.cc b/src/print.cc
index b7f72bf0..215ab30b 100644
--- a/src/print.cc
+++ b/src/print.cc
@@ -119,7 +119,12 @@ namespace {
}
}
+ std::size_t count = xact.posts.size();
+ std::size_t index = 0;
+
foreach (post_t * post, xact.posts) {
+ index++;
+
if (! report.HANDLED(generated) &&
(post->has_flags(ITEM_TEMP | ITEM_GENERATED) &&
! post->has_flags(POST_ANONYMIZED)))
@@ -163,17 +168,15 @@ namespace {
std::string::size_type slip =
(static_cast<std::string::size_type>(account_width) -
static_cast<std::string::size_type>(name.length()));
- if (slip > 0) {
- out.width(static_cast<std::streamsize>(slip));
- out << ' ';
- }
-
- std::ostringstream amtbuf;
string amt;
if (post->amount_expr) {
amt = post->amount_expr->text();
- } else {
+ }
+ else if (! (count == 2 && index == 2 &&
+ (*xact.posts.begin())->amount.commodity() ==
+ post->amount.commodity() &&
+ ! (*xact.posts.begin())->cost && ! post->cost)) {
int amount_width =
(report.HANDLER(amount_width_).specified ?
report.HANDLER(amount_width_).value.to_int() : 12);
@@ -191,6 +194,7 @@ namespace {
(static_cast<std::string::size_type>(amt.length()) -
static_cast<std::string::size_type>(trimmed_amt.length()));
+ std::ostringstream amtbuf;
if (slip + amt_slip < 2)
amtbuf << string(2 - (slip + amt_slip), ' ');
amtbuf << amt;
@@ -208,9 +212,15 @@ namespace {
amtbuf << " = " << *post->assigned_amount;
string trailer = amtbuf.str();
- out << trailer;
-
- account_width += unistring(trailer).length();
+ if (! trailer.empty()) {
+ if (slip > 0) {
+ out.width(static_cast<std::streamsize>(slip));
+ out << ' ';
+ }
+ out << trailer;
+
+ account_width += unistring(trailer).length();
+ }
} else {
out << pbuf.str();
}