diff options
-rw-r--r-- | src/report.cc | 42 | ||||
-rw-r--r-- | src/report.h | 19 |
2 files changed, 52 insertions, 9 deletions
diff --git a/src/report.cc b/src/report.cc index 4a7b105f..2189812b 100644 --- a/src/report.cc +++ b/src/report.cc @@ -93,6 +93,33 @@ void report_t::normalize_options(const string& verb) start_of_week = *weekday; } + long meta_width = -1; + + if (! HANDLED(prepend_format_) && HANDLED(meta_)) { + if (! HANDLED(meta_width_)) { + string::size_type i = HANDLER(meta_).str().find(':'); + if (i != string::npos) { + HANDLED(meta_width_).on_with + (string("?normalize"), + lexical_cast<long>(string(HANDLER(meta_).str(), i + 1))); + HANDLED(meta_).on(string("?normalize"), + string(HANDLER(meta_).str(), 0, i)); + } + } + if (HANDLED(meta_width_)) { + HANDLER(prepend_format_).on + (string("?normalize"), + string("%(justify(truncated(tag(\"") + + HANDLER(meta_).str() + "\"), " + + HANDLED(meta_width_).value.to_string() + " - 1), " + + HANDLED(meta_width_).value.to_string() + "))"); + meta_width = HANDLED(meta_width_).value.to_long(); + } else { + HANDLER(prepend_format_).on(string("?normalize"), string("%(tag(\"") + + HANDLER(meta_).str() + "\"))"); + } + } + if (verb == "print" || verb == "xact" || verb == "dump") { HANDLER(related).on_only(string("?normalize")); HANDLER(related_all).on_only(string("?normalize")); @@ -165,6 +192,9 @@ void report_t::normalize_options(const string& verb) else cols = 80L; + if (meta_width > 0) + cols -= meta_width; + if (cols > 0) { DEBUG("auto.columns", "cols = " << cols); @@ -187,11 +217,11 @@ void report_t::normalize_options(const string& verb) HANDLER(total_width_).value.to_long() : amount_width); - DEBUG("auto.columns", "date_width = " << date_width); - DEBUG("auto.columns", "payee_width = " << payee_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); + DEBUG("auto.columns", "amount_width = " << amount_width); + DEBUG("auto.columns", "total_width = " << total_width); if (! HANDLER(date_width_).specified && ! HANDLER(payee_width_).specified && @@ -207,6 +237,8 @@ void report_t::normalize_options(const string& verb) } } + if (! HANDLED(meta_width_)) + HANDLER(meta_width_).on_with(string("?normalize"), 0L); if (! HANDLER(date_width_).specified) HANDLER(date_width_).on_with(string("?normalize"), date_width); if (! HANDLER(payee_width_).specified) @@ -862,6 +894,8 @@ option_t<report_t> * report_t::lookup_option(const char * p) case 'm': OPT(market); else OPT(monthly); + else OPT(meta_); + else OPT(meta_width_); break; case 'n': OPT_CH(collapse); diff --git a/src/report.h b/src/report.h index 682c2414..50071940 100644 --- a/src/report.h +++ b/src/report.h @@ -264,6 +264,7 @@ public: HANDLER(lots).report(out); HANDLER(lots_actual).report(out); HANDLER(market).report(out); + HANDLER(meta_).report(out); HANDLER(monthly).report(out); HANDLER(no_total).report(out); HANDLER(now_).report(out); @@ -312,6 +313,7 @@ public: HANDLER(weekly).report(out); HANDLER(wide).report(out); HANDLER(yearly).report(out); + HANDLER(meta_width_).report(out); HANDLER(date_width_).report(out); HANDLER(payee_width_).report(out); HANDLER(account_width_).report(out); @@ -619,6 +621,8 @@ public: .set_expr(string("--market"), "market(total_expr, date, exchange)"); }); + OPTION(report_t, meta_); + OPTION_(report_t, monthly, DO() { // -M parent->HANDLER(period_).on(string("--monthly"), "monthly"); }); @@ -776,12 +780,13 @@ public: " %(ansify_if(justify(truncated(account, account_width, abbrev_len), " " account_width), blue if color))" " %(justify(scrub(display_amount), amount_width, " - " 3 + date_width + payee_width + account_width + amount_width, " - " true, color))" + " 3 + meta_width + date_width + payee_width + account_width" + " + amount_width, true, color))" " %(justify(scrub(display_total), total_width, " - " 4 + date_width + payee_width + account_width + amount_width " - " + total_width, true, color))\n%/" - "%(justify(\" \", 2 + date_width + payee_width))%$3 %$4 %$5\n"); + " 4 + meta_width + date_width + payee_width + account_width" + " + amount_width + total_width, true, color))\n%/" + "%(justify(\" \", 2 + date_width + payee_width))" + "%$3 %$4 %$5\n"); }); OPTION(report_t, related); // -r @@ -891,6 +896,10 @@ public: parent->HANDLER(period_).on(string("--yearly"), "yearly"); }); + OPTION__(report_t, meta_width_, + bool specified; + CTOR(report_t, meta_width_) { specified = false; } + DO_(args) { value = args[1].to_long(); specified = true; }); OPTION__(report_t, date_width_, bool specified; CTOR(report_t, date_width_) { specified = false; } |