instrumentation/hrktorrent: add PrintStatusStream function in core.cppp - moved print...
authorRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Wed, 11 Aug 2010 16:56:50 +0000 (19:56 +0300)
committerRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Wed, 11 Aug 2010 16:56:50 +0000 (19:56 +0300)
instrumentation/hrktorrent/core.cpp

index f06f403..8002a1d 100644 (file)
@@ -32,7 +32,32 @@ GetETA(libtorrent::size_type done, libtorrent::size_type wanted, libtorrent::siz
        else\r
                return 0;\r
 }\r
-       \r
+\r
+static void\r
+PrintStatusStream(std::stringstream &output, int columns, int stdout_is_tty)\r
+{\r
+       s_output = output.str();\r
+\r
+       if (stdout_is_tty) {\r
+               if(s.length() > columns) {\r
+                       s.resize(columns - 3);\r
+                       s.append("..");\r
+               }\r
+               else if(s.length() < columns) {\r
+                       for(int i = 0; i < s.length() - columns; i++)\r
+                               s.append(" ");\r
+               }\r
+       }\r
+\r
+       if (stdout_is_tty) {\r
+               std::cout << s_output.c_str() << "\r";\r
+       }\r
+       else {\r
+               std::cout << s_output.c_str() << std::endl;\r
+       }\r
+\r
+       std::cout.flush();\r
+}\r
 \r
 void*\r
 CCore::StatusLoop(void* data)\r
@@ -65,7 +90,6 @@ CCore::StatusLoop(void* data)
                columns = ws.ws_col;\r
        }\r
 \r
-\r
        while(Core->isRunning()) {\r
                if(Settings->GetI("forcereannounce") > 0 && loopcount >= Settings->GetI("forcereannounce")*60) {\r
                        loopcount = 0;\r
@@ -109,27 +133,8 @@ CCore::StatusLoop(void* data)
                        eta -= (eta/60)*60;\r
                }\r
                output << eta << "s";\r
-               s_output = output.str();\r
 \r
-               if (stdout_is_tty) {\r
-                       if(s_output.length() > columns) {\r
-                               s_output.resize(columns - 3);\r
-                               s_output.append("..");\r
-                       }\r
-                       else if(s_output.length() < columns) {\r
-                               for(int i = 0; i < s_output.length() - columns; i++)\r
-                                       s_output.append(" ");\r
-                       }\r
-               }\r
-               if (stdout_is_tty) {\r
-                       std::cout << s_output.c_str() << "\r";\r
-               }\r
-               else {\r
-                       std::cout << s_output.c_str() << std::endl;\r
-               }\r
-\r
-       \r
-               std::cout.flush();\r
+               PrintStatusStream(output, columns, stdout_is_tty);\r
                output.str("");\r
 \r
                sleep(1);\r