mothra: use tput to display download speed
parent
1538024413
commit
f3a21be163
|
@ -528,8 +528,8 @@ char *arg(char *s){
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
void save(int ifd, char *name){
|
void save(int ifd, char *name){
|
||||||
char buf[4096];
|
char buf[NNAME];
|
||||||
int ofd;
|
int cfd, ofd;
|
||||||
if(ifd < 0){
|
if(ifd < 0){
|
||||||
message("save: %s: %r", name);
|
message("save: %s: %r", name);
|
||||||
return;
|
return;
|
||||||
|
@ -539,17 +539,18 @@ void save(int ifd, char *name){
|
||||||
message("save: %s: %r", name);
|
message("save: %s: %r", name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch(rfork(RFNOTEG|RFNAMEG|RFFDG|RFPROC|RFNOWAIT)){
|
switch(rfork(RFNOTEG|RFNAMEG|RFFDG|RFMEM|RFPROC|RFNOWAIT)){
|
||||||
case -1:
|
case -1:
|
||||||
message("Can't fork: %r");
|
message("Can't fork: %r");
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
|
dup(ifd, 0);
|
||||||
|
close(ifd);
|
||||||
|
dup(ofd, 1);
|
||||||
|
close(ofd);
|
||||||
snprint(buf, sizeof(buf), "-pid %d", getpid());
|
snprint(buf, sizeof(buf), "-pid %d", getpid());
|
||||||
if(newwindow(buf) != -1){
|
if(newwindow(buf) != -1){
|
||||||
int blk, cfd, n;
|
close(2); open("/dev/cons", OWRITE);
|
||||||
vlong off;
|
|
||||||
|
|
||||||
close(1); open("/dev/cons", OWRITE);
|
|
||||||
if((cfd = open("/dev/label", OWRITE)) >= 0){
|
if((cfd = open("/dev/label", OWRITE)) >= 0){
|
||||||
fprint(cfd, "save %s", name);
|
fprint(cfd, "save %s", name);
|
||||||
close(cfd);
|
close(cfd);
|
||||||
|
@ -558,24 +559,10 @@ void save(int ifd, char *name){
|
||||||
fprint(cfd, "scroll\n");
|
fprint(cfd, "scroll\n");
|
||||||
close(cfd);
|
close(cfd);
|
||||||
}
|
}
|
||||||
off = 0;
|
fprint(2, "save %s...\n", name);
|
||||||
blk = 0;
|
execl("/bin/tput", "tput", "-p", nil);
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
|
execl("/bin/cat", "cat", nil);
|
||||||
exits(0);
|
exits(0);
|
||||||
}
|
}
|
||||||
close(ifd);
|
close(ifd);
|
||||||
|
|
Loading…
Reference in New Issue