From b6528f302688e28b43ac0e7a253b76709dac6974 Mon Sep 17 00:00:00 2001 From: Ben Boyter Date: Tue, 19 Jul 2022 14:00:48 +1000 Subject: [PATCH] progress --- main.go | 8 +++++++- processor/processor.go | 5 ++++- processor/workers.go | 14 ++++++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index abacc3e..4a6d19f 100644 --- a/main.go +++ b/main.go @@ -82,7 +82,13 @@ func main() { "progress", "p", false, - "display progress of files", + "display progress of all files", + ) + flags.BoolVar( + &processor.ProgressLarge, + "progress-large", + false, + "display progress of only large files", ) flags.BoolVar( &processor.Debug, diff --git a/processor/processor.go b/processor/processor.go index 866cf55..f264550 100644 --- a/processor/processor.go +++ b/processor/processor.go @@ -26,6 +26,9 @@ var Trace = false // Progress uses ui bar to display the progress of files var Progress = false +// ProgressLarge uses ui bar to display the progress of files +var ProgressLarge = false + // Recursive to walk directories var Recursive = false @@ -149,7 +152,7 @@ func Process() { close(fileListQueue) }() - if Progress { + if Progress || ProgressLarge { uiprogress.Start() // start rendering of progress bars } diff --git a/processor/workers.go b/processor/workers.go index 76f4767..3af8705 100644 --- a/processor/workers.go +++ b/processor/workers.go @@ -84,6 +84,16 @@ func fileProcessorWorker(input chan string, output chan Result) { r, err = processReadFile(res, &content) } + if Progress { + var bar *uiprogress.Bar + bar = uiprogress.AddBar(1) // Add a new bar + bar.AppendFunc(func(b *uiprogress.Bar) string { + split := strings.Split(file.Name(), "/") + return "file: " + split[len(split)-1] + }) + bar.Set(1) + } + if Trace { printTrace(fmt.Sprintf("nanoseconds processReadFileParallel: %s: %d", res, makeTimestampNano()-fileStartTime)) } @@ -254,7 +264,7 @@ func processScanner(filename string, fsize int) (Result, error) { } var bar *uiprogress.Bar - if Progress { + if Progress || ProgressLarge { bar = uiprogress.AddBar(fsize) // Add a new bar bar.AppendFunc(func(b *uiprogress.Bar) string { split := strings.Split(filename, "/") @@ -271,7 +281,7 @@ func processScanner(filename string, fsize int) (Result, error) { return Result{}, err } - if Progress { + if Progress || ProgressLarge { sum += n _ = bar.Set(sum) }