summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-02-19 14:43:04 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-02-19 14:44:28 -0400
commit9f963bda38b4d9d39ff376935d34ca30cbd55109 (patch)
tree7a94aecc476438fd622e35c4fda2a14b0c7c8e71 /src
parent5b897a12fc6df24fe6f7a93e7f0aa5bd7b709d23 (diff)
downloadfork-ledger-9f963bda38b4d9d39ff376935d34ca30cbd55109.tar.gz
fork-ledger-9f963bda38b4d9d39ff376935d34ca30cbd55109.tar.bz2
fork-ledger-9f963bda38b4d9d39ff376935d34ca30cbd55109.zip
Auto-size register report based on COLUMNS
Diffstat (limited to 'src')
-rw-r--r--src/global.cc36
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[])