diff options
author | Stefano Zacchiroli <zack@upsilon.cc> | 2014-10-13 23:15:23 +0200 |
---|---|---|
committer | Martin Michlmayr <tbm@cyrius.com> | 2014-10-13 17:15:56 -0400 |
commit | 56976a127c081a6a008c81966360003a8711a319 (patch) | |
tree | b27188861374e243746aaf561a0a9cf480989fbb /src/report.cc | |
parent | 6b2520cc49edf4d167bec10850b832c308ebf9a3 (diff) | |
download | fork-ledger-56976a127c081a6a008c81966360003a8711a319.tar.gz fork-ledger-56976a127c081a6a008c81966360003a8711a319.tar.bz2 fork-ledger-56976a127c081a6a008c81966360003a8711a319.zip |
make --columns default to terminal width, as returned by ioctl()
If set, the COLUMNS environment variable will take precedence over terminal
width. However, please note that COLUMNS is usually *not* exported by shells to
child processes, so in most cases COLUMNS will be undefined for ledger---hence
the motivation for this change.
Terminal width is queried using ioctl() on stdin. For the sake of portability
the querying is done only on platform where ioctl() is detected as supported at
compile-time.
Diffstat (limited to 'src/report.cc')
-rw-r--r-- | src/report.cc | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/report.cc b/src/report.cc index 7bb79bd1..a05a57d9 100644 --- a/src/report.cc +++ b/src/report.cc @@ -181,10 +181,17 @@ void report_t::normalize_options(const string& verb) } long cols = 0; +#if HAVE_IOCTL + struct winsize ws; +#endif if (HANDLED(columns_)) cols = lexical_cast<long>(HANDLER(columns_).value); else if (const char * columns = std::getenv("COLUMNS")) cols = lexical_cast<long>(columns); +#if HAVE_IOCTL + else if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) != -1) + cols = ws.ws_col; +#endif else cols = 80L; |