From 12d866b28a9252aecaf87e216222c8ff105c653b Mon Sep 17 00:00:00 2001 From: xiaoyaofenfen <1254525673@qq.com> Date: Thu, 23 Feb 2023 15:12:35 +0800 Subject: [PATCH] add file size percentage for upload & download command #236 --- internal/functions/pandownload/download_task_unit.go | 4 +++- internal/functions/panupload/upload_task_unit.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/functions/pandownload/download_task_unit.go b/internal/functions/pandownload/download_task_unit.go index 889b42b..ae69cfe 100644 --- a/internal/functions/pandownload/download_task_unit.go +++ b/internal/functions/pandownload/download_task_unit.go @@ -209,9 +209,11 @@ func (dtu *DownloadTaskUnit) download() (err error) { } if dtu.Cfg.ShowProgress { - fmt.Fprintf(builder, "\r[%s] ↓ %s/%s %s/s(%s/s) in %s, left %s ............", dtu.taskInfo.Id(), + downloadedPercentage := fmt.Sprintf("%.2f%%", float64(status.Downloaded())/float64(status.TotalSize())*100) + fmt.Fprintf(builder, "\r[%s] ↓ %s/%s(%s) %s/s(%s/s) in %s, left %s ............", dtu.taskInfo.Id(), converter.ConvertFileSize(status.Downloaded(), 2), converter.ConvertFileSize(status.TotalSize(), 2), + downloadedPercentage, converter.ConvertFileSize(status.SpeedsPerSecond(), 2), converter.ConvertFileSize(dtu.GlobalSpeedsStat.GetSpeeds(), 2), status.TimeElapsed()/1e7*1e7, leftStr, diff --git a/internal/functions/panupload/upload_task_unit.go b/internal/functions/panupload/upload_task_unit.go index 3263284..a924f49 100644 --- a/internal/functions/panupload/upload_task_unit.go +++ b/internal/functions/panupload/upload_task_unit.go @@ -179,9 +179,11 @@ func (utu *UploadTaskUnit) upload() (result *taskframework.TaskUnitRunResult) { } if utu.ShowProgress { - fmt.Printf("\r[%s] ↑ %s/%s %s/s(%s/s) in %s ............", utu.taskInfo.Id(), + uploadedPercentage := fmt.Sprintf("%.2f%%", float64(status.Uploaded())/float64(status.TotalSize())*100) + fmt.Printf("\r[%s] ↑ %s/%s(%s) %s/s(%s/s) in %s ............", utu.taskInfo.Id(), converter.ConvertFileSize(status.Uploaded(), 2), converter.ConvertFileSize(status.TotalSize(), 2), + uploadedPercentage, converter.ConvertFileSize(status.SpeedsPerSecond(), 2), converter.ConvertFileSize(utu.GlobalSpeedsStat.GetSpeeds(), 2), status.TimeElapsed(),