Changed: #1051 Fixed some display problems

This commit is contained in:
kervala 2010-10-10 23:12:37 +02:00
parent 30f5782a1d
commit d5a512b55b

View file

@ -78,40 +78,54 @@ void printCheck(const std::string &str)
void printDownload(const std::string &str)
{
static uint previousLength = 0;
static char spaces[80];
static const uint maxLength = 160;
static char spaces[maxLength];
uint maxLength = 80;
// if "COLUMNS" environnement variable is defined, use it
if (getenv("COLUMNS"))
{
NLMISC::fromString(std::string(getenv("COLUMNS")), maxLength);
}
// only use 79 columns to not wrap
--maxLength;
// temporary modified string
std::string nstr = str;
uint length = 0;
if (useUtf8)
{
ucstring utf8Str;
utf8Str.fromUtf8(str);
length = (uint)utf8Str.length();
ucstring ucstr;
ucstr.fromUtf8(nstr);
length = (uint)ucstr.length();
if (length > maxLength)
{
ucstr = ucstr.luabind_substr(length - maxLength - 3);
nstr = std::string("...") + ucstr.toUtf8();
length = maxLength;
}
}
else
{
length = (uint)str.length();
}
sint diff = length - previousLength;
if (diff > 0 && length < maxLength)
length = (uint)nstr.length();
if (length > maxLength)
{
memset(spaces, ' ', length);
spaces[length] = '\0';
// "erase" previous line
printf("%s\r", spaces);
fflush(stdout);
nstr = std::string("...") + nstr.substr(length - maxLength - 3);
length = maxLength;
}
}
// add padding with spaces
memset(spaces, ' ', maxLength);
spaces[maxLength - length] = '\0';
// display download in purple
if (useEsc)
{
printf("\033[1;35m%s\033[0m\r", str.c_str());
printf("\033[1;35m%s%s\033[0m\r", nstr.c_str(), spaces);
}
else
{
@ -120,7 +134,7 @@ void printDownload(const std::string &str)
SetConsoleTextAttribute(hStdout, FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_INTENSITY);
#endif
printf("%s\r", str.c_str());
printf("%s%s\r", nstr.c_str(), spaces);
#ifdef NL_OS_WINDOWS
if (hStdout != INVALID_HANDLE_VALUE && hStdout)
@ -129,8 +143,6 @@ void printDownload(const std::string &str)
}
fflush(stdout);
previousLength = length;
}
int main(int argc, char *argv[])