diff options
author | John Wiegley <johnw@newartisans.com> | 2009-06-16 16:57:10 +0100 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-06-16 16:57:10 +0100 |
commit | 298a4faef371cae8f308c0b729a1a34ea7aa927c (patch) | |
tree | 277f3125c4e03f7c80c8187c6165a66286131a9b /src/value.cc | |
parent | 995c94ef178d143c2458ebf66ddb084aa782e975 (diff) | |
download | fork-ledger-298a4faef371cae8f308c0b729a1a34ea7aa927c.tar.gz fork-ledger-298a4faef371cae8f308c0b729a1a34ea7aa927c.tar.bz2 fork-ledger-298a4faef371cae8f308c0b729a1a34ea7aa927c.zip |
Move amount colorization deeper into the core
This is necessary in order to redden negative amounts correctly under
all circumstances, such as component amounts of a multi-commodity
balance.
Fixes 727B2DF8-A2A1-4716-9C15-547F20D5F933
Diffstat (limited to 'src/value.cc')
-rw-r--r-- | src/value.cc | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/value.cc b/src/value.cc index f34d0e48..6f6e665d 100644 --- a/src/value.cc +++ b/src/value.cc @@ -1424,10 +1424,12 @@ void value_t::print(std::ostream& out, const int first_width, const int latter_width, const bool right_justify, + const bool colorize, const optional<string>& date_format) const { if (first_width > 0 && - ! is_amount() && ! is_balance() && ! is_string()) { + (! is_amount() || as_amount().is_zero()) && + ! is_balance() && ! is_string()) { out.width(first_width); if (right_justify) @@ -1460,17 +1462,20 @@ void value_t::print(std::ostream& out, break; case INTEGER: - out << std::right << as_long(); + if (colorize && as_long() < 0) + justify(out, to_string(), first_width, right_justify, true); + else + out << as_long(); break; case AMOUNT: { if (as_amount().is_zero()) { - out.width(first_width); - out << (right_justify ? std::right : std::left) << 0; + out << 0; } else { std::ostringstream buf; buf << as_amount(); - justify(out, buf.str(), first_width, right_justify); + justify(out, buf.str(), first_width, right_justify, + colorize && as_amount().sign() < 0); } break; } @@ -1493,14 +1498,15 @@ void value_t::print(std::ostream& out, out << ", "; value.print(out, first_width, latter_width, right_justify, - date_format); + colorize, date_format); } out << ')'; break; } case BALANCE: - as_balance().print(out, first_width, latter_width, right_justify); + as_balance().print(out, first_width, latter_width, right_justify, + colorize); break; case POINTER: |