gnokii-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[patch] nk6510.c: Advance progress indicator in place


From: Yoni Rabkin
Subject: [patch] nk6510.c: Advance progress indicator in place
Date: Fri, 21 Mar 2008 15:18:35 +0200
User-agent: Gnus/5.110007 (No Gnus v0.7) Emacs/23.0.50 (gnu/linux)

I've attached two patches which do the same thing in a different way,
both against today's CVS.

gnokii-cleaner-progress-in-place.patch: Uses the "\r" terminal escape,
which is only 99.9% portable. wget also uses "\r" aka ^M, so it can't be
*that* bad.

gnokii-progress-in-place.patch: Kludgy and flickers, since it uses the
"\b" terminal escape. But every terminal that ever existed should
support it.

Index: nk6510.c
===================================================================
RCS file: /sources/gnokii/gnokii/common/phones/nk6510.c,v
retrieving revision 1.258
diff -u -r1.258 nk6510.c
--- nk6510.c    3 Feb 2008 15:24:37 -0000       1.258
+++ nk6510.c    21 Mar 2008 12:33:46 -0000
@@ -1706,7 +1706,7 @@
 
        /* Get the data */
        while (data->file->togo > 0) {
-               int progress;
+               int progress, prev_progress = 0;
 
                memcpy(req3+4, data->file->id, NK6510_FILE_ID_LENGTH);
                i = data->file->file_length - data->file->togo;
@@ -1726,8 +1726,12 @@
                if (err != GN_ERR_NONE)
                        return err;
                progress = 100 * (data->file->file_length - data->file->togo) / 
data->file->file_length;
-               fprintf(stderr, _("Progress: %d%% completed\n"), progress);
+               if (progress != prev_progress) {
+                       fprintf(stderr, _("\rProgress: %d%% completed"), 
progress);
+               }
+               prev_progress = progress;
        }
+       fprintf(stderr, _("\n"));
        
        /* Finish the transfer */
        memcpy(req4+4, data->file->id, NK6510_FILE_ID_LENGTH);
Index: nk6510.c
===================================================================
RCS file: /sources/gnokii/gnokii/common/phones/nk6510.c,v
retrieving revision 1.258
diff -u -r1.258 nk6510.c
--- nk6510.c    3 Feb 2008 15:24:37 -0000       1.258
+++ nk6510.c    21 Mar 2008 11:50:09 -0000
@@ -1706,7 +1706,7 @@
 
        /* Get the data */
        while (data->file->togo > 0) {
-               int progress;
+               int progress, erase, prev_progress = 0;
 
                memcpy(req3+4, data->file->id, NK6510_FILE_ID_LENGTH);
                i = data->file->file_length - data->file->togo;
@@ -1726,8 +1726,13 @@
                if (err != GN_ERR_NONE)
                        return err;
                progress = 100 * (data->file->file_length - data->file->togo) / 
data->file->file_length;
-               fprintf(stderr, _("Progress: %d%% completed\n"), progress);
+               if (progress != prev_progress) {
+                       for (erase=0; erase<24; erase++) fprintf(stderr, 
_("\b"));
+                       fprintf(stderr, _("Progress: %d%% completed"), 
progress);
+               }
+               prev_progress = progress;
        }
+       fprintf(stderr, _("\n"));
        
        /* Finish the transfer */
        memcpy(req4+4, data->file->id, NK6510_FILE_ID_LENGTH);
-- 
   "Cut your own wood and it will warm you twice"

reply via email to

[Prev in Thread] Current Thread [Next in Thread]