Author: niels
Date: Mon May 26 19:20:37 2014
New Revision: 9461

URL: http://svn.gna.org/viewcvs/service-tech?rev=9461&view=rev
Log:
* made progress bar more portable


Modified:
    trunk/lola2/src/InputOutput/Reporter.cc
    trunk/lola2/src/InputOutput/Reporter.h

Modified: trunk/lola2/src/InputOutput/Reporter.cc
URL: 
http://svn.gna.org/viewcvs/service-tech/trunk/lola2/src/InputOutput/Reporter.cc?rev=9461&r1=9460&r2=9461&view=diff
==============================================================================
--- trunk/lola2/src/InputOutput/Reporter.cc     (original)
+++ trunk/lola2/src/InputOutput/Reporter.cc     Mon May 26 19:20:37 2014
@@ -117,7 +117,7 @@
     return String(res);
 }
 
-void ReporterSocket::bar(int, int) const
+void ReporterSocket::bar(const unsigned int, const unsigned int) const
 {
     return;
 }
@@ -292,11 +292,19 @@
     return String(res);
 }
 
-void ReporterStream::bar(int i, int n) const
-{
+/*!
+\note Taken from 
http://www.rosshemsley.co.uk/2011/02/creating-a-progress-bar-in-c-or-any-other-console-app/
+
+\param i  The number of already processed elements
+\param n  The total number of elements to be processed.
+*/
+void ReporterStream::bar(const unsigned int i, const unsigned int n) const
+{
+    assert(i <= n);
+    
     // useColor is a variable that indicates whether we work in a terminal
     // if not, we skip the display of the progress bar
-    if (!isatty(fileno(stderr)))
+    if (not useColor)
     {
         return;
     }
@@ -331,7 +339,8 @@
     }
     else
     {
-        fprintf(stderr, "\033[F\033[J");
+        // move cursor up and clear line
+        fprintf(stderr, "\033[1A\033[2K");
     }
 
     // if the progress bar is at 100%, reset the bar
@@ -409,7 +418,7 @@
     return String(res);
 }
 
-void ReporterSilent::bar(int, int) const
+void ReporterSilent::bar(const unsigned int, const unsigned int) const
 {
     return;
 }

Modified: trunk/lola2/src/InputOutput/Reporter.h
URL: 
http://svn.gna.org/viewcvs/service-tech/trunk/lola2/src/InputOutput/Reporter.h?rev=9461&r1=9460&r2=9461&view=diff
==============================================================================
--- trunk/lola2/src/InputOutput/Reporter.h      (original)
+++ trunk/lola2/src/InputOutput/Reporter.h      Mon May 26 19:20:37 2014
@@ -77,7 +77,7 @@
     virtual void abort(errorcode_t) const __attribute__((noreturn)) = 0;
 
     /// display a progress bar
-    virtual void bar(int, int) const = 0;
+    virtual void bar(const unsigned int, const unsigned int) const = 0;
 };
 
 
@@ -111,7 +111,7 @@
     String markup(markup_t, const char *, ...) const;
 
     /// display a progress bar
-    void bar(int, int) const;
+    void bar(const unsigned int, const unsigned int) const;
 };
 
 
@@ -196,7 +196,7 @@
     String markup(markup_t, const char *, ...) const;
 
     /// display a progress bar
-    void bar(int, int) const;
+    void bar(const unsigned int, const unsigned int) const;
 };
 
 /*!
@@ -218,5 +218,5 @@
     String markup(markup_t, const char *, ...) const;
 
     /// display a progress bar
-    void bar(int, int) const;
-};
+    void bar(const unsigned int, const unsigned int) const;
+};


-- 
You received this e-mail, because you subscribed the mailing list 
"service-tech-commits" which will forward you any e-mail addressed to 
[email protected]. If you want to unsubscribe or make any changes to 
your subscription, please go to
https://mail.gna.org/listinfo/service-tech-commits.

Reply via email to