Made getTerminalWidth detect if it is running in a terminal before trying to get the width.

This commit is contained in:
Steffan Byrne 2016-12-02 21:26:37 -05:00
parent d11f376030
commit 5822bce376

View File

@ -378,10 +378,17 @@ void Util::setFilePermissions(const boost::filesystem::path& path, const boost::
} }
int Util::getTerminalWidth() int Util::getTerminalWidth()
{
int width;
if(isatty(STDOUT_FILENO))
{ {
struct winsize w; struct winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
return static_cast<int>(w.ws_col); width = static_cast<int>(w.ws_col);
}
else
width = 10000;//Something sufficiently big
return width;
} }