2008-03-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Now download line is printed nicely with no garbage at the end 
of
	line. I use ioctl to get the columns of terminal.
	If stdout is redirected to another device, instead of carriage 
return,
	end of line '\n' character is used. This is feature 
request#1909659
	* src/ConsoleStatCalc.cc (calculateStat)
pull/1/head
Tatsuhiro Tsujikawa 2008-03-11 16:18:33 +00:00
parent 102ce611d1
commit 34df2cc416
2 changed files with 24 additions and 4 deletions

View File

@ -1,3 +1,11 @@
2008-03-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Now download line is printed nicely with no garbage at the end of
line. I use ioctl to get the columns of terminal.
If stdout is redirected to another device, instead of carriage return,
end of line '\n' character is used. This is feature request#1909659
* src/ConsoleStatCalc.cc (calculateStat)
2008-03-11 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Included a2time.h

View File

@ -43,6 +43,9 @@
#ifdef ENABLE_BITTORRENT
# include "BtContext.h"
#endif // ENABLE_BITTORRENT
#include <termios.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <iomanip>
#include <iostream>
@ -57,9 +60,14 @@ ConsoleStatCalc::calculateStat(const RequestGroupManHandle& requestGroupMan,
return;
}
_cp.reset();
std::cout << "\r ";
std::cout << "\r";
bool isTTY = isatty(STDOUT_FILENO) == 1;
if(isTTY) {
struct winsize size;
if(ioctl(STDOUT_FILENO, TIOCGWINSZ, &size) == -1) {
size.ws_col = 80;
}
std::cout << '\r' << std::setw(size.ws_col) << ' ' << '\r';
}
if(requestGroupMan->countRequestGroup() > 0) {
RequestGroupHandle firstRequestGroup = requestGroupMan->getRequestGroup(0);
TransferStat stat = firstRequestGroup->calculateStat();
@ -177,7 +185,11 @@ ConsoleStatCalc::calculateStat(const RequestGroupManHandle& requestGroupMan,
}
}
#endif // ENABLE_MESSAGE_DIGEST
std::cout << std::flush;
if(isTTY) {
std::cout << std::flush;
} else {
std::cout << std::endl;
}
}
} // namespace aria2