From: Razvan Deaconescu Date: Wed, 11 Aug 2010 16:56:50 +0000 (+0300) Subject: instrumentation/hrktorrent: add PrintStatusStream function in core.cppp - moved print... X-Git-Tag: next-share-m32~15 X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=88866ad29a4f419a2f0c5e5d00beefda358a9cd3;p=cs-p2p-next.git instrumentation/hrktorrent: add PrintStatusStream function in core.cppp - moved print code from StatusLoop function --- diff --git a/instrumentation/hrktorrent/core.cpp b/instrumentation/hrktorrent/core.cpp index f06f403..8002a1d 100644 --- a/instrumentation/hrktorrent/core.cpp +++ b/instrumentation/hrktorrent/core.cpp @@ -32,7 +32,32 @@ GetETA(libtorrent::size_type done, libtorrent::size_type wanted, libtorrent::siz else return 0; } - + +static void +PrintStatusStream(std::stringstream &output, int columns, int stdout_is_tty) +{ + s_output = output.str(); + + if (stdout_is_tty) { + if(s.length() > columns) { + s.resize(columns - 3); + s.append(".."); + } + else if(s.length() < columns) { + for(int i = 0; i < s.length() - columns; i++) + s.append(" "); + } + } + + if (stdout_is_tty) { + std::cout << s_output.c_str() << "\r"; + } + else { + std::cout << s_output.c_str() << std::endl; + } + + std::cout.flush(); +} void* CCore::StatusLoop(void* data) @@ -65,7 +90,6 @@ CCore::StatusLoop(void* data) columns = ws.ws_col; } - while(Core->isRunning()) { if(Settings->GetI("forcereannounce") > 0 && loopcount >= Settings->GetI("forcereannounce")*60) { loopcount = 0; @@ -109,27 +133,8 @@ CCore::StatusLoop(void* data) eta -= (eta/60)*60; } output << eta << "s"; - s_output = output.str(); - if (stdout_is_tty) { - if(s_output.length() > columns) { - s_output.resize(columns - 3); - s_output.append(".."); - } - else if(s_output.length() < columns) { - for(int i = 0; i < s_output.length() - columns; i++) - s_output.append(" "); - } - } - if (stdout_is_tty) { - std::cout << s_output.c_str() << "\r"; - } - else { - std::cout << s_output.c_str() << std::endl; - } - - - std::cout.flush(); + PrintStatusStream(output, columns, stdout_is_tty); output.str(""); sleep(1);