Browse Source

完善进度条显示

master
453530270@qq.com 2 years ago
parent
commit
f29a8c5520
  1. 2
      ftree.h
  2. 6
      server.c

2
ftree.h

@ -28,7 +28,7 @@
#define PORT 30100
#endif
# 进度条
// 进度条
#define PROCBAR_LEN 101
#define PROC_STYLE '#'

6
server.c

@ -159,6 +159,7 @@ int handleclient(struct client *p) {
exit(-1);
}
// printf("size %d read in %d bytes\n", p->info->size, len);
procbar(p->info->size,len);
p->state = AWAITING_HASH;
return 1;
}
@ -389,14 +390,17 @@ int checkfile(struct client *p) {
void procbar(double total,double current){
char bar[PROCBAR_LEN];
memset(bar,'\0',sizeof(bar));
// label
const char *label= "|/_\\";
//
int cnt=0;
int len= strlen(label);
// 占比
double rate = (100*current)/total;
//循环次数,必须为整数
int loop_count = (int) rate;
//loop print
whiel(cnt<=loop_count){
while(cnt<=loop_count){
printf("[%-100s][%.11f%%][%c]\r",bar,rate,label[cnt%len]);
// 直接输出不,非缓冲区
fflush(stdout);

Loading…
Cancel
Save