Files
taskwarrior-2.x/src/interactive.cpp
Paul Beckingham 0f5a4434ff Bug #511
- Fixed bug #511, which caused display problem on Cygwin when colored output
  used the full width of the terminal.  The 'avoidlastcolumn' configuration
  variable forces taskwarrior to never use the last column.
2011-05-30 10:21:50 -04:00

104 lines
2.9 KiB
C++

////////////////////////////////////////////////////////////////////////////////
// taskwarrior - a command line task list manager.
//
// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
// All rights reserved.
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 2 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the
//
// Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor,
// Boston, MA
// 02110-1301
// USA
//
////////////////////////////////////////////////////////////////////////////////
#include <sstream>
#include <stdio.h>
#include <sys/ioctl.h>
#include <Context.h>
#include <main.h>
#include <i18n.h>
#include <cmake.h>
////////////////////////////////////////////////////////////////////////////////
int Context::getWidth ()
{
// Determine window size.
int width = config.getInteger ("defaultwidth");
// A zero width value means 'infinity', which is approximated here by 2^16.
if (width == 0)
return 65536;
if (config.getBoolean ("detection"))
{
if (terminal_width == 0 &&
terminal_height == 0)
{
unsigned short buff[4];
if (ioctl (fileno(stdout), TIOCGWINSZ, &buff) != -1)
{
terminal_height = buff[0];
terminal_width = buff[1];
std::stringstream out;
out << "Context::getWidth: determined width of " << terminal_width << " characters";
debug (out.str ());
}
}
width = terminal_width;
// Ncurses does this, and perhaps we need to as well, to avoid a problem on
// Cygwin where the display goes right up to the terminal width, and causes
// and odd color wrapping problem.
if (config.getBoolean ("avoidlastcolumn"))
--width;
}
return width;
}
////////////////////////////////////////////////////////////////////////////////
int Context::getHeight ()
{
int height = 24;
if (config.getBoolean ("detection"))
{
if (terminal_width == 0 &&
terminal_height == 0)
{
unsigned short buff[4];
if (ioctl (fileno(stdout), TIOCGWINSZ, &buff) != -1)
{
terminal_height = buff[0];
terminal_width = buff[1];
std::stringstream out;
out << "Context::getWidth: determined height of " << terminal_height << " characters";
debug (out.str ());
}
}
height = terminal_height;
}
return height;
}
////////////////////////////////////////////////////////////////////////////////