print honors --columns, --account,amount-width
This commit is contained in:
parent
0f3e7e3e7f
commit
7bd0170d51
1 changed files with 60 additions and 23 deletions
81
src/print.cc
81
src/print.cc
|
|
@ -48,9 +48,14 @@ print_xacts::print_xacts(report_t& _report,
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void print_note(std::ostream& out, const string& note)
|
void print_note(std::ostream& out,
|
||||||
|
const string& note,
|
||||||
|
const std::size_t columns,
|
||||||
|
const std::size_t prior_width)
|
||||||
{
|
{
|
||||||
if (note.length() > 15)
|
// The 4 is for four leading spaces at the beginning of the posting, and
|
||||||
|
// the 3 is for two spaces and a semi-colon before the note.
|
||||||
|
if (columns > 0 && note.length() > columns - (prior_width + 3))
|
||||||
out << "\n ;";
|
out << "\n ;";
|
||||||
else
|
else
|
||||||
out << " ;";
|
out << " ;";
|
||||||
|
|
@ -79,22 +84,32 @@ namespace {
|
||||||
format = report.HANDLER(date_format_).str().c_str();
|
format = report.HANDLER(date_format_).str().c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
out << format_date(item_t::use_effective_date ?
|
std::ostringstream buf;
|
||||||
xact.date() : xact.actual_date(), format_type, format);
|
|
||||||
if (! item_t::use_effective_date && xact.effective_date())
|
|
||||||
out << '=' << format_date(*xact.effective_date(), format_type, format);
|
|
||||||
out << ' ';
|
|
||||||
|
|
||||||
out << (xact.state() == item_t::CLEARED ? "* " :
|
buf << format_date(item_t::use_effective_date ?
|
||||||
|
xact.date() : xact.actual_date(),
|
||||||
|
format_type, format);
|
||||||
|
if (! item_t::use_effective_date && xact.effective_date())
|
||||||
|
buf << '=' << format_date(*xact.effective_date(),
|
||||||
|
format_type, format);
|
||||||
|
buf << ' ';
|
||||||
|
|
||||||
|
buf << (xact.state() == item_t::CLEARED ? "* " :
|
||||||
(xact.state() == item_t::PENDING ? "! " : ""));
|
(xact.state() == item_t::PENDING ? "! " : ""));
|
||||||
|
|
||||||
if (xact.code)
|
if (xact.code)
|
||||||
out << '(' << *xact.code << ") ";
|
buf << '(' << *xact.code << ") ";
|
||||||
|
|
||||||
out << xact.payee;
|
buf << xact.payee;
|
||||||
|
|
||||||
|
string leader = buf.str();
|
||||||
|
out << leader;
|
||||||
|
|
||||||
|
std::size_t columns = (report.HANDLED(columns_) ?
|
||||||
|
report.HANDLER(columns_).value.to_long() : 80);
|
||||||
|
|
||||||
if (xact.note)
|
if (xact.note)
|
||||||
print_note(out, *xact.note);
|
print_note(out, *xact.note, columns, unistring(leader).length());
|
||||||
out << '\n';
|
out << '\n';
|
||||||
|
|
||||||
if (xact.metadata) {
|
if (xact.metadata) {
|
||||||
|
|
@ -139,20 +154,37 @@ namespace {
|
||||||
buf << ')';
|
buf << ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! post->has_flags(POST_CALCULATED) || report.HANDLED(print_virtual)) {
|
|
||||||
unistring name(buf.str());
|
unistring name(buf.str());
|
||||||
|
|
||||||
|
std::size_t account_width =
|
||||||
|
(report.HANDLER(account_width_).specified ?
|
||||||
|
report.HANDLER(account_width_).value.to_long() : 36);
|
||||||
|
|
||||||
|
if (account_width < name.length())
|
||||||
|
account_width = name.length();
|
||||||
|
|
||||||
|
if (! post->has_flags(POST_CALCULATED) || report.HANDLED(print_virtual)) {
|
||||||
out << name.extract();
|
out << name.extract();
|
||||||
int slip = 36 - static_cast<int>(name.length());
|
int slip = (static_cast<int>(account_width) -
|
||||||
if (slip > 0)
|
static_cast<int>(name.length()));
|
||||||
out << string(slip, ' ');
|
if (slip > 0) {
|
||||||
|
out.width(slip);
|
||||||
|
out << ' ';
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostringstream amtbuf;
|
||||||
|
|
||||||
string amt;
|
string amt;
|
||||||
if (post->amount_expr) {
|
if (post->amount_expr) {
|
||||||
amt = post->amount_expr->text();
|
amt = post->amount_expr->text();
|
||||||
} else {
|
} else {
|
||||||
|
std::size_t amount_width =
|
||||||
|
(report.HANDLER(amount_width_).specified ?
|
||||||
|
report.HANDLER(amount_width_).value.to_long() : 12);
|
||||||
|
|
||||||
std::ostringstream amt_str;
|
std::ostringstream amt_str;
|
||||||
report.scrub(post->amount).print(amt_str, 12, -1, true);
|
report.scrub(post->amount)
|
||||||
|
.print(amt_str, static_cast<int>(amount_width), -1, true);
|
||||||
amt = amt_str.str();
|
amt = amt_str.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -161,24 +193,29 @@ namespace {
|
||||||
int amt_slip = (static_cast<int>(amt.length()) -
|
int amt_slip = (static_cast<int>(amt.length()) -
|
||||||
static_cast<int>(trimmed_amt.length()));
|
static_cast<int>(trimmed_amt.length()));
|
||||||
if (slip + amt_slip < 2)
|
if (slip + amt_slip < 2)
|
||||||
out << string(2 - (slip + amt_slip), ' ');
|
amtbuf << string(2 - (slip + amt_slip), ' ');
|
||||||
out << amt;
|
amtbuf << amt;
|
||||||
|
|
||||||
if (post->cost && ! post->has_flags(POST_CALCULATED)) {
|
if (post->cost && ! post->has_flags(POST_CALCULATED)) {
|
||||||
if (post->has_flags(POST_COST_IN_FULL))
|
if (post->has_flags(POST_COST_IN_FULL))
|
||||||
out << " @@ " << report.scrub(post->cost->abs());
|
amtbuf << " @@ " << report.scrub(post->cost->abs());
|
||||||
else
|
else
|
||||||
out << " @ " << report.scrub((*post->cost / post->amount).abs());
|
amtbuf << " @ " << report.scrub((*post->cost / post->amount).abs());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (post->assigned_amount)
|
if (post->assigned_amount)
|
||||||
out << " = " << report.scrub(*post->assigned_amount);
|
amtbuf << " = " << report.scrub(*post->assigned_amount);
|
||||||
|
|
||||||
|
string trailer = amtbuf.str();
|
||||||
|
out << trailer;
|
||||||
|
|
||||||
|
account_width += unistring(trailer).length();
|
||||||
} else {
|
} else {
|
||||||
out << buf.str();
|
out << buf.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (post->note)
|
if (post->note)
|
||||||
print_note(out, *post->note);
|
print_note(out, *post->note, columns, 4 + account_width);
|
||||||
out << '\n';
|
out << '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue