diff options
author | John Wiegley <johnw@newartisans.com> | 2009-10-29 00:23:57 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-10-29 00:23:57 -0400 |
commit | 2b2ffb7787df634aee1681dac7be48e986d34337 (patch) | |
tree | 8e93df310b06f56892341f76d024de4ebe7d3881 | |
parent | 52433e56e562976887325ce48a6271abb82a89aa (diff) | |
download | fork-ledger-2b2ffb7787df634aee1681dac7be48e986d34337.tar.gz fork-ledger-2b2ffb7787df634aee1681dac7be48e986d34337.tar.bz2 fork-ledger-2b2ffb7787df634aee1681dac7be48e986d34337.zip |
If isatty is available, no colors/pager for non-ttys
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/global.cc | 8 | ||||
-rw-r--r-- | src/report.h | 17 |
3 files changed, 24 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac index ad1c4b37..69fe0e1e 100644 --- a/configure.ac +++ b/configure.ac @@ -352,7 +352,7 @@ AC_STRUCT_TM #AC_FUNC_MKTIME #AC_FUNC_STAT #AC_FUNC_STRFTIME -AC_CHECK_FUNCS([access realpath getpwuid getpwnam]) +AC_CHECK_FUNCS([access realpath getpwuid getpwnam isatty]) # Pepare the Makefiles AC_CONFIG_FILES([Makefile po/Makefile.in intl/Makefile]) diff --git a/src/global.cc b/src/global.cc index 19cab1c8..6c8cc547 100644 --- a/src/global.cc +++ b/src/global.cc @@ -418,8 +418,14 @@ void global_scope_t::normalize_report_options(const string& verb) report_t& rep(report()); - if (! rep.HANDLED(no_color)) +#ifdef HAVE_ISATTY + if (! rep.HANDLED(no_color) && isatty(STDOUT_FILENO)) rep.HANDLER(color).on_only(string("?normalize")); + if (rep.HANDLED(color) && ! isatty(STDOUT_FILENO)) + rep.HANDLER(color).off(); + if (rep.HANDLED(pager_) && ! isatty(STDOUT_FILENO)) + rep.HANDLER(pager_).off(); +#endif // jww (2009-02-09): These globals are a hack, but hard to avoid. item_t::use_effective_date = (rep.HANDLED(effective) && diff --git a/src/report.h b/src/report.h index 294af19a..22008af6 100644 --- a/src/report.h +++ b/src/report.h @@ -630,10 +630,11 @@ public: OPTION(report_t, output_); // -o +#ifdef HAVE_ISATTY OPTION__ (report_t, pager_, CTOR(report_t, pager_) { - if (! std::getenv("PAGER")) { + if (! std::getenv("PAGER") && isatty(STDOUT_FILENO)) { bool have_less = false; if (exists(path("/opt/local/bin/less")) || exists(path("/usr/local/bin/less")) || @@ -654,6 +655,20 @@ public: else option_t<report_t>::on_with(whence, text); }); +#else // HAVE_ISATTY + OPTION__ + (report_t, pager_, + CTOR(report_t, pager_) { + } + virtual void on_with(const optional<string>& whence, const value_t& text) { + string cmd(text.to_string()); + if (cmd == "" || cmd == "false" || cmd == "off" || + cmd == "none" || cmd == "no" || cmd == "disable") + option_t<report_t>::off(); + else + option_t<report_t>::on_with(whence, text); + }); +#endif // HAVE_ISATTY OPTION(report_t, payee_as_account); |