]> Zhao Yanbai Git Server - minix.git/commitdiff
Progress bar prettification
authorBen Gras <ben@minix3.org>
Fri, 12 Aug 2005 12:35:17 +0000 (12:35 +0000)
committerBen Gras <ben@minix3.org>
Fri, 12 Aug 2005 12:35:17 +0000 (12:35 +0000)
commands/simple/progressbar.c

index 3373e9e5025044a41f50af91d531db0e39ccb6b6..164f74a26c003a2233028d73fc1c7ea1d0f5a5da 100755 (executable)
@@ -22,7 +22,7 @@ prettyprogress(long b, long maxb, time_t starttime)
          secremain = (maxb - b) / bpsec;
          minremain = (secremain / 60) % 60;
          hremain = secremain / 3600;
-       len = printf("Remainining: %ld files. ", maxb-b);
+       len = printf("Remaining: %ld files. ", maxb-b);
 
 #if 0
        len += printf("ETA: %d:%02d:%02d ",
@@ -38,7 +38,7 @@ prettyprogress(long b, long maxb, time_t starttime)
        printf("|");
        for(; i < len-2; i++) 
                printf("-");
-       printf("]\n");
+       printf("]\e[K\n");
   } else printf("\n");
 
   return;
@@ -61,13 +61,16 @@ char *argv[];
        for(l = 1; l <= LINES+1; l++) printf("\n");
        printf("\e[A");
        while(fgets(line, sizeof(line), stdin)) {
+               char *nl;
                i++;
                for(l = 0; l <= LINES; l++)  printf("\e[A");
                if(i <= count) prettyprogress(i, count, start);
                else printf("\n");
                printf("\e[M");
                for(l = 0; l < LINES; l++)  printf("\e[B");
-               printf("\r%s\e[A", line);
+               if((nl = strchr(line, '\n'))) *nl = '\0';
+               line[78] = '\0';
+               printf("\r%s\r", line);
        }
 
        printf("\nDone.\e[K\n");