diff options
author | John Wiegley <johnw@newartisans.com> | 2009-02-21 22:04:01 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-02-21 22:04:01 -0400 |
commit | eb4aa8784338dc52730a97654bcd61642b4ff959 (patch) | |
tree | 4e6d3e6a64f8155844a198776fb1cc0bf5683e1c /src/report.cc | |
parent | 8ca91c1196181954e0b3da36110bfe069d2831fe (diff) | |
download | fork-ledger-eb4aa8784338dc52730a97654bcd61642b4ff959.tar.gz fork-ledger-eb4aa8784338dc52730a97654bcd61642b4ff959.tar.bz2 fork-ledger-eb4aa8784338dc52730a97654bcd61642b4ff959.zip |
Added a new --colors option, for terminal fun
The following colors are applied in the balance and register reports:
GREEN To a date, if it occurs in the future
BOLD If a payee name relates to an uncleared entry
BLUE For account names
RED For negative values
Diffstat (limited to 'src/report.cc')
-rw-r--r-- | src/report.cc | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/report.cc b/src/report.cc index 3112a98e..3178755f 100644 --- a/src/report.cc +++ b/src/report.cc @@ -220,6 +220,32 @@ value_t report_t::fn_format_date(call_scope_t& args) return string_value(format_date(args[0].to_date(), args[1].to_string())); } +value_t report_t::fn_ansify_if(call_scope_t& scope) +{ + interactive_t args(scope, "vsb"); + + if (args.get<bool>(2)) { + string color = args.get<string>(1); + std::ostringstream buf; + if (color == "black") buf << "\e[30m"; + else if (color == "red") buf << "\e[31m"; + else if (color == "green") buf << "\e[32m"; + else if (color == "yellow") buf << "\e[33m"; + else if (color == "blue") buf << "\e[34m"; + else if (color == "magenta") buf << "\e[35m"; + else if (color == "cyan") buf << "\e[36m"; + else if (color == "white") buf << "\e[37m"; + else if (color == "bold") buf << "\e[1m"; + else if (color == "underline") buf << "\e[4m"; + else if (color == "blink") buf << "\e[5m"; + buf << args.value_at(0); + buf << "\e[0m"; + return string_value(buf.str()); + } else { + return args.value_at(0); + } +} + namespace { template <class Type = xact_t, class handler_ptr = xact_handler_ptr, @@ -330,8 +356,7 @@ option_t<report_t> * report_t::lookup_option(const char * p) else OPT(amount_); else OPT(amount_data); else OPT(anon); - else OPT(ansi); - else OPT(ansi_invert); + else OPT_ALT(colors, ansi); else OPT(average); else OPT(account_width_); else OPT(amount_width_); @@ -353,6 +378,7 @@ option_t<report_t> * report_t::lookup_option(const char * p) else OPT_ALT(comm_as_account, commodity_as_account); else OPT(collapse); else OPT(collapse_if_zero); + else OPT(colors); else OPT(columns_); else OPT_ALT(basis, cost); else OPT_(current); @@ -492,6 +518,8 @@ expr_t::ptr_op_t report_t::lookup(const string& name) case 'a': if (is_eq(p, "amount_expr")) return MAKE_FUNCTOR(report_t::fn_amount_expr); + else if (is_eq(p, "ansify_if")) + return MAKE_FUNCTOR(report_t::fn_ansify_if); break; case 'c': |