From 298a4faef371cae8f308c0b729a1a34ea7aa927c Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 16 Jun 2009 16:57:10 +0100 Subject: 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 --- src/value.cc | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/value.cc') 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& 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: -- cgit v1.2.3