Don't use auto-widths for widths explicitly given

This commit is contained in:
John Wiegley 2009-02-20 14:18:41 -04:00
parent a181ac52d3
commit e05f29bff0
2 changed files with 58 additions and 29 deletions

View file

@ -407,30 +407,49 @@ void global_scope_t::normalize_report_options(const string& verb)
DEBUG("auto.columns", "cols = " << cols); DEBUG("auto.columns", "cols = " << cols);
long date_width = rep.HANDLER(date_width_).value.to_long(); long date_width = rep.HANDLER(date_width_).value.to_long();
long payee_width = int(double(cols) * 0.263157); long payee_width = (rep.HANDLER(payee_width_).specified ?
long account_width = int(double(cols) * 0.302631); rep.HANDLER(payee_width_).value.to_long() :
long amount_width = int(double(cols) * 0.157894); int(double(cols) * 0.263157));
long total_width = amount_width; long account_width = (rep.HANDLER(account_width_).specified ?
rep.HANDLER(account_width_).value.to_long() :
int(double(cols) * 0.302631));
long amount_width = (rep.HANDLER(amount_width_).specified ?
rep.HANDLER(amount_width_).value.to_long() :
int(double(cols) * 0.157894));
long total_width = (rep.HANDLER(total_width_).specified ?
rep.HANDLER(total_width_).value.to_long() :
amount_width);
DEBUG("auto.columns", "date_width = " << date_width); DEBUG("auto.columns", "date_width = " << date_width);
DEBUG("auto.columns", "payee_width = " << payee_width); DEBUG("auto.columns", "payee_width = " << payee_width);
DEBUG("auto.columns", "account_width = " << account_width); DEBUG("auto.columns", "account_width = " << account_width);
DEBUG("auto.columns", "amount_width = " << amount_width); DEBUG("auto.columns", "amount_width = " << amount_width);
DEBUG("auto.columns", "total_width = " << total_width); DEBUG("auto.columns", "total_width = " << total_width);
long total = (4 /* the spaces between */ + date_width + payee_width + if (! rep.HANDLER(date_width_).specified &&
account_width + amount_width + total_width); ! rep.HANDLER(payee_width_).specified &&
if (total > cols) { ! rep.HANDLER(account_width_).specified &&
DEBUG("auto.columns", "adjusting account down"); ! rep.HANDLER(amount_width_).specified &&
account_width -= total - cols; ! rep.HANDLER(total_width_).specified) {
DEBUG("auto.columns", "account_width now = " << account_width); long total = (4 /* the spaces between */ + date_width + payee_width +
account_width + amount_width + total_width);
if (total > cols) {
DEBUG("auto.columns", "adjusting account down");
account_width -= total - cols;
DEBUG("auto.columns", "account_width now = " << account_width);
}
} }
rep.HANDLER(date_width_).on_with(date_width); if (! rep.HANDLER(date_width_).specified)
rep.HANDLER(payee_width_).on_with(payee_width); rep.HANDLER(date_width_).on_with(date_width);
rep.HANDLER(account_width_).on_with(account_width); if (! rep.HANDLER(payee_width_).specified)
rep.HANDLER(amount_width_).on_with(amount_width); rep.HANDLER(payee_width_).on_with(payee_width);
rep.HANDLER(total_width_).on_with(total_width); if (! rep.HANDLER(account_width_).specified)
rep.HANDLER(account_width_).on_with(account_width);
if (! rep.HANDLER(amount_width_).specified)
rep.HANDLER(amount_width_).on_with(amount_width);
if (! rep.HANDLER(total_width_).specified)
rep.HANDLER(total_width_).on_with(total_width);
} }
} }

View file

@ -565,10 +565,15 @@ public:
OPTION_(report_t, wide, DO() { // -w OPTION_(report_t, wide, DO() { // -w
parent->HANDLER(date_width_).on_with(9L); parent->HANDLER(date_width_).on_with(9L);
parent->HANDLER(date_width_).specified = true;
parent->HANDLER(payee_width_).on_with(35L); parent->HANDLER(payee_width_).on_with(35L);
parent->HANDLER(payee_width_).specified = true;
parent->HANDLER(account_width_).on_with(39L); parent->HANDLER(account_width_).on_with(39L);
parent->HANDLER(account_width_).specified = true;
parent->HANDLER(amount_width_).on_with(22L); parent->HANDLER(amount_width_).on_with(22L);
parent->HANDLER(amount_width_).specified = true;
parent->HANDLER(total_width_).on_with(22L); parent->HANDLER(total_width_).on_with(22L);
parent->HANDLER(total_width_).specified = true;
}); });
OPTION_(report_t, yearly, DO() { // -Y OPTION_(report_t, yearly, DO() { // -Y
@ -576,20 +581,25 @@ public:
}); });
OPTION__(report_t, date_width_, OPTION__(report_t, date_width_,
CTOR(report_t, date_width_) { on_with(9L); } bool specified;
DO_(args) { value = args[0].to_long(); }); CTOR(report_t, date_width_) { on_with(9L); specified = false; }
DO_(args) { value = args[0].to_long(); specified = true; });
OPTION__(report_t, payee_width_, OPTION__(report_t, payee_width_,
CTOR(report_t, payee_width_) { on_with(20L); } bool specified;
DO_(args) { value = args[0].to_long(); }); CTOR(report_t, payee_width_) { on_with(20L); specified = false; }
DO_(args) { value = args[0].to_long(); specified = true; });
OPTION__(report_t, account_width_, OPTION__(report_t, account_width_,
CTOR(report_t, account_width_) { on_with(23L); } bool specified;
DO_(args) { value = args[0].to_long(); }); CTOR(report_t, account_width_) { on_with(23L); specified = false; }
DO_(args) { value = args[0].to_long(); specified = true; });
OPTION__(report_t, amount_width_, OPTION__(report_t, amount_width_,
CTOR(report_t, amount_width_) { on_with(12L); } bool specified;
DO_(args) { value = args[0].to_long(); }); CTOR(report_t, amount_width_) { on_with(12L); specified = false; }
DO_(args) { value = args[0].to_long(); specified = true; });
OPTION__(report_t, total_width_, OPTION__(report_t, total_width_,
CTOR(report_t, total_width_) { on_with(12L); } bool specified;
DO_(args) { value = args[0].to_long(); }); CTOR(report_t, total_width_) { on_with(12L); specified = false; }
DO_(args) { value = args[0].to_long(); specified = true; });
}; };
} // namespace ledger } // namespace ledger