ref: df5e6592517971f3028e99ad62e250573b621822
parent: 88e161c34664af8571cd6242b67135ba4eb64450
author: cinap_lenrek <cinap_lenrek@rei2.9hal>
date: Sat Nov 19 13:34:42 EST 2011
mothra: use tput to display download speed
--- a/sys/src/cmd/mothra/mothra.c
+++ b/sys/src/cmd/mothra/mothra.c
@@ -528,8 +528,8 @@
return s;
}
void save(int ifd, char *name){- char buf[4096];
- int ofd;
+ char buf[NNAME];
+ int cfd, ofd;
if(ifd < 0){ message("save: %s: %r", name);return;
@@ -539,17 +539,18 @@
message("save: %s: %r", name);return;
}
- switch(rfork(RFNOTEG|RFNAMEG|RFFDG|RFPROC|RFNOWAIT)){+ switch(rfork(RFNOTEG|RFNAMEG|RFFDG|RFMEM|RFPROC|RFNOWAIT)){case -1:
message("Can't fork: %r");break;
case 0:
+ dup(ifd, 0);
+ close(ifd);
+ dup(ofd, 1);
+ close(ofd);
snprint(buf, sizeof(buf), "-pid %d", getpid());
if(newwindow(buf) != -1){- int blk, cfd, n;
- vlong off;
-
- close(1); open("/dev/cons", OWRITE);+ close(2); open("/dev/cons", OWRITE); if((cfd = open("/dev/label", OWRITE)) >= 0){fprint(cfd, "save %s", name);
close(cfd);
@@ -558,24 +559,10 @@
fprint(cfd, "scroll\n");
close(cfd);
}
- off = 0;
- blk = 0;
- werrstr("");- for(;;){- if((blk++ % 4) == 0){- if(off > 0)
- print("\n");- print("%s: ", name);- }
- if((n=read(ifd, buf, sizeof(buf))) <= 0)
- break;
- if(write(ofd, buf, n) != n)
- break;
- off += n;
- print("%lldK... ", off/1024);- }
- print("%r\n");+ fprint(2, "save %s...\n", name);
+ execl("/bin/tput", "tput", "-p", nil);}
+ execl("/bin/cat", "cat", nil);exits(0);
}
close(ifd);
--
⑨