mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-10 09:19:01 +00:00
Changed: #1051 Fixed some display problems
This commit is contained in:
parent
28800dcda6
commit
1347527272
1 changed files with 36 additions and 24 deletions
|
@ -78,40 +78,54 @@ void printCheck(const std::string &str)
|
||||||
|
|
||||||
void printDownload(const std::string &str)
|
void printDownload(const std::string &str)
|
||||||
{
|
{
|
||||||
static uint previousLength = 0;
|
static char spaces[80];
|
||||||
|
|
||||||
static const uint maxLength = 160;
|
uint maxLength = 80;
|
||||||
static char spaces[maxLength];
|
|
||||||
|
// 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;
|
uint length = 0;
|
||||||
|
|
||||||
if (useUtf8)
|
if (useUtf8)
|
||||||
{
|
{
|
||||||
ucstring utf8Str;
|
ucstring ucstr;
|
||||||
utf8Str.fromUtf8(str);
|
ucstr.fromUtf8(nstr);
|
||||||
length = (uint)utf8Str.length();
|
length = (uint)ucstr.length();
|
||||||
|
if (length > maxLength)
|
||||||
|
{
|
||||||
|
ucstr = ucstr.luabind_substr(length - maxLength - 3);
|
||||||
|
nstr = std::string("...") + ucstr.toUtf8();
|
||||||
|
length = maxLength;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
length = (uint)str.length();
|
length = (uint)nstr.length();
|
||||||
}
|
if (length > maxLength)
|
||||||
|
|
||||||
sint diff = length - previousLength;
|
|
||||||
|
|
||||||
if (diff > 0 && length < maxLength)
|
|
||||||
{
|
{
|
||||||
memset(spaces, ' ', length);
|
nstr = std::string("...") + nstr.substr(length - maxLength - 3);
|
||||||
spaces[length] = '\0';
|
length = maxLength;
|
||||||
|
|
||||||
// "erase" previous line
|
|
||||||
printf("%s\r", spaces);
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add padding with spaces
|
||||||
|
memset(spaces, ' ', maxLength);
|
||||||
|
spaces[maxLength - length] = '\0';
|
||||||
|
|
||||||
// display download in purple
|
// display download in purple
|
||||||
if (useEsc)
|
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
|
else
|
||||||
{
|
{
|
||||||
|
@ -120,7 +134,7 @@ void printDownload(const std::string &str)
|
||||||
SetConsoleTextAttribute(hStdout, FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_INTENSITY);
|
SetConsoleTextAttribute(hStdout, FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_INTENSITY);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
printf("%s\r", str.c_str());
|
printf("%s%s\r", nstr.c_str(), spaces);
|
||||||
|
|
||||||
#ifdef NL_OS_WINDOWS
|
#ifdef NL_OS_WINDOWS
|
||||||
if (hStdout != INVALID_HANDLE_VALUE && hStdout)
|
if (hStdout != INVALID_HANDLE_VALUE && hStdout)
|
||||||
|
@ -129,8 +143,6 @@ void printDownload(const std::string &str)
|
||||||
}
|
}
|
||||||
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
previousLength = length;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
|
Loading…
Reference in a new issue