diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/global.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/global.cc b/src/global.cc index f5ebe61a..0ecd1fb8 100644 --- a/src/global.cc +++ b/src/global.cc @@ -395,6 +395,42 @@ void global_scope_t::normalize_report_options(const string& verb) if (rep.HANDLED(period_) && ! rep.HANDLED(sort_all_)) rep.HANDLER(sort_entries_).on_only(); + + long cols = 0; + if (rep.HANDLED(columns_)) + cols = rep.HANDLER(columns_).value.to_long(); + else if (const char * columns = std::getenv("COLUMNS")) + cols = lexical_cast<long>(columns); + + if (cols > 0) { + DEBUG("auto.columns", "cols = " << cols); + + long date_width = rep.HANDLER(date_width_).value.to_long(); + long payee_width = int(double(cols) * 0.263157); + long account_width = int(double(cols) * 0.302631); + long amount_width = int(double(cols) * 0.157894); + long total_width = amount_width; + + DEBUG("auto.columns", "date_width = " << date_width); + DEBUG("auto.columns", "payee_width = " << payee_width); + DEBUG("auto.columns", "account_width = " << account_width); + DEBUG("auto.columns", "amount_width = " << amount_width); + DEBUG("auto.columns", "total_width = " << total_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); + rep.HANDLER(payee_width_).on_with(payee_width); + rep.HANDLER(account_width_).on_with(account_width); + rep.HANDLER(amount_width_).on_with(amount_width); + rep.HANDLER(total_width_).on_with(total_width); + } } void handle_debug_options(int argc, char * argv[]) |