summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@rei2.9hal>2011-11-19 18:34:42 +0100
committercinap_lenrek <cinap_lenrek@rei2.9hal>2011-11-19 18:34:42 +0100
commitf3a21be163d919490f6e4eab464b3146228f3661 (patch)
treea47537b89160fea556b6986f156a7b33b56a95ac
parent15380244133d7b6f4f3ca84032e147ed460e5c22 (diff)
downloadplan9front-f3a21be163d919490f6e4eab464b3146228f3661.tar.xz
mothra: use tput to display download speed
-rw-r--r--sys/src/cmd/mothra/mothra.c35
1 files changed, 11 insertions, 24 deletions
diff --git a/sys/src/cmd/mothra/mothra.c b/sys/src/cmd/mothra/mothra.c
index e8d4ba019..82865bc42 100644
--- a/sys/src/cmd/mothra/mothra.c
+++ b/sys/src/cmd/mothra/mothra.c
@@ -528,8 +528,8 @@ char *arg(char *s){
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 @@ void save(int ifd, char *name){
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 @@ void save(int ifd, char *name){
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);