diff options
author | Andy Cedilnik <andy.cedilnik@kitware.com> | 2004-09-16 14:58:56 (GMT) |
---|---|---|
committer | Andy Cedilnik <andy.cedilnik@kitware.com> | 2004-09-16 14:58:56 (GMT) |
commit | 6a4071b5d213c52631fe2e73f6f8f51b40ac2e0b (patch) | |
tree | fb460f476d46ccefbe0107a2ccdd50a1d88f6e0d /Source/kwsys/SystemTools.cxx | |
parent | d349d6ff18c046df2c9f775a22d28f8e9c10fc7d (diff) | |
download | CMake-6a4071b5d213c52631fe2e73f6f8f51b40ac2e0b.zip CMake-6a4071b5d213c52631fe2e73f6f8f51b40ac2e0b.tar.gz CMake-6a4071b5d213c52631fe2e73f6f8f51b40ac2e0b.tar.bz2 |
ENH: Add method to retrieve the terminal width
Diffstat (limited to 'Source/kwsys/SystemTools.cxx')
-rw-r--r-- | Source/kwsys/SystemTools.cxx | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 3f6ee37..1643c16 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -35,6 +35,8 @@ #include <stdlib.h> #include <sys/param.h> #include <sys/wait.h> +#include <sys/ioctl.h> +#include <unistd.h> #endif #if defined(_WIN32) && (defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__)) @@ -1846,6 +1848,38 @@ bool SystemTools::GetLineFromStream(kwsys_ios::istream& is, kwsys_stl::string& l return haveData; } +int SystemTools::GetTerminalWidth() +{ + int width = -1; +#ifndef _WIN32 + struct winsize ws; + char *columns; /* Unix98 environment variable */ + if(ioctl(1, TIOCGWINSZ, &ws) != -1 && ws.ws_col>0 && ws.ws_row>0) + { + width = ws.ws_col; + } + if(!isatty(STDOUT_FILENO)) + { + width = -1; + } + columns = getenv("COLUMNS"); + if(columns && *columns) + { + long t; + char *endptr; + t = strtol(columns, &endptr, 0); + if(endptr && !*endptr && (t>0) && (t<1000)) + { + width = (int)t; + } + } + if ( width < 9 ) + { + width = -1; + } +#endif + return width; +} } // namespace KWSYS_NAMESPACE #if defined(_MSC_VER) && defined(_DEBUG) |